Fix a bug(event handler) 86/273886/3
authorUnsung Lee <unsung.lee@samsung.com>
Fri, 15 Apr 2022 07:08:58 +0000 (16:08 +0900)
committerUnsung Lee <unsung.lee@samsung.com>
Fri, 15 Apr 2022 07:47:52 +0000 (16:47 +0900)
remove useless cgroup event handlers

Change-Id: If369bee2e44514d65609eddfc4a7abfe0cd1e6e0
Signed-off-by: Unsung Lee <unsung.lee@samsung.com>
src/common/cgroup/memory-cgroup.c
src/common/cgroup/memory-cgroup.h
src/process/watchdog/app-watchdog.c
src/resource-limiter/memory/vmpressure-lowmem-handler.c

index 67984e1..85c64ce 100644 (file)
@@ -333,13 +333,8 @@ void memcg_info_set_limit(struct memcg_info *mi, float ratio,
        if (!mi)
                return;
 
-
        mi->limit = (float)totalram * ratio;
        mi->limit_ratio = ratio;
-       mi->threshold[MEM_LEVEL_CRITICAL] = (unsigned int)(mi->limit * MEMCG_LOW_RATIO);
-       mi->threshold[MEM_LEVEL_OOM] = (unsigned int)(mi->limit * MEMCG_MEDIUM_RATIO);
-       mi->threshold_leave = (float)mi->limit * MEMCG_FOREGROUND_LEAVE_RATIO;
-       mi->oomleave = mi->limit - mi->threshold_leave;
 }
 
 void memcg_set_default_swappiness(int swappiness)
index 221636a..f3258ec 100644 (file)
@@ -165,8 +165,6 @@ struct memcg_info {
        /* limit ratio, if don't want to set limit, use NO_LIMIT*/
        float limit_ratio;
        unsigned int limit;
-       /* leave memory usage */
-       unsigned int oomleave;
        /* thresholds, normal, swap, low, medium, and leave */
        unsigned int threshold[MEM_LEVEL_MAX];  /* MB */
        unsigned int threshold_leave;                   /* MB */
index 40ccaa7..ba1601d 100644 (file)
@@ -94,6 +94,7 @@ static gboolean app_watchdog_cb(gpointer data)
        if (!conn)
                return false;
 
+       /* update a method name of all daemons or apps which listen this signal */
        _I("[WATCHDOG] detect app watchdog for pid %d with timeout %u", wai->pid, wai->watchdog_timeout);
        g_dbus_connection_emit_signal(conn, NULL, RESOURCED_PATH_PROCESS,
                                RESOURCED_INTERFACE_PROCESS, SIGNAL_APP_WATCHDOG,
index cc1c34f..26222ac 100644 (file)
@@ -343,7 +343,6 @@ static void lowmem_request_destroy(gpointer data)
 /*-------------------------------------------------*/
 
 /* 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);
@@ -422,35 +421,6 @@ static inline void get_total_memory(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;
@@ -1304,38 +1274,6 @@ static void lowmem_trigger_memory_state_action(int mem_state)
        }
 }
 
-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;
@@ -1574,25 +1512,6 @@ static void lowmem_press_root_cgroup_handler(void)
        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;
@@ -1608,12 +1527,14 @@ static bool lowmem_press_eventfd_handler(int fd, void *data)
                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;
                }
        }
 
@@ -1634,13 +1555,13 @@ static int lowmem_press_register_eventfd(struct memcg_info *mi)
 
        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;
 }
@@ -1885,9 +1806,12 @@ static void print_mem_configs(void)
                                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);