lowmem-governor: Move governor to plugin-backend 38/288338/26
authorSangYoun Kwak <sy.kwak@samsung.com>
Wed, 15 Feb 2023 09:04:33 +0000 (18:04 +0900)
committerSangYoun Kwak <sy.kwak@samsung.com>
Fri, 7 Apr 2023 07:59:04 +0000 (16:59 +0900)
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>
packaging/resourced.spec
src/CMakeLists.txt
src/resource-limiter/memory/lowmem-governor.c
src/resource-limiter/memory/lowmem.h

index a618e631ab894091ffab6e5cd8fd1e556d8f017e..efbbb63d2d5f2a1eee586a70370c78f964e40c46 100644 (file)
@@ -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
index 6ac553821f640e060ccf160570f5d522ebce46eb..a4908f0ff2597cc0e4b612cfb38927b39c60a013 100644 (file)
@@ -110,6 +110,7 @@ SET(REQUIRES_LIST ${REQUIRES_LIST}
        libudev
        dbus-1
        libsyscommon
+       plugin-api-resourced
   )
 
 INCLUDE(FindPkgConfig)
index 1409a919997e7afd3ff290583c7bca9e49990883..0a7e800b9281361aa4bac753725fa04363083a6e 100644 (file)
  * @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;
 }
 
index e365c2f47ece028ef8ecfc3f6fc53484b98cc611..c434148bd948aca752b23a7b1b3af94fda87ec0b 100644 (file)
@@ -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);