resourced-memory-lmk: Add a skeleton of get_kill_candidates_post funcs 41/295041/8
authorUnsung Lee <unsung.lee@samsung.com>
Fri, 30 Jun 2023 06:16:14 +0000 (15:16 +0900)
committerUnsung Lee <unsung.lee@samsung.com>
Mon, 31 Jul 2023 01:55:43 +0000 (10:55 +0900)
Add a skeleton of three get_kill_candidates_post funcs
(get_kill_candidates_post, get_kill_candidates_post_with_wss, and
get_kill_candidates_post_with_foreground) in resourced-memory-lmk

resourced supports three type of get_kill_candidates_post ops newly
  - int get_kill_candidates_post(GArray *candidates)
    to consider user custom governor policy
  - int get_kill_candidates_post_with_wss(GArray *candidates)
    to consider working set size of app
  - int get_kill_candidates_post_with_foreground(GArray *candidates,
  enum oom_level oom_level)
    to consider window information of app

Change-Id: I9f774c6ff075f48319925c40c772c969ce838d03
Signed-off-by: Unsung Lee <unsung.lee@samsung.com>
src/resourced-memory-lmk/resourced-memory-lmk.c

index 03a6a6bcb9844ced34cc00ed31e6453b851e88a4..c506942f63e1533be4a9e27d9be822e2245d139f 100644 (file)
 
 #define EXPORT __attribute__ ((visibility("default")))
 
+/**
+ * -900 is very low oom_score_adj (-1000 to 1000), so
+ * focused app will not be choosen as victim regardless of memory size.
+ */
+#define OOMADJ_APP_IN_FOREGROUND_APP_LIST      -900
+
+static syscommon_plugin_backend_resourced_memory_lmk_funcs g_lmk_funcs;
+
 static int compare_victims(const struct task_info **ta,
                        const struct task_info **tb,
                        const unsigned long *totalram_kibi_bytes)
@@ -83,27 +91,86 @@ int get_kill_candidates(GArray *candidates,
        return candidates->len;
 }
 
-static int resourced_memory_lmk_init(void **data)
+static int is_valid_candidates_list(GArray *candidates)
 {
-       syscommon_plugin_backend_resourced_memory_lmk_funcs *funcs = NULL;
+       if (!candidates)
+               return -EINVAL;
 
-       funcs = calloc(1, sizeof(*funcs));
-       if (!funcs)
-               return -ENOMEM;
+       if (!candidates->len)
+               return -EINVAL;
 
-       funcs->get_kill_candidates = get_kill_candidates;
+       return 0;
+}
 
-       *data = (void *)funcs;
+static int get_kill_candidates_post(GArray *candidates)
+{
+       return is_valid_candidates_list(candidates);
+}
+
+static int get_kill_candidates_post_with_wss(GArray *candidates)
+{
+       return is_valid_candidates_list(candidates);
+}
+
+static int get_kill_candidates_post_with_foreground(GArray *candidates,
+               enum syscommon_resourced_memory_lmk_oom_level oom_level)
+{
+       int ret = is_valid_candidates_list(candidates);
+       if (ret < 0)
+               return ret;
+
+       if (oom_level != OOM_LEVEL_FOREGROUND)
+               return 0;
+
+       for (int i = 0; i < candidates->len; ++i) {
+               /**
+                * TODO: Each task_info can have more than one window information.
+                * Therefore, trace all of windows of each task_info
+                */
+               struct task_info *task = g_array_index(candidates,
+                                                       struct task_info *, i);
+
+               if (!task)
+                       continue;
+       }
+
+       /**
+        * TODO: Reorder foreground app candidates according to policy.
+        *
+        * 1. Basically, sorting candidates from high value of z to low one.
+        * 2. If window information's is_focus is equal to 1,
+        * put it to end of candidates.
+        * 3. If task_info's oom_score_lru is OOMADJ_APP_IN_FOREGROUND_APP_LIST,
+        * put it to end of candidates.
+        * 4. App memory size is out of interest
+        *
+        * candidates will be sorted like below:
+        *
+        * |(high z) --> (low z)|(is_focused = 1)|(OOMADJ_APP_IN_FOREGROUND_APP_LIST)|
+        */
+
+       return 0;
+}
+
+static int resourced_memory_lmk_init(void **data)
+{
+       *data = (void *)&g_lmk_funcs;
 
        return 0;
 }
 
 static int resourced_memory_lmk_exit(void *data)
 {
-       free(data);
        return 0;
 }
 
+static syscommon_plugin_backend_resourced_memory_lmk_funcs g_lmk_funcs = {
+       .get_kill_candidates = get_kill_candidates,
+       .get_kill_candidates_post = get_kill_candidates_post,
+       .get_kill_candidates_post_with_wss = get_kill_candidates_post_with_wss,
+       .get_kill_candidates_post_with_foreground = get_kill_candidates_post_with_foreground,
+};
+
 syscommon_plugin_backend EXPORT system_plugin_backend_resourced_memory_lmk_data = {
        .name = "resourced-memory-lmk",
        .vendor = "Samsung",