#include <assert.h>
#include <stdbool.h>
+#include "lowmem.h"
#include "trace.h"
-#include "lowmem-governor.h"
+#include "module.h"
static int compare_victims(const struct task_info **ta,
const struct task_info **tb,
return candidates->len;
}
+
+static int lowmem_governor_initialize(void *data)
+{
+ lowmem_initialize_governor_ops(lowmem_governor_get_kill_candidates);
+ return RESOURCED_ERROR_NONE;
+}
+
+static int lowmem_governor_finalize(void *data)
+{
+ return RESOURCED_ERROR_NONE;
+}
+
+static struct module_ops lowmem_governor_module_ops = {
+ .priority = MODULE_PRIORITY_INITIAL,
+ .name = "lowmem-governor",
+ .init = lowmem_governor_initialize,
+ .exit = lowmem_governor_finalize,
+};
+
+MODULE_REGISTER(&lowmem_governor_module_ops)
+++ /dev/null
-/*
- * resourced
- *
- * 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.
- *
- */
-
-/**
- * @file lowmem-governor.h
- * @desc Function and structure for governor feature.
- **/
-
-#ifndef __LOWMEM_GOVERNOR_H__
-#define __LOWMEM_GOVERNOR_H__
-
-#include <stdbool.h>
-
-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;
-};
-
-int lowmem_governor_get_kill_candidates(GArray *candidates,
- GArray *task_info_app_array,
- GArray *task_info_proc_array,
- unsigned long totalram_kb);
-
-#endif /* __LOWMEM_GOVERNOR_H__ */
return lowmem_task_info_proc_array;
}
+struct lowmem_governor_ops {
+ int(*get_kill_candidates)(GArray *, GArray *, GArray *, unsigned long);
+};
+
+static struct lowmem_governor_ops governor_ops = { NULL };
+void lowmem_initialize_governor_ops(int(*get_kill_candidates)(GArray *,
+ GArray *, GArray *, unsigned long))
+{
+ governor_ops.get_kill_candidates = get_kill_candidates;
+}
+
/**
* @brief Terminate up to max_victims processes after finding them from pai.
It depends on proc_app_info lists
if (!lowmem_kill_candidates)
lowmem_kill_candidates = g_array_new(false, false, sizeof(struct task_info *));
- candidates_cnt = lowmem_governor_get_kill_candidates(lowmem_kill_candidates,
- task_info_app_array,
- task_info_proc_array,
- totalram_kb);
+ assert(governor_ops.get_kill_candidates != NULL);
+ candidates_cnt = governor_ops.get_kill_candidates(
+ lowmem_kill_candidates,
+ task_info_app_array,
+ task_info_proc_array,
+ totalram_kb);
_D("[LMK] candidates_cnt=%d", candidates_cnt);
if (candidates_cnt <= 0) {
#include <memory-cgroup.h>
#include "fd-handler.h"
-#include "lowmem-governor.h"
#ifdef __cplusplus
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);
LOWMEM_RECLAIM_NEXT_TYPE
};
+void lowmem_initialize_governor_ops(int(*)(GArray *, GArray *, GArray *,
+ unsigned long));
+
#ifdef __cplusplus
}
#endif /* __cplusplus */