lmkd: introduce lowmem_min_oom_score tunable

Current lmkd behavior to kill cached apps when free memory hits low
watermark threshold does not work well on certain devices where more
or less aggressive behavior would yield better results. Introduce a
tunable to control the min oom_score_adj level at which lmkd considers
to kill processes when the system gets into this state. The default
value is set to 701 which preserves the current behavior of killing
cached apps except for the last active one. Setting it to lower values
will make more processes eligible to be killed, setting it to higher
values will limit the kills to a smaller set of processes. Setting it
to 1001 will prevent any process from being killed for this reason.

Bug: 334867461
Bug: 337063274
Change-Id: I1447436e0a0cd1e696b34d2c06b92ff73a5100a9
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
This commit is contained in:
Suren Baghdasaryan 2024-04-25 09:01:13 -07:00
parent 02de7905e5
commit 3dc50798a3
3 changed files with 16 additions and 1 deletions

View File

@ -100,6 +100,12 @@ properties:
to 0 will ignore available memory and assume that to 0 will ignore available memory and assume that
configured swap size can be always utilized fully. configured swap size can be always utilized fully.
Default = 1 (no compression). Default = 1 (no compression).
- `ro.lmk.lowmem_min_oom_score`: min oom_score_adj level used to select processes
to kill when memory is critically low. Setting it
to 1001 will prevent any kills for this reason. Min
acceptable value is 201 (apps up to perceptible).
Default = 701 (all cached apps excluding the last
active one).
lmkd will set the following Android properties according to current system lmkd will set the following Android properties according to current system
configurations: configurations:

View File

@ -164,6 +164,8 @@ static inline void trace_kill_end() {}
#define DEF_DIRECT_RECL_THRESH_MS 0 #define DEF_DIRECT_RECL_THRESH_MS 0
/* ro.lmk.swap_compression_ratio property defaults */ /* ro.lmk.swap_compression_ratio property defaults */
#define DEF_SWAP_COMP_RATIO 1 #define DEF_SWAP_COMP_RATIO 1
/* ro.lmk.lowmem_min_oom_score defaults */
#define DEF_LOWMEM_MIN_SCORE (PREVIOUS_APP_ADJ + 1)
#define LMKD_REINIT_PROP "lmkd.reinit" #define LMKD_REINIT_PROP "lmkd.reinit"
@ -235,6 +237,7 @@ static int kpoll_fd;
static bool delay_monitors_until_boot; static bool delay_monitors_until_boot;
static int direct_reclaim_threshold_ms; static int direct_reclaim_threshold_ms;
static int swap_compression_ratio; static int swap_compression_ratio;
static int lowmem_min_oom_score;
static struct psi_threshold psi_thresholds[VMPRESS_LEVEL_COUNT] = { static struct psi_threshold psi_thresholds[VMPRESS_LEVEL_COUNT] = {
{ PSI_SOME, 70 }, /* 70ms out of 1sec for partial stall */ { PSI_SOME, 70 }, /* 70ms out of 1sec for partial stall */
{ PSI_SOME, 100 }, /* 100ms out of 1sec for partial stall */ { PSI_SOME, 100 }, /* 100ms out of 1sec for partial stall */
@ -2932,7 +2935,7 @@ update_watermarks:
kill_reason = LOW_MEM; kill_reason = LOW_MEM;
snprintf(kill_desc, sizeof(kill_desc), "%s watermark is breached", snprintf(kill_desc, sizeof(kill_desc), "%s watermark is breached",
wmark < WMARK_LOW ? "min" : "low"); wmark < WMARK_LOW ? "min" : "low");
min_score_adj = PREVIOUS_APP_ADJ + 1; min_score_adj = lowmem_min_oom_score;
} }
/* Kill a process if necessary */ /* Kill a process if necessary */
@ -4016,6 +4019,9 @@ static bool update_props() {
GET_LMK_PROPERTY(int64, "direct_reclaim_threshold_ms", DEF_DIRECT_RECL_THRESH_MS); GET_LMK_PROPERTY(int64, "direct_reclaim_threshold_ms", DEF_DIRECT_RECL_THRESH_MS);
swap_compression_ratio = swap_compression_ratio =
GET_LMK_PROPERTY(int64, "swap_compression_ratio", DEF_SWAP_COMP_RATIO); GET_LMK_PROPERTY(int64, "swap_compression_ratio", DEF_SWAP_COMP_RATIO);
lowmem_min_oom_score =
std::max(PERCEPTIBLE_APP_ADJ + 1,
GET_LMK_PROPERTY(int32, "lowmem_min_oom_score", DEF_LOWMEM_MIN_SCORE));
reaper.enable_debug(debug_process_killing); reaper.enable_debug(debug_process_killing);

View File

@ -58,3 +58,6 @@ on property:persist.device_config.lmkd_native.direct_reclaim_threshold_ms=*
on property:persist.device_config.lmkd_native.swap_compression_ratio=* on property:persist.device_config.lmkd_native.swap_compression_ratio=*
setprop lmkd.reinit ${sys.boot_completed:-0} setprop lmkd.reinit ${sys.boot_completed:-0}
on property:persist.device_config.lmkd_native.lowmem_min_oom_score=*
setprop lmkd.reinit ${sys.boot_completed:-0}