lowmem: Set fixed oom_score_adj of foreground app during LMK 93/294693/17
authorUnsung Lee <unsung.lee@samsung.com>
Fri, 23 Jun 2023 04:19:17 +0000 (13:19 +0900)
committerUnsung Lee <unsung.lee@samsung.com>
Mon, 31 Jul 2023 02:35:06 +0000 (11:35 +0900)
Set fixed oom_score_adj during LMK process when app is foreground
and foreground oom_score_adj is fixed.

resourced LMK considers oom_score_adj and memory size to choose vicitim when
available memory size is too low. Meanwhile, some apps should not be killed
by LMK when apps are foreground (visible to user).
This configuration can protect foreground apps when LMK is triggered by
fixing low oom_score_adj.

If foreground oom_score_adj is already fixed by the configuration and
App is foreground, then oom_score_adj of 'task_info' gets value from
the fixed oom_score_adj (very low value).

Change-Id: Idbc1352a1994f7bc5363159021117b8b0e79f2a4
Signed-off-by: Unsung Lee <unsung.lee@samsung.com>
src/process/proc-main.c
src/resource-limiter/memory/lowmem.c

index 6881605..b09f2dd 100644 (file)
@@ -808,6 +808,7 @@ __attribute__((weak)) struct proc_app_info *proc_create_app_info(const char *app
                pai->memory.use_mem_limit = false;
                pai->memory.oom_killed = false;
                pai->memory.memlimit_update_exclude = false;
+               pai->memory.foreground_oom_score_adj = OOMADJ_APP_MAX + 10;
 
                if (fixed_app_list_get()) {
                        int error;
index b988396..e3c9c30 100644 (file)
@@ -505,6 +505,19 @@ static int is_app(pid_t pid)
        return 1;
 }
 
+static bool is_foreground_app(int oom_score_adj,
+               int foreground_oom_score_adj)
+{
+       if (oom_score_adj != OOMADJ_FOREGRD_LOCKED &&
+               oom_score_adj != OOMADJ_FOREGRD_UNLOCKED)
+               return false;
+
+       if (foreground_oom_score_adj > OOMADJ_APP_MAX)
+               return false;
+
+       return true;
+}
+
 static GArray *lowmem_get_task_info_app(int killer_flags, int start_oom, int end_oom)
 {
        GSList *iter = NULL;
@@ -559,6 +572,9 @@ static GArray *lowmem_get_task_info_app(int killer_flags, int start_oom, int end
                        task.oom_score_lru =
                                OOMADJ_FAVORITE + OOMADJ_FAVORITE_APP_INCREASE
                                * pai->lru_state;
+               } else if (is_foreground_app(pai->memory.oom_score_adj,
+                                       pai->memory.foreground_oom_score_adj)) {
+                       task.oom_score_lru = pai->memory.foreground_oom_score_adj;
                } else {
                        task.oom_score_lru = pai->memory.oom_score_adj;
                }