Calculate used memory size with available memory 53/107253/1 accepted/tizen_3.0.m2_mobile accepted/tizen_3.0.m2_tv accepted/tizen_3.0.m2_wearable tizen_3.0.m2 tizen_3.0_tv accepted/tizen/3.0.m2/mobile/20170104.121648 accepted/tizen/3.0.m2/tv/20170104.122347 accepted/tizen/3.0.m2/wearable/20170104.122727 accepted/tizen/3.0/common/20161228.162331 accepted/tizen/3.0/ivi/20161228.095219 accepted/tizen/3.0/mobile/20161228.095118 accepted/tizen/3.0/tv/20161228.095139 accepted/tizen/3.0/wearable/20161228.095156 submit/tizen_3.0.m2/20170104.093749 submit/tizen_3.0/20161228.012708
authorKichan Kwon <k_c.kwon@samsung.com>
Tue, 27 Dec 2016 08:42:28 +0000 (17:42 +0900)
committerKichan Kwon <k_c.kwon@samsung.com>
Tue, 27 Dec 2016 08:43:47 +0000 (17:43 +0900)
- Actual size of used memory should be calculated from difference of
 total memory and available memory

Change-Id: Ia78f705198b3c70d6a22a8d356e7396c2b63d666
Signed-off-by: Kichan Kwon <k_c.kwon@samsung.com>
src/runtime_info_usage.c

index 6e8d3e6..75e7a30 100644 (file)
@@ -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;