lowmem: Support 'get_kill_candidates_post' funcs 59/294659/19
authorUnsung Lee <unsung.lee@samsung.com>
Wed, 21 Jun 2023 10:31:02 +0000 (19:31 +0900)
committerChanwoo Choi <cw00.choi@samsung.com>
Mon, 31 Jul 2023 02:39:59 +0000 (02:39 +0000)
Support LMK governor post funcs which will be called after
LMK governor function to reorder a victim candidate list

resourced LMK needs to reorder victim candidates list according to
serveral conditions (e.g., working set size, foreground app status)

resourced supports three type of get_kill_candidates_post ops newly
  - int syscommon_plugin_resourced_memory_lmk_get_kill_candidates_post(
  GArray *candidates)
  to consider user custom governor policy
  - int syscommon_plugin_resourced_memory_lmk_get_kill_candidates_post_with_wss(
  GArray *candidates)
  to consider working set size of app
  - int syscommon_plugin_resourced_memory_lmk_get_kill_candidates_post_with_foreground(
  GArray *candidates)
  to consider window information of app

Change-Id: I32bab160d66d05cd986b9f84c942ea1d2b8a59c4
Signed-off-by: Unsung Lee <unsung.lee@samsung.com>
src/resource-limiter/memory/lowmem-governor.c
src/resource-limiter/memory/lowmem.c
src/resource-limiter/memory/lowmem.h

index 2cfa41c..44a5613 100644 (file)
@@ -47,9 +47,6 @@ static int lowmem_governor_initialize(void *data)
         * (governor for the lowmem killer and governors for the memory levels)
         */
 
-       /* Register the governor for the lowmem_worker(lowmem killer) */
-       lowmem_register_lmk_governor(syscommon_plugin_resourced_memory_lmk_get_kill_candidates);
-
        /* Register governors for the memory levels */
        lowmem_register_mem_level_governor(MEM_LEVEL_HIGH, mem_state_dummy_governor);
        lowmem_register_mem_level_governor(MEM_LEVEL_MEDIUM, mem_state_dummy_governor);
index 02d3c14..2f72a1c 100644 (file)
@@ -43,6 +43,8 @@
 #include <eventsystem.h>
 #include <malloc.h>
 
+#include <system/syscommon-plugin-resourced-memory-lmk.h>
+
 #include "trace.h"
 #include "cgroup.h"
 #include "lowmem.h"
@@ -684,17 +686,6 @@ static GArray *lowmem_get_task_info_proc()
        return lowmem_task_info_proc_array;
 }
 
-struct lowmem_governor_ops {
-       int(*get_kill_candidates)(GArray *, GArray *, GArray *, unsigned long);
-};
-
-static struct lowmem_governor_ops governor_ops = { NULL };
-void lowmem_register_lmk_governor(int(*get_kill_candidates)(GArray *,
-                                       GArray *, GArray *, unsigned long))
-{
-       governor_ops.get_kill_candidates = get_kill_candidates;
-}
-
 static int(*lowmem_controller_kill_candidates)(GArray *, unsigned, unsigned int,
                                        int, int, int *, unsigned int *,
                                        unsigned, void(*)(void));
@@ -724,6 +715,7 @@ static int lowmem_kill_victims(int max_victims,
        int start_oom, int end_oom, unsigned should_be_freed, int flags,
        unsigned int *total_size, int *completed, unsigned int threshold)
 {
+       int ret;
        unsigned int total_victim_size = 0;
        int candidates_cnt = 0;
        int victim_cnt = 0;
@@ -746,19 +738,42 @@ static int lowmem_kill_victims(int max_victims,
        if (!lowmem_kill_candidates)
                lowmem_kill_candidates = g_array_new(false, false, sizeof(struct task_info *));
 
-       assert(governor_ops.get_kill_candidates != NULL);
-       candidates_cnt = governor_ops.get_kill_candidates(
+       candidates_cnt = syscommon_plugin_resourced_memory_lmk_get_kill_candidates(
                                                lowmem_kill_candidates,
                                                task_info_app_array,
                                                task_info_proc_array,
                                                totalram_kb);
-
-       _D("[LMK] candidates_cnt=%d", candidates_cnt);
        if (candidates_cnt <= 0) {
                status = LOWMEM_RECLAIM_NEXT_TYPE;
                goto leave;
        }
 
+       /**
+        * Add, delete, and reorder already ordered lowmem_kill_candidates
+        * according to the governor post rule.
+        */
+       ret = syscommon_plugin_resourced_memory_lmk_get_kill_candidates_post(
+                               lowmem_kill_candidates);
+       if (ret < 0) {
+               status = LOWMEM_RECLAIM_NEXT_TYPE;
+               goto leave;
+       }
+
+       ret = syscommon_plugin_resourced_memory_lmk_get_kill_candidates_post_with_wss(
+                               lowmem_kill_candidates);
+       if (ret < 0) {
+               status = LOWMEM_RECLAIM_NEXT_TYPE;
+               goto leave;
+       }
+
+       ret = syscommon_plugin_resourced_memory_lmk_get_kill_candidates_post_with_foreground(
+                               lowmem_kill_candidates);
+       if (ret < 0) {
+               status = LOWMEM_RECLAIM_NEXT_TYPE;
+               goto leave;
+       }
+
+       _D("[LMK] candidates_cnt=%d", lowmem_kill_candidates->len);
        assert(lowmem_controller_kill_candidates != NULL);
        victim_cnt = lowmem_controller_kill_candidates(lowmem_kill_candidates,
                                                should_be_freed, threshold,
index ea54103..35c24d0 100644 (file)
@@ -93,9 +93,6 @@ enum {
        LOWMEM_RECLAIM_NEXT_TYPE
 };
 
-void lowmem_register_lmk_governor(int(*)(GArray *, GArray *, GArray *,
-                                       unsigned long));
-
 void lowmem_register_lmk_controller(int(*kill_candidates)(GArray *, unsigned,
                                                unsigned int, int, int, int *,
                                                unsigned int *, unsigned,