Add active, inactive, and swap usage of each app in task_info structure.
This infomration will be used in get_kill_candidates_post_with_wss() function.
Active, inactive, and swap usage are counted by
- Active usage is sum of active_anon + active_file in memcg
- Inactive usage is sum of inactive_anon + inactive_file in memcg
- Swap usage is a mount of swap in memcg
Change-Id: I1e96d12023eb303754a0120e18c20ee9e66a1459
Signed-off-by: Unsung Lee <unsung.lee@samsung.com>
return 0;
}
+int memcg_get_inactive_memory(char *memcg, unsigned long long *inactive_bytes)
+{
+ int ret;
+ _cleanup_free_ struct cgroup_memory_stat *mem_stat = NULL;
+
+ ret = memcg_get_memory_stat(memcg, &mem_stat);
+ if (ret) {
+ _D("fail to get memory status : %s", memcg);
+ return ret;
+ }
+
+ *inactive_bytes = mem_stat->value[CGROUP_MEMORY_STAT_INACTIVE_FILE];
+ *inactive_bytes += mem_stat->value[CGROUP_MEMORY_STAT_INACTIVE_ANON];
+
+ return 0;
+}
+
+int memcg_get_active_memory(char *memcg, unsigned long long *active_bytes)
+{
+ int ret;
+ _cleanup_free_ struct cgroup_memory_stat *mem_stat = NULL;
+
+ ret = memcg_get_memory_stat(memcg, &mem_stat);
+ if (ret) {
+ _D("fail to get memory status : %s", memcg);
+ return ret;
+ }
+
+ *active_bytes = mem_stat->value[CGROUP_MEMORY_STAT_ACTIVE_FILE];
+ *active_bytes += mem_stat->value[CGROUP_MEMORY_STAT_ACTIVE_ANON];
+
+ return 0;
+}
+
int memcg_get_anon_usage(char *memcg, unsigned long long *anon_usage_bytes)
{
int r;
int memcg_get_memory_stat(const char *name, struct cgroup_memory_stat **mem_stat);
/**
+ * @desc get inactive memory usage of cgroup based on memory.stat
+ * @return 0 if the value was correctly read
+ */
+int memcg_get_inactive_memory(char *memcg, unsigned long long *inactive_bytes);
+
+/**
+ * @desc get active memory usage of cgroup based on memory.stat
+ * @return 0 if the value was correctly read
+ */
+int memcg_get_active_memory(char *memcg, unsigned long long *active_bytes);
+
+/**
* @desc get anon memory usage of cgroup based on memory.stat
* @return 0 if the value was correctly read
*/
task->is_mapped = window.is_mapped;
}
+static void init_task_working_set_size_info(struct task_info *task,
+ const char *appid)
+{
+ char path[PATH_MAX] = "";
+ unsigned long long inactive_bytes;
+ unsigned long long active_bytes;
+ unsigned long long swap_bytes;
+ int ret;
+
+ assert(task);
+ assert(appid);
+
+ snprintf(path, PATH_MAX, "%s/%s", MEMCG_PRIVATE_PATH, appid);
+
+ ret = memcg_get_active_memory(path, &active_bytes);
+ if (ret)
+ goto parse_fail;
+
+ ret = memcg_get_inactive_memory(path, &inactive_bytes);
+ if (ret)
+ goto parse_fail;
+
+ ret = memcg_get_swap_usage(path, &swap_bytes);
+ if (ret)
+ goto parse_fail;
+
+ task->active_memory_kb = (unsigned long) BYTE_TO_KBYTE(active_bytes);
+ task->inactive_memory_kb = (unsigned long) BYTE_TO_KBYTE(inactive_bytes);
+ task->swap_memory_kb = (unsigned long) BYTE_TO_KBYTE(swap_bytes);
+
+ return;
+
+parse_fail:
+ task->active_memory_kb = 0;
+ task->inactive_memory_kb = 0;
+ task->swap_memory_kb = 0;
+}
+
static GArray *lowmem_get_task_info_app(int killer_flags, int start_oom, int end_oom)
{
GSList *iter = NULL;
struct proc_app_info *pai = (struct proc_app_info *)(iter->data);
struct task_info task;
+ if (!pai->appid)
+ continue;
+
if (!pai->main_pid)
continue;
}
init_task_window_info(&task, pai->window);
+ init_task_working_set_size_info(&task, pai->appid);
+
g_array_append_val(lowmem_task_info_app_array, task);
}