memory: make generic api for getting rss 37/130437/1
authorByungSoo Kim <bs1770.kim@samsung.com>
Tue, 18 Apr 2017 11:18:57 +0000 (20:18 +0900)
committerKunhoon Baik <knhoon.baik@samsung.com>
Mon, 22 May 2017 09:24:00 +0000 (18:24 +0900)
Other modules also need to get RSS
because it is faster than checking smaps.

Change-Id: I4af8207cf57ae47c8ba66177770a012a02d6566a
Signed-off-by: ByungSoo Kim <bs1770.kim@samsung.com>
src/common/procfs.c
src/common/procfs.h
src/memory/vmpressure-lowmem-handler.c

index 40a9576ea7626d5e7fdad90e29a6e4ae325f6e62..b668212d98d528e85ba50b2e6e2189f6343bdb8f 100644 (file)
@@ -53,6 +53,9 @@
 
 #define PAGE_SIZE_KB 4
 
+#define MEM_RSS_RATIO                  0.3
+#define MEM_SWAP_RATIO                 0.5
+
 static struct sys_node_table sys_node_tables[] = {
        { SYS_VM_SHRINK_MEMORY, "/proc/sys/vm/shrink_memory", 1, 1 },
        { SYS_VM_COMPACT_MEMORY, "/proc/sys/vm/compact_memory", 1, 1 },
@@ -287,6 +290,28 @@ int proc_get_uss(pid_t pid, unsigned int *uss)
        return RESOURCED_ERROR_NONE;
 }
 
+int proc_get_rss(pid_t pid, unsigned int *rss)
+{
+       unsigned int vmrss, vmswap;
+       int ret;
+
+       *rss = 0;
+
+       ret = proc_get_mem_usage(pid, &vmswap, &vmrss);
+       if (ret != RESOURCED_ERROR_NONE)
+               return ret;
+
+       /*
+        * USS is more real live usage compare to RSS.
+        * But, RSS is faster to get, PSS is very slow.
+        * So, RSS value with heuristic weight factor and SWAP size which is considered swap compression ration
+        * can be more accurate value as well as getting it fastly.
+        */
+       *rss = vmrss * MEM_RSS_RATIO + vmswap * MEM_SWAP_RATIO;
+
+       return RESOURCED_ERROR_NONE;
+}
+
 int proc_get_zram_usage(pid_t pid, unsigned int *usage)
 {
        int ret;
index 5e905b83e538e0e8d884622f65ee67c4e1bddea2..596d055f9ed5d8047d2bf728e6b241a2e36b77fc 100644 (file)
@@ -249,6 +249,12 @@ int proc_get_pss(pid_t pid, unsigned int *pss);
  */
 int proc_get_uss(pid_t pid, unsigned int *uss);
 
+/**
+ * @desc get RSS memory usage from /proc/{pid}/status file.
+ * @return negative value if error or pid doesn't exist
+ */
+int proc_get_rss(pid_t pid, unsigned int *rss);
+
 /**
  * @desc get aproximated usage of Zram for pid
  * @return negative value if error or pid doesn't exist
index 6f0906d9349b09d9ca27e0e0a221050452e64670..fb7bb120a1fef37f1f791745994053c6d8126d95 100644 (file)
@@ -85,8 +85,6 @@
 #define MAX_FD_VICTIMS                 10
 #define NUM_RM_LOGS                    5
 #define THRESHOLD_MARGIN               10 /* MB */
-#define MEM_RSS_RATIO                  0.3
-#define MEM_SWAP_RATIO                 0.5
 
 #define MEM_SIZE_64                    64  /* MB */
 #define MEM_SIZE_256                   256 /* MB */
@@ -365,28 +363,6 @@ static int lowmem_mem_usage_uss(pid_t pid, unsigned int *usage)
        return RESOURCED_ERROR_NONE;
 }
 
-static int lowmem_mem_usage_rss(pid_t pid, unsigned int *usage)
-{
-       unsigned int rss, swap;
-       int ret;
-
-       *usage = 0;
-
-       ret = proc_get_mem_usage(pid, &swap, &rss);
-       if (ret != RESOURCED_ERROR_NONE)
-               return ret;
-
-       /*
-        * USS is more real live usage compare to RSS.
-        * But, RSS is faster to get, PSS is very slow.
-        * So, RSS value with heuristic weight factor and SWAP size which is considered swap compression ration
-        * can be more accurate value as well as getting it fastly.
-        */
-       *usage = rss * MEM_RSS_RATIO + swap * MEM_SWAP_RATIO;
-
-       return RESOURCED_ERROR_NONE;
-}
-
 unsigned int lowmem_get_task_mem_usage_rss(const struct task_info *tsk)
 {
        unsigned int size = 0, total_size = 0;
@@ -399,7 +375,7 @@ unsigned int lowmem_get_task_mem_usage_rss(const struct task_info *tsk)
         * is used.
         */
        if (tsk->pids == NULL) {
-               ret = lowmem_mem_usage_rss(tsk->pid, &size);
+               ret = proc_get_rss(tsk->pid, &size);
 
                /* If there is no proc entry for given pid the process
                 * should be abandoned during further processing
@@ -412,7 +388,7 @@ unsigned int lowmem_get_task_mem_usage_rss(const struct task_info *tsk)
 
        for (index = 0; index < tsk->pids->len; index++) {
                pid = g_array_index(tsk->pids, pid_t, index);
-               ret = lowmem_mem_usage_rss(pid, &size);
+               ret = proc_get_rss(pid, &size);
                if (ret != RESOURCED_ERROR_NONE)
                        continue;
                total_size += size;