#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 },
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;
*/
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
#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 */
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;
* 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
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;