+++ /dev/null
-/**
- * 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 <glib.h>
-
-#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;
-}
+++ /dev/null
-/**
- * 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__ */
*/
#include <stdlib.h>
+#include <glib.h>
+#include <assert.h>
+#include <stdbool.h>
#include <plugin/plugin-common-interface.h>
+#include <plugin/plugin-resourced-memory-lmk.h>
#include <plugin/plugin-resourced-memory-lmk-interface.h>
#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;
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;