From f124b36b642df50a827a784d94cfcf99d782fe91 Mon Sep 17 00:00:00 2001 From: Kichan Kwon Date: Tue, 27 Dec 2016 17:42:28 +0900 Subject: [PATCH] Calculate used memory size with available memory - Actual size of used memory should be calculated from difference of total memory and available memory Change-Id: Ia78f705198b3c70d6a22a8d356e7396c2b63d666 Signed-off-by: Kichan Kwon --- src/runtime_info_usage.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/runtime_info_usage.c b/src/runtime_info_usage.c index 6e8d3e6..75e7a30 100644 --- a/src/runtime_info_usage.c +++ b/src/runtime_info_usage.c @@ -159,7 +159,7 @@ API int runtime_info_get_system_memory_info(runtime_memory_info_s *info) { FILE *meminfo_fp; char buf[256]; - unsigned long swap_total, swap_free, value; + unsigned long swap_total, swap_free, value, mem_available; if (info == NULL) { _E("INVALID_PARAMETER(0x%08x) : invalid output param", @@ -167,7 +167,7 @@ API int runtime_info_get_system_memory_info(runtime_memory_info_s *info) return RUNTIME_INFO_ERROR_INVALID_PARAMETER; } - swap_total = swap_free = 0; + swap_total = swap_free = mem_available = 0; meminfo_fp = fopen("/proc/meminfo", "r"); if (meminfo_fp == NULL) { @@ -183,6 +183,8 @@ API int runtime_info_get_system_memory_info(runtime_memory_info_s *info) info->free = kBtoKiB(value); else if (sscanf(buf, "Cached: %lu", &value) == 1) info->cache = kBtoKiB(value); + else if (sscanf(buf, "MemAvailable: %lu", &value) == 1) + mem_available = kBtoKiB(value); else if (sscanf(buf, "SwapTotal: %lu", &value) == 1) swap_total = value; else if (sscanf(buf, "SwapFree: %lu", &value) == 1) @@ -190,7 +192,7 @@ API int runtime_info_get_system_memory_info(runtime_memory_info_s *info) } fclose(meminfo_fp); - info->used = (info->total > info->free) ? (info->total - info->free) : 0; + info->used = mem_available ? (info->total - mem_available) : (info->total - info->free - info->cache); info->swap = kBtoKiB(((swap_total > swap_free) ? (int)(swap_total - swap_free) : 0)); return RUNTIME_INFO_ERROR_NONE; -- 2.7.4