#define EXPORT __attribute__ ((visibility("default")))
+/**
+ * -900 is very low oom_score_adj (-1000 to 1000), so
+ * focused app will not be choosen as victim regardless of memory size.
+ */
+#define OOMADJ_APP_IN_FOREGROUND_APP_LIST -900
+
+static syscommon_plugin_backend_resourced_memory_lmk_funcs g_lmk_funcs;
+
static int compare_victims(const struct task_info **ta,
const struct task_info **tb,
const unsigned long *totalram_kibi_bytes)
return candidates->len;
}
-static int resourced_memory_lmk_init(void **data)
+static int is_valid_candidates_list(GArray *candidates)
{
- syscommon_plugin_backend_resourced_memory_lmk_funcs *funcs = NULL;
+ if (!candidates)
+ return -EINVAL;
- funcs = calloc(1, sizeof(*funcs));
- if (!funcs)
- return -ENOMEM;
+ if (!candidates->len)
+ return -EINVAL;
- funcs->get_kill_candidates = get_kill_candidates;
+ return 0;
+}
- *data = (void *)funcs;
+static int get_kill_candidates_post(GArray *candidates)
+{
+ return is_valid_candidates_list(candidates);
+}
+
+static int get_kill_candidates_post_with_wss(GArray *candidates)
+{
+ return is_valid_candidates_list(candidates);
+}
+
+static int get_kill_candidates_post_with_foreground(GArray *candidates,
+ enum syscommon_resourced_memory_lmk_oom_level oom_level)
+{
+ int ret = is_valid_candidates_list(candidates);
+ if (ret < 0)
+ return ret;
+
+ if (oom_level != OOM_LEVEL_FOREGROUND)
+ return 0;
+
+ for (int i = 0; i < candidates->len; ++i) {
+ /**
+ * TODO: Each task_info can have more than one window information.
+ * Therefore, trace all of windows of each task_info
+ */
+ struct task_info *task = g_array_index(candidates,
+ struct task_info *, i);
+
+ if (!task)
+ continue;
+ }
+
+ /**
+ * TODO: Reorder foreground app candidates according to policy.
+ *
+ * 1. Basically, sorting candidates from high value of z to low one.
+ * 2. If window information's is_focus is equal to 1,
+ * put it to end of candidates.
+ * 3. If task_info's oom_score_lru is OOMADJ_APP_IN_FOREGROUND_APP_LIST,
+ * put it to end of candidates.
+ * 4. App memory size is out of interest
+ *
+ * candidates will be sorted like below:
+ *
+ * |(high z) --> (low z)|(is_focused = 1)|(OOMADJ_APP_IN_FOREGROUND_APP_LIST)|
+ */
+
+ return 0;
+}
+
+static int resourced_memory_lmk_init(void **data)
+{
+ *data = (void *)&g_lmk_funcs;
return 0;
}
static int resourced_memory_lmk_exit(void *data)
{
- free(data);
return 0;
}
+static syscommon_plugin_backend_resourced_memory_lmk_funcs g_lmk_funcs = {
+ .get_kill_candidates = get_kill_candidates,
+ .get_kill_candidates_post = get_kill_candidates_post,
+ .get_kill_candidates_post_with_wss = get_kill_candidates_post_with_wss,
+ .get_kill_candidates_post_with_foreground = get_kill_candidates_post_with_foreground,
+};
+
syscommon_plugin_backend EXPORT system_plugin_backend_resourced_memory_lmk_data = {
.name = "resourced-memory-lmk",
.vendor = "Samsung",