On Apr 21, 2:21 am, Magnus <
perssonmag...@gmail.com> wrote:
> I would still like to get an explanation as to why the Java APIs show
> a lot more memory available than the UNIX commands available in the
> adb shell.
>
> memInfo = new ActivityManager.MemoryInfo();
> mgr.getMemoryInfo(memInfo);
> s = String.valueOf(memInfo.availMem);
>
> Is the Dalvik machine allocating memory at start that is not available
> to the Linux kernel but shown form the Java APIs?
ActivityManager.MemoryInfo is not related to Dalvik. Note this is
different from Debug.MemoryInfo (which is also largely unrelated to
the VM).
ActivityManager.MemoryInfo uses ActivityManager.getMemoryInfo (see
frameworks/base/core/java/android/app/ActivityManager.java). The call
into the system service ends up in
ActivityManagerService.getMemoryInfo (frameworks/base/services/java/
com/android/server/am/ActivityManagerService.java).
public void getMemoryInfo(ActivityManager.MemoryInfo outInfo) {
outInfo.availMem = Process.getFreeMemory();
outInfo.threshold = HOME_APP_MEM;
outInfo.lowMemory = outInfo.availMem <
(HOME_APP_MEM + ((HIDDEN_APP_MEM-HOME_APP_MEM)/2));
}
Process.getFreeMemory is implemented in frameworks/base/core/jni/
android_util_Process.cpp. It opens /proc/meminfo and adds up MemFree
and Cached.
FWIW, I don't believe I've looked at any of this code before. All I
did was grep for strings in your original message, look at the
sources, and iterate. There's no need to remain puzzled when
recursive grep is available. :-) (If you ". build/envsetup.sh" in the
source tree, you will have a handy "sgrep" shell command. The first
one takes a while to run if you do it over the entire source tree, but
after that it's all in the disk cache and you can grep the entire
thing quickly -- 1.75 seconds on my system.)