Read zoneinfo to get total RAM size 89/115789/2 accepted/tizen/common/20170221.135557 accepted/tizen/ivi/20170221.225645 accepted/tizen/mobile/20170221.225559 accepted/tizen/tv/20170221.225614 accepted/tizen/unified/20170309.031931 accepted/tizen/wearable/20170221.225630 submit/tizen/20170221.093648 submit/tizen_unified/20170308.100405
authorKichan Kwon <k_c.kwon@samsung.com>
Tue, 21 Feb 2017 09:23:58 +0000 (18:23 +0900)
committerKichan Kwon <k_c.kwon@samsung.com>
Tue, 21 Feb 2017 09:26:58 +0000 (18:26 +0900)
- /proc/meminfo support total RAM size except kernel reserved memory
- To get whole RAM size, we calculate (the number of page * page size)

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

index 75e7a30..4a05400 100644 (file)
@@ -35,6 +35,7 @@
 #define CPU_USAGE 2
 
 #define kBtoKiB(val) (int)(((long long)val * 1024)/1000)
+#define pagetoKiB(val) (int)((long long)val * 4096 / 1000)
 
 //LCOV_EXCL_START : system error
 static int runtime_info_get_dbus_error(const char *err_name)
@@ -157,7 +158,7 @@ static DBusMessage *runtime_info_dbus_process_usage_info(int *pid, int size, int
 
 API int runtime_info_get_system_memory_info(runtime_memory_info_s *info)
 {
-       FILE *meminfo_fp;
+       FILE *fp;
        char buf[256];
        unsigned long swap_total, swap_free, value, mem_available;
 
@@ -169,14 +170,14 @@ API int runtime_info_get_system_memory_info(runtime_memory_info_s *info)
 
        swap_total = swap_free = mem_available = 0;
 
-       meminfo_fp = fopen("/proc/meminfo", "r");
-       if (meminfo_fp == NULL) {
+       fp = fopen("/proc/meminfo", "r");
+       if (fp == NULL) {
                _E("IO_ERROR(0x%08x) : failed to open file to read memory usage",
                                RUNTIME_INFO_ERROR_IO_ERROR);
                return RUNTIME_INFO_ERROR_IO_ERROR;
        }
 
-       while (fgets(buf, sizeof(buf), meminfo_fp) != NULL) {
+       while (fgets(buf, sizeof(buf), fp) != NULL) {
                if (sscanf(buf, "MemTotal: %lu", &value) == 1)
                        info->total = kBtoKiB(value);
                else if (sscanf(buf, "MemFree: %lu", &value) == 1)
@@ -190,11 +191,34 @@ API int runtime_info_get_system_memory_info(runtime_memory_info_s *info)
                else if (sscanf(buf, "SwapFree: %lu", &value) == 1)
                        swap_free = value;
        }
-       fclose(meminfo_fp);
+       fclose(fp);
 
        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));
 
+       /*
+        * Get total memory size from zoneinfo
+        *
+        * meminfo show the total memory size
+        * except kernel reserved memory
+        *
+        * Therefore, we will use (the number of page * page size)
+        */
+       fp = fopen("/proc/zoneinfo", "r");
+       if (fp == NULL) {
+               _E("IO_ERROR(0x%08x) : failed to open file to read memory size",
+                               RUNTIME_INFO_ERROR_IO_ERROR);
+               return RUNTIME_INFO_ERROR_IO_ERROR;
+       }
+
+       info->total = 0;
+       while (fgets(buf, sizeof(buf), fp) != NULL)
+               if (sscanf(buf, " spanned %lu", &value) == 1)
+                       info->total += value;
+       info->total = pagetoKiB(info->total);
+
+       fclose(fp);
+
        return RUNTIME_INFO_ERROR_NONE;
 }