lmkd: introduce swap_compression_ratio tunable

Free swap is calculated using the min of free swap that kernel would
consider using and easily available memory which can be used by ZRAM
for swapping purposes. However calculation does not consider the
average data compression ratio of ZRAM. Introduce a tunable to set
the average swap compression ratio used when evaluating the amount
of data which can be swapped. Default is set to 1 (no compression)
to keep current behavior. Setting it to 0 will ignore available memory
and assume that configured swap size can be always utilized fully.

Bug: 285854307
Bug: 327561101
Change-Id: I6b0f93ce24179ebf7365a3dbcd52c6e4a52ac200
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
This commit is contained in:
Suren Baghdasaryan 2023-06-08 20:51:20 +00:00
parent 6593e2cee6
commit 63dd69984d
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}