/*-------------------------------------------------*/
/* low memory action function for cgroup */
-static void memory_cgroup_proactive_lmk_act(enum cgroup_type type, struct memcg_info *mi);
/* low memory action function */
static void high_mem_act(void);
static void swap_activate_act(void);
}
}
-static int lowmem_mem_usage_uss(pid_t pid, unsigned int *usage)
-{
- unsigned int uss, zram = 0;
- int ret;
-
- *usage = 0;
-
- /*
- * In lowmem we need to know memory size of processes to
- * for terminating apps. To get most real value of usage
- * we should use USS + ZRAM usage for selected process.
- *
- * Those values will contain the most approximated amount
- * of memory that will be freed after process termination.
- */
- ret = proc_get_uss(pid, &uss);
- if (ret != RESOURCED_ERROR_NONE)
- return ret;
-
- if (swap_get_state() == SWAP_ON) {
- ret = proc_get_zram_usage(pid, &zram);
- /* If we don't get zram usage, it's not a problem */
- if (ret != RESOURCED_ERROR_NONE)
- zram = 0;
- }
- *usage = uss + zram;
- return RESOURCED_ERROR_NONE;
-}
-
unsigned int lowmem_get_task_mem_usage_rss(const struct task_info *tsk)
{
unsigned int size = 0, total_size = 0;
}
}
-static void lowmem_dump_cgroup_procs(struct memcg_info *mi)
-{
- int i;
- unsigned int size;
- pid_t pid;
- GArray *pids_array = NULL;
-
- cgroup_get_pids(mi->name, &pids_array);
-
- for (i = 0; i < pids_array->len; i++) {
- pid = g_array_index(pids_array, pid_t, i);
- lowmem_mem_usage_uss(pid, &size);
- _I("pid = %d, size = %u KB", pid, size);
- }
- g_array_free(pids_array, true);
-}
-
-static void memory_cgroup_proactive_lmk_act(enum cgroup_type type, struct memcg_info *mi)
-{
- struct lowmem_control *ctl;
-
- /* To Do: only start to kill fg victim when no pending fg victim */
- lowmem_dump_cgroup_procs(mi);
-
- ctl = LOWMEM_NEW_REQUEST();
- if (ctl) {
- LOWMEM_SET_REQUEST(ctl, OOM_SINGLE_SHOT | OOM_IN_DEPTH, type,
- mi->oomleave, num_max_victims, NULL);
- lowmem_queue_request(&lmw, ctl);
- }
-}
-
static unsigned int check_mem_state(unsigned int available)
{
int mem_state;
prev_available = available;
}
-static void lowmem_press_cgroup_handler(enum cgroup_type type, struct memcg_info *mi)
-{
- unsigned int usage, threshold;
- int ret;
-
- ret = memcg_get_anon_usage(mi->name, &usage);
- if (ret) {
- _D("getting anonymous memory usage fails");
- return;
- }
-
- threshold = mi->threshold[MEM_LEVEL_OOM];
- if (usage >= threshold)
- memory_cgroup_proactive_lmk_act(type, mi);
- else
- _I("anon page %u MB < medium threshold %u MB", BYTE_TO_MBYTE(usage),
- BYTE_TO_MBYTE(threshold));
-}
-
static bool lowmem_press_eventfd_handler(int fd, void *data)
{
struct memcg_info *mi;
mi = get_memcg_info(type);
if (fd == mi->evfd) {
/* call low memory handler for this memcg */
- if (type == CGROUP_ROOT)
+ if (type == CGROUP_ROOT) {
lowmem_press_root_cgroup_handler();
+ return true;
+ }
else {
- lowmem_press_cgroup_handler(type, mi);
+ _E("Wrong event fd for cgroup %s", convert_cgroup_type_to_str(type));
+ return false;
}
- return true;
}
}
if (evfd < 0) {
int saved_errno = errno;
- _E("fail to register event press fd %s cgroup", name);
+ _E("Failed to register event press fd %s cgroup", name);
return -saved_errno;
}
mi->evfd = evfd;
- _I("register event fd success for %s cgroup", name);
+ _I("Register event fd success for %s cgroup", name);
add_fd_read_handler(evfd, lowmem_press_eventfd_handler, NULL, NULL, &handler);
return 0;
}
convert_cgroup_type_to_str(cgroup), get_memcg_info(cgroup)->limit);
}
- for (int mem_lvl = 0; mem_lvl < MEM_LEVEL_MAX; mem_lvl++)
- _I("[MEMORY-LEVEL] set threshold for memory level '%s' to %u MB",
- convert_memstate_to_str(mem_lvl), get_root_memcg_info()->threshold[mem_lvl]);
+ for (int cgroup = CGROUP_ROOT; cgroup < CGROUP_END; cgroup++) {
+ for (int mem_lvl = 0; mem_lvl < MEM_LEVEL_MAX; mem_lvl++) {
+ _I("[MEMORY-LEVEL] set threshold of %s for memory level '%s' to %u MB", convert_cgroup_type_to_str(cgroup),
+ convert_memstate_to_str(mem_lvl), get_memcg_info(cgroup)->threshold[mem_lvl]);
+ }
+ }
_I("[LMK] set number of max victims as %d", num_max_victims);
_I("[LMK] set threshold leave to %u MB", get_root_memcg_info()->threshold_leave);