lmkd: introduce swap_compression_ratio tunable am: 63dd69984d am: 42dba7a8e0

Original change: https://android-review.googlesource.com/c/platform/system/memory/lmkd/+/2620611

Change-Id: If85c22d8ca73941e3be74fe5a5e060a59c1482d7
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Suren Baghdasaryan 2024-04-05 05:23:34 +00:00 committed by Automerger Merge Worker
commit 5ef52d6f01
3 changed files with 18 additions and 1 deletions

View File

@ -95,6 +95,11 @@ properties:
- `ro.lmk.direct_reclaim_threshold_ms`: direct reclaim duration threshold in - `ro.lmk.direct_reclaim_threshold_ms`: direct reclaim duration threshold in
milliseconds to consider the system as stuck in milliseconds to consider the system as stuck in
direct reclaim. Default = 0 (disabled) direct reclaim. Default = 0 (disabled)
- `ro.lmk.swap_compression_ratio`: swap average compression ratio to be used when
estimating how much data can be swapped. Setting it
to 0 will ignore available memory and assume that
configured swap size can be always utilized fully.
Default = 1 (no compression).
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

@ -162,6 +162,8 @@ static inline void trace_kill_end() {}
#define DEF_COMPLETE_STALL 700 #define DEF_COMPLETE_STALL 700
/* ro.lmk.direct_reclaim_threshold_ms property defaults */ /* ro.lmk.direct_reclaim_threshold_ms property defaults */
#define DEF_DIRECT_RECL_THRESH_MS 0 #define DEF_DIRECT_RECL_THRESH_MS 0
/* ro.lmk.swap_compression_ratio property defaults */
#define DEF_SWAP_COMP_RATIO 1
#define LMKD_REINIT_PROP "lmkd.reinit" #define LMKD_REINIT_PROP "lmkd.reinit"
@ -232,6 +234,7 @@ static bool use_psi_monitors = false;
static int kpoll_fd; 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 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 */
@ -1946,8 +1949,12 @@ static int meminfo_parse(union meminfo *mi) {
// from the free memory or reclaimed. Use the lowest of free_swap and easily available memory to // from the free memory or reclaimed. Use the lowest of free_swap and easily available memory to
// measure free swap because they represent how much swap space the system will consider to use // measure free swap because they represent how much swap space the system will consider to use
// and how much it can actually use. // and how much it can actually use.
// Swap compression ratio in the calculation can be adjusted using swap_compression_ratio tunable.
// By setting swap_compression_ratio to 0, available memory can be ignored.
static inline int64_t get_free_swap(union meminfo *mi) { static inline int64_t get_free_swap(union meminfo *mi) {
return std::min(mi->field.free_swap, mi->field.easy_available); if (swap_compression_ratio)
return std::min(mi->field.free_swap, mi->field.easy_available * swap_compression_ratio);
return mi->field.free_swap;
} }
/* /proc/vmstat parsing routines */ /* /proc/vmstat parsing routines */
@ -3998,6 +4005,8 @@ static bool update_props() {
delay_monitors_until_boot = GET_LMK_PROPERTY(bool, "delay_monitors_until_boot", false); delay_monitors_until_boot = GET_LMK_PROPERTY(bool, "delay_monitors_until_boot", false);
direct_reclaim_threshold_ms = direct_reclaim_threshold_ms =
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 =
GET_LMK_PROPERTY(int64, "swap_compression_ratio", DEF_SWAP_COMP_RATIO);
reaper.enable_debug(debug_process_killing); reaper.enable_debug(debug_process_killing);

View File

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