diff options
author | SangYoun Kwak <sy.kwak@samsung.com> | 2023-02-15 18:04:33 +0900 |
---|---|---|
committer | SangYoun Kwak <sy.kwak@samsung.com> | 2023-04-07 16:59:04 +0900 |
commit | ed3bc1648d8d0ff804963521baf37634f2106f34 (patch) | |
tree | 5f050c57851fa9113dc5b83116b653f62416899e | |
parent | db5ec6c73c99ce3cc79c938ecaa7acc8bf2b3750 (diff) | |
download | resourced-ed3bc1648d8d0ff804963521baf37634f2106f34.tar.gz resourced-ed3bc1648d8d0ff804963521baf37634f2106f34.tar.bz2 resourced-ed3bc1648d8d0ff804963521baf37634f2106f34.zip |
lowmem-governor: Move governor to plugin-backend
lowmem-governor was moved from lowmem to plugin-backend-resourced.
lowmem module can use governor through the functions of
plugin-resourced.
* "plugin_resourced_memory_lmk_get_kill_candidates" is a function of
the plugin-backend-resourced. Kill candidates can be retrieved using
this function.
* plugin-api-resourced was added to the BuildRequires.
Change-Id: I3d010ee15cf74447ce4a354808bb662674670972
Signed-off-by: SangYoun Kwak <sy.kwak@samsung.com>
-rw-r--r-- | packaging/resourced.spec | 1 | ||||
-rw-r--r-- | src/CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/resource-limiter/memory/lowmem-governor.c | 62 | ||||
-rw-r--r-- | src/resource-limiter/memory/lowmem.h | 30 |
4 files changed, 6 insertions, 88 deletions
diff --git a/packaging/resourced.spec b/packaging/resourced.spec index a618e631..efbbb63d 100644 --- a/packaging/resourced.spec +++ b/packaging/resourced.spec @@ -42,6 +42,7 @@ BuildRequires: pkgconfig(capi-system-device) BuildRequires: pkgconfig(capi-system-resource) BuildRequires: pkgconfig(cmocka) BuildRequires: pkgconfig(libsyscommon) +BuildRequires: pkgconfig(plugin-api-resourced) Requires(post): %{_sbindir}/update-alternatives Requires(preun): %{_sbindir}/update-alternatives diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 6ac55382..a4908f0f 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -110,6 +110,7 @@ SET(REQUIRES_LIST ${REQUIRES_LIST} libudev dbus-1 libsyscommon + plugin-api-resourced ) INCLUDE(FindPkgConfig) diff --git a/src/resource-limiter/memory/lowmem-governor.c b/src/resource-limiter/memory/lowmem-governor.c index 1409a919..0a7e800b 100644 --- a/src/resource-limiter/memory/lowmem-governor.c +++ b/src/resource-limiter/memory/lowmem-governor.c @@ -21,72 +21,14 @@ * @desc Provides governor function to sort out candidate process to kill. */ -#include <stdlib.h> -#include <glib.h> -#include <assert.h> -#include <stdbool.h> +#include <plugin/plugin-resourced-memory-lmk.h> #include "lowmem.h" -#include "trace.h" #include "module.h" -static int compare_victims(const struct task_info **ta, - const struct task_info **tb, - const unsigned long *totalram_kb) -{ - 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_kb / 2000) + (*ta)->size; - pb = (*tb)->oom_score_lru * (*totalram_kb / 2000) + (*tb)->size; - - return pb - pa; -} - -int lowmem_governor_get_kill_candidates(GArray *candidates, - GArray *task_info_app_array, - GArray *task_info_proc_array, - unsigned long totalram_kb) -{ - if (!candidates) - return -1; - - 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; - g_array_append_val(candidates, task); - } - - if (!candidates->len) - return 0; - - 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); - } - } - - g_array_sort_with_data(candidates, (GCompareDataFunc)compare_victims, - &totalram_kb); - - return candidates->len; -} - static int lowmem_governor_initialize(void *data) { - lowmem_initialize_governor_ops(lowmem_governor_get_kill_candidates); + lowmem_initialize_governor_ops(plugin_resourced_memory_lmk_get_kill_candidates); return RESOURCED_ERROR_NONE; } diff --git a/src/resource-limiter/memory/lowmem.h b/src/resource-limiter/memory/lowmem.h index e365c2f4..c434148b 100644 --- a/src/resource-limiter/memory/lowmem.h +++ b/src/resource-limiter/memory/lowmem.h @@ -29,6 +29,8 @@ #include <proc-common.h> #include <memory-cgroup.h> +#include <plugin/plugin-resourced-memory-lmk.h> + #include "fd-handler.h" #ifdef __cplusplus @@ -37,34 +39,6 @@ extern "C" { #define MAX_MEMORY_CGROUP_VICTIMS 10 -struct task_info { - /** - * Mostly, there are not multiple processes with the same pgid. - * So, for the frequent case, we use pid variable to avoid - * allocating arrays. - */ - pid_t pid; - GArray *pids; - pid_t pgid; - int oom_score_adj; /* equal to /proc/<pid>/oom_score_adj */ - /** - * oom_score_lru is equal to oom_score_adj - * or adjusted by proc_app_info's lru_state - * for apps that are marked as favourite. - * It can be used to compare between apps/procs for LMK. - */ - int oom_score_lru; - int size; - /** - * proc_app_info_oom_killed and proc_app_info_flags - * are not used if task is not an app. - * Especially, proc_app_info_oom_killed is NULL when this task - * is not an app - */ - bool *proc_app_info_oom_killed; - int proc_app_info_flags; -}; - unsigned int lowmem_get_task_mem_usage_rss(const struct task_info *tsk); void lowmem_trigger_swap(pid_t pid, char *path, bool move); int lowmem_trigger_reclaim(int flags, int victims, enum oom_score score, int threshold); |