sconf() limitations and strange implementation

81 views
Skip to first unread message

John Dallman

unread,
Aug 24, 2018, 5:56:16 AM8/24/18
to andro...@googlegroups.com
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

Alex Cohn

unread,
Aug 26, 2018, 5:57:36 AM8/26/18
to android-ndk

John Dallman

unread,
Aug 28, 2018, 8:45:46 AM8/28/18
to andro...@googlegroups.com
I need to get it programatically, rather than in the ADB command-line environment. After digging a bit further, it seems that there isn't a Linux API like the BSD vmmanager, so I'll just parse /proc/meminfo. 

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 andro...@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/53a132c5-4470-4986-b8e8-7d6b850334b9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages