From: Unsung Lee Date: Fri, 30 Jun 2023 06:16:14 +0000 (+0900) Subject: resourced-memory-lmk: Add a skeleton of get_kill_candidates_post funcs X-Git-Tag: accepted/tizen/unified/20230803.174803~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ddd4b421b8486d5edfd402b9bc26bac6c0f2d0ab;p=platform%2Fcore%2Fsystem%2Fplugin%2Fresourced-generic.git resourced-memory-lmk: Add a skeleton of get_kill_candidates_post funcs 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 --- diff --git a/src/resourced-memory-lmk/resourced-memory-lmk.c b/src/resourced-memory-lmk/resourced-memory-lmk.c index 03a6a6b..c506942 100644 --- a/src/resourced-memory-lmk/resourced-memory-lmk.c +++ b/src/resourced-memory-lmk/resourced-memory-lmk.c @@ -29,6 +29,14 @@ #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",