John Dallman
2018-08-24 09:55:54 UTC
I'm porting a large mathematical modelling library, written in C (*not*
C++) to Android. Its main test harness on UNIX and Windows platforms is a
command-line program, and I'm intending to build that as a command-line
tool and run it in the ADB shell. This is much easier than making a normal
Android app out of it. There will be an Android-specific test app as well,
of course.
My command line tool needs to find out how much memory is available for its
use. As it isn't a conventional app, it has no way to receive the normal
memory low warnings for GUI apps. As the devices that it runs on are
dedicated to doing testing, and are locked away in a server room to keep
them away from prying fingers, I don't need to worry about changes in
available memory as other apps are started and shut down. So it looked as
if I could use classic UNIX sconf() to find out how much memory is
available.
For the total physical memory of the machine, this works: sconf(
_SC_PAGE_SIZE) * sysconf( _SC_PHYS_PAGES) gives me a figure that matches
/proc/meminfo's MemTotal figure.
For available memory, sysconf( _SC_PAGE_SIZE) * sysconf( _SC_AVPHYS_PAGES)
gives me the same size as the /proc/meminfo's MemFree figure. But that's
quite small, about 200MB on a 4GB device with no apps active on the GUI.
So I went looking for an sconf parameter that matches proc/meminfo's
MemAvailable figure. I didn't find it, but I did find the source for that
part of Bionic LibC, at
https://android.googlesource.com/platform/bionic/+/a186b2e/libc/bionic/sysconf.cpp,
and that revealed that the _SC_PHYS_PAGES and _SC_AVPHYS_PAGES queries are
implemented by parsing /proc/meminfo.
This seems odd: is there no Linux system call that could be used to
implement these sysconf queries? Is there a proper way of getting a size
equivalent to MemAvailable?
Thanks,
John
C++) to Android. Its main test harness on UNIX and Windows platforms is a
command-line program, and I'm intending to build that as a command-line
tool and run it in the ADB shell. This is much easier than making a normal
Android app out of it. There will be an Android-specific test app as well,
of course.
My command line tool needs to find out how much memory is available for its
use. As it isn't a conventional app, it has no way to receive the normal
memory low warnings for GUI apps. As the devices that it runs on are
dedicated to doing testing, and are locked away in a server room to keep
them away from prying fingers, I don't need to worry about changes in
available memory as other apps are started and shut down. So it looked as
if I could use classic UNIX sconf() to find out how much memory is
available.
For the total physical memory of the machine, this works: sconf(
_SC_PAGE_SIZE) * sysconf( _SC_PHYS_PAGES) gives me a figure that matches
/proc/meminfo's MemTotal figure.
For available memory, sysconf( _SC_PAGE_SIZE) * sysconf( _SC_AVPHYS_PAGES)
gives me the same size as the /proc/meminfo's MemFree figure. But that's
quite small, about 200MB on a 4GB device with no apps active on the GUI.
So I went looking for an sconf parameter that matches proc/meminfo's
MemAvailable figure. I didn't find it, but I did find the source for that
part of Bionic LibC, at
https://android.googlesource.com/platform/bionic/+/a186b2e/libc/bionic/sysconf.cpp,
and that revealed that the _SC_PHYS_PAGES and _SC_AVPHYS_PAGES queries are
implemented by parsing /proc/meminfo.
This seems odd: is there no Linux system call that could be used to
implement these sysconf queries? Is there a proper way of getting a size
equivalent to MemAvailable?
Thanks,
John
--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-ndk+***@googlegroups.com.
To post to this group, send email to android-***@googlegroups.com.
Visit this group at https://groups.google.com/group/android-ndk.
To view this discussion on the web visit https://groups.google.com/d/msgid/android-ndk/CAH1xqgmc%3DT%2Brcv7K-WvO5rx2UiiNwS7xkwRfMOvRQWb3_pnmfg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-ndk+***@googlegroups.com.
To post to this group, send email to android-***@googlegroups.com.
Visit this group at https://groups.google.com/group/android-ndk.
To view this discussion on the web visit https://groups.google.com/d/msgid/android-ndk/CAH1xqgmc%3DT%2Brcv7K-WvO5rx2UiiNwS7xkwRfMOvRQWb3_pnmfg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.