#define INIT_PROCESS_ID 1
#define MINIMUM_Z_VALUE 1
+#define LMK_TRY_COUNT_THRESHOLD 2
+#define WSS_THRESHOLD 55
+
/**
* -900 is very low oom_score_adj (-1000 to 1000), so
* focused app will not be choosen as victim regardless of memory size.
return is_valid_candidates_list(candidates);
}
-static int get_kill_candidates_post_with_wss(GArray *candidates)
+static int calculate_working_set_size(struct task_info task, int *wss)
{
- return is_valid_candidates_list(candidates);
+ unsigned long active_memory_kb = task.active_memory_kb;
+ unsigned long inactive_memory_kb = task.inactive_memory_kb;
+ unsigned long swap_memory_kb = task.swap_memory_kb;
+ unsigned long sum_memory_kb =
+ active_memory_kb + inactive_memory_kb + swap_memory_kb;
+
+ if (!wss)
+ return -EINVAL;
+
+ /* Check whether it is app. If not, do not calculate working set size */
+ if (active_memory_kb == 0 && inactive_memory_kb == 0) {
+ *wss = -1;
+ return 0;
+ }
+
+ /**
+ * If working set size is lower than working set size threshold,
+ * then do not consider working set size of this app.
+ */
+ *wss = (active_memory_kb * 100) / sum_memory_kb;
+ if (*wss < WSS_THRESHOLD)
+ *wss = -1;
+
+ return 0;
+}
+
+static int get_kill_candidates_post_with_wss(GArray *candidates, int lmk_try_count)
+{
+ int max_wss = 0;
+ int max_wss_app_memory_size_kb = 1024 * 1024 * 1024;
+ struct task_info *max_wss_app_task = NULL;
+
+ int ret = is_valid_candidates_list(candidates);
+ if (ret < 0)
+ return ret;
+
+ if (lmk_try_count <= 0)
+ return -EINVAL;
+
+ if (lmk_try_count >= LMK_TRY_COUNT_THRESHOLD)
+ return 0;
+
+ for (int i = 0; i < candidates->len; ++i) {
+ int wss = 0;
+ struct task_info *task = g_array_index(candidates,
+ struct task_info *, i);
+
+ assert(task);
+
+ if (calculate_working_set_size(*task, &wss) < 0)
+ return -EINVAL;
+
+ if (wss < 0)
+ continue;
+
+ if (max_wss < wss) {
+ max_wss = wss;
+ max_wss_app_memory_size_kb = task->size;
+ max_wss_app_task = task;
+ } else if (max_wss == wss
+ && max_wss_app_memory_size_kb > task->size) {
+ max_wss_app_memory_size_kb = task->size;
+ max_wss_app_task = task;
+ }
+ }
+
+ /* All apps in candidates list have lower wss than WSS_THRESHOLD */
+ if (max_wss_app_task == NULL)
+ return 0;
+
+ max_wss_app_task->is_free_from_kill = true;
+
+ return 0;
}
static int get_kill_candidates_post_with_foreground(GArray *candidates,