diff options
| author | 2015-12-09 09:36:12 -0800 | |
|---|---|---|
| committer | 2015-12-09 21:36:39 +0000 | |
| commit | 187a6aeb112ecbf85387a21ea75cf6beb3f9fc76 (patch) | |
| tree | e362341afeac7576ad509dc473668daa7d00c56e | |
| parent | 35fc197caaecf22e8e5642963aa4807f1b43d88f (diff) | |
Prefer new zram ABI
Starting with Linux 4.1, reading from /dev/block/zram*/mem_used_total
logs this warning:
"Attribute mem_used_total (and others) will be removed. See zram
documentation."
mem_used_total and several related counters are now consolidated under a
new node mm_stat. Prefer that when it's available.
Bug: 25951511
Change-Id: I0862c3cd1af5d003158aca6be42db25e4bebe7c7
Signed-off-by: Greg Hackmann <ghackmann@google.com>
| -rw-r--r-- | core/jni/android_os_Debug.cpp | 40 |
1 files changed, 31 insertions, 9 deletions
diff --git a/core/jni/android_os_Debug.cpp b/core/jni/android_os_Debug.cpp index 1ee7ea8f7ea6..71f881e6d6e1 100644 --- a/core/jni/android_os_Debug.cpp +++ b/core/jni/android_os_Debug.cpp @@ -595,6 +595,36 @@ enum { MEMINFO_COUNT }; +static long get_zram_mem_used() +{ +#define ZRAM_SYSFS "/sys/block/zram0/" + FILE *f = fopen(ZRAM_SYSFS "mm_stat", "r"); + if (f) { + long mem_used_total = 0; + + int matched = fscanf(f, "%*d %*d %ld %*d %*d %*d %*d", &mem_used_total); + if (matched != 1) + ALOGW("failed to parse " ZRAM_SYSFS "mm_stat"); + + fclose(f); + return mem_used_total; + } + + f = fopen(ZRAM_SYSFS "mem_used_total", "r"); + if (f) { + long mem_used_total = 0; + + int matched = fscanf(f, "%ld", &mem_used_total); + if (matched != 1) + ALOGW("failed to parse " ZRAM_SYSFS "mem_used_total"); + + fclose(f); + return mem_used_total; + } + + return 0; +} + static void android_os_Debug_getMemInfo(JNIEnv *env, jobject clazz, jlongArray out) { char buffer[1024]; @@ -680,15 +710,7 @@ static void android_os_Debug_getMemInfo(JNIEnv *env, jobject clazz, jlongArray o if (*p) p++; } - fd = open("/sys/block/zram0/mem_used_total", O_RDONLY); - if (fd >= 0) { - len = read(fd, buffer, sizeof(buffer)-1); - close(fd); - if (len > 0) { - buffer[len] = 0; - mem[MEMINFO_ZRAM_TOTAL] = atoll(buffer)/1024; - } - } + mem[MEMINFO_ZRAM_TOTAL] = get_zram_mem_used() / 1024; // Recompute Vmalloc Used since the value in meminfo // doesn't account for I/O remapping which doesn't use RAM. mem[MEMINFO_VMALLOC_USED] = get_allocated_vmalloc_memory() / 1024; |