From: SangYoun Kwak Date: Wed, 15 Feb 2023 08:59:04 +0000 (+0900) Subject: resourced-memory-lmk: Add governor function X-Git-Tag: accepted/tizen/unified/20230607.160238~9 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d0969fde1629a310318961264465db3412b63e75;p=platform%2Fcore%2Fsystem%2Fplugin%2Fresourced-generic.git resourced-memory-lmk: Add governor function The "get_kill_candidates" function has been added to the resourced-memory-lmk module. This function has been separated from lowmem module of resourced. Signed-off-by: SangYoun Kwak --- diff --git a/packaging/plugin-backend-resourced-rpi.spec b/packaging/plugin-backend-resourced-rpi.spec index b7cca95..645d139 100644 --- a/packaging/plugin-backend-resourced-rpi.spec +++ b/packaging/plugin-backend-resourced-rpi.spec @@ -26,6 +26,7 @@ cp %{SOURCE1} . %build %cmake . -DENABLE_DLOG=1 \ + -DPLUGIN_BACKEND_RESOURCED_MEMORY_LMK_ENABLE_DLOG=1 \ -DPLUGIN_NAME=%{name} \ -DPLUGIN_LICENSE_DIR=%{PLUGIN_LICENSEDIR} \ -DPLUGIN_LIB_DIR=%{PLUGIN_LIBDIR} diff --git a/src/resourced-memory-lmk/resourced-memory-lmk-governor.c b/src/resourced-memory-lmk/resourced-memory-lmk-governor.c deleted file mode 100644 index 2251e58..0000000 --- a/src/resourced-memory-lmk/resourced-memory-lmk-governor.c +++ /dev/null @@ -1,29 +0,0 @@ -/** - * plugin-backend-resourced-rpi - * - * Copyright (c) 2023 Samsung Electronics Co., Ltd. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include - -#include "common.h" -#include "resourced-memory-lmk-governor.h" - -GArray *lowmem_governor_get_kill_candidates(GSList *proc_app_list, int start_oom, int end_oom, int killer_flags) -{ - _D("lowmem_governor_get_kill_candidates called"); - - return NULL; -} diff --git a/src/resourced-memory-lmk/resourced-memory-lmk-governor.h b/src/resourced-memory-lmk/resourced-memory-lmk-governor.h deleted file mode 100644 index 9328607..0000000 --- a/src/resourced-memory-lmk/resourced-memory-lmk-governor.h +++ /dev/null @@ -1,24 +0,0 @@ -/** - * plugin-backend-resourced-rpi - * - * Copyright (c) 2023 Samsung Electronics Co., Ltd. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef __RESOURCED_MEMORY_LMK_GOVERNOR_H__ -#define __RESOURCED_MEMORY_LMK_GOVERNOR_H__ - -GArray *lowmem_governor_get_kill_candidates(GSList *proc_app_list, int start_oom, int end_oom, int killer_flags); - -#endif /* __RESOURCED_MEMORY_LMK_GOVERNOR_H__ */ diff --git a/src/resourced-memory-lmk/resourced-memory-lmk.c b/src/resourced-memory-lmk/resourced-memory-lmk.c index 39b0b4a..24af625 100644 --- a/src/resourced-memory-lmk/resourced-memory-lmk.c +++ b/src/resourced-memory-lmk/resourced-memory-lmk.c @@ -17,23 +17,84 @@ */ #include +#include +#include +#include #include +#include #include #include "common.h" -#include "resourced-memory-lmk-governor.h" /* TODO: Remove this line */ #define EXPORT __attribute__ ((visibility("default"))) -/* -GArray *get_kill_candidates(GSList *proc_app_list, int start_oom, int end_oom, int killer_flags) +static int compare_victims(const struct task_info **ta, + const struct task_info **tb, + const unsigned long *totalram_kibi_bytes) { - return NULL; + unsigned int pa, pb; + + assert(ta != NULL); + assert(tb != NULL); + assert(*ta != NULL); + assert(*tb != NULL); + /** + * followed by kernel badness point calculation using heuristic. + * oom_score_adj is normalized by its unit, which varies -1000 ~ 1000. + */ + pa = (*ta)->oom_score_lru * (*totalram_kibi_bytes / 2000) + (*ta)->size; + pb = (*tb)->oom_score_lru * (*totalram_kibi_bytes / 2000) + (*tb)->size; + + return pb - pa; +} + +static GArray *get_kill_candidates(GArray *task_info_app_array, + GArray *task_info_proc_array, + int start_oom, int end_oom, + unsigned long totalram_kibi_bytes) +{ + GArray *candidates = + g_array_new(false, false, sizeof(struct task_info *)); + + for (int i = 0; i < task_info_app_array->len; ++i) { + struct task_info *task = &g_array_index(task_info_app_array, + struct task_info, i); + + if (!task->pid) + continue; + + if (task->oom_score_adj > end_oom + || task->oom_score_adj < start_oom) + continue; + + g_array_append_val(candidates, task); + } + + _D("Apps candidate ratio=%d/%d", + candidates->len, task_info_app_array->len); + + if (!candidates->len) { + return candidates; + } + + if (task_info_proc_array) { + for (int i = 0; i < task_info_proc_array->len; ++i) { + struct task_info *task = + &g_array_index(task_info_proc_array, + struct task_info, i); + g_array_append_val(candidates, task); + } + _D("%d processes were added to candidate", task_info_proc_array->len); + } + + g_array_sort_with_data(candidates, (GCompareDataFunc)compare_victims, + &totalram_kibi_bytes); + + return candidates; } -*/ -int resourced_memory_lmk_init(void **data) +static int resourced_memory_lmk_init(void **data) { plugin_backend_resourced_memory_lmk_funcs *funcs = NULL; @@ -41,15 +102,14 @@ int resourced_memory_lmk_init(void **data) if (!funcs) return -ENOMEM; - /* funcs->get_kill_candidates = get_kill_candidates; */ /* TODO: Use this line instead of a line below */ - funcs->get_kill_candidates = lowmem_governor_get_kill_candidates; /* TODO: Remove this line */ + funcs->get_kill_candidates = get_kill_candidates; *data = (void *)funcs; return 0; } -int resourced_memory_lmk_exit(void *data) +static int resourced_memory_lmk_exit(void *data) { free(data); return 0;