From 11641becfc0fec2af1e06c413811bbf5f490d55f Mon Sep 17 00:00:00 2001 From: Unsung Lee Date: Thu, 17 Aug 2023 14:34:57 +0900 Subject: [PATCH] swap: Reclaim memory when LCD is off Reclaim memory from BackgroundMru memory cgroup when LCD is off to reserve memory. This is one of patch to restore BackgroundReclaim configuration of resourced 6.0. Change-Id: I3657689a11931f8f80deeaaebc64fcdc4dc35747 Signed-off-by: Unsung Lee --- src/common/notifier.h | 2 ++ src/process/proc-monitor.c | 3 ++- src/resource-limiter/memory/lowmem-controller.c | 23 +++++++++++++++++++++++ src/resource-limiter/memory/lowmem.c | 5 +++++ src/resource-limiter/memory/lowmem.h | 1 + 5 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/common/notifier.h b/src/common/notifier.h index e3cd6d4..6764554 100644 --- a/src/common/notifier.h +++ b/src/common/notifier.h @@ -112,6 +112,8 @@ enum notifier_type { RESOURCED_NOTIFIER_LOW_BATTERY, RESOURCED_NOTIFIER_CPU_ON, RESOURCED_NOTIFIER_CPU_OFF, + RESOURCED_NOTIFIER_LCD_ON, + RESOURCED_NOTIFIER_LCD_OFF, RESOURCED_NOTIFIER_DEDUP_START, RESOURCED_NOTIFIER_DEDUP_SCAN, diff --git a/src/process/proc-monitor.c b/src/process/proc-monitor.c index 3183373..eb188fe 100644 --- a/src/process/proc-monitor.c +++ b/src/process/proc-monitor.c @@ -1068,12 +1068,13 @@ static void proc_dbus_systemservice_handler(GVariant *params) EXPORT_TEST void proc_dbus_lcd_on(GVariant *params) { current_lcd_state = LCD_STATE_ON; - /* nothing */ + resourced_notify(RESOURCED_NOTIFIER_LCD_ON, NULL); } EXPORT_TEST void proc_dbus_lcd_off(GVariant *params) { current_lcd_state = LCD_STATE_OFF; + resourced_notify(RESOURCED_NOTIFIER_LCD_OFF, NULL); } EXPORT_TEST void booting_done_signal_handler(GVariant *params) diff --git a/src/resource-limiter/memory/lowmem-controller.c b/src/resource-limiter/memory/lowmem-controller.c index 7341946..ecfcf3e 100644 --- a/src/resource-limiter/memory/lowmem-controller.c +++ b/src/resource-limiter/memory/lowmem-controller.c @@ -393,6 +393,27 @@ static int lowmem_control_handler(void *data) return RESOURCED_ERROR_NONE; } +static int lowmem_bg_reclaim_handler(void *data) +{ + if (swap_get_state() != SWAP_ON) + return RESOURCED_ERROR_NONE; + + if (!is_bg_reclaim_supported()) + return RESOURCED_ERROR_NONE; + + /* + * Proactively reclaiming memory used by long-lived background processes + * (such as widget instances) may be efficient on devices with limited + * memory constraints. The pages used by such processes could be reclaimed + * (if swap is enabled) earlier than they used to while minimizing the + * impact on the user experience. + */ + resourced_notify(RESOURCED_NOTIFIER_SWAP_START, + get_memcg_info(MEMCG_BACKGROUND_MRU)->name); + + return RESOURCED_ERROR_NONE; +} + static void medium_cb(struct lowmem_control *ctl) { if (ctl->status == LOWMEM_RECLAIM_DONE) @@ -530,6 +551,7 @@ static int lowmem_controller_initialize(void *data) lowmem_register_mem_level_controller(MEM_LEVEL_OOM, oom_mem_control); register_notifier(RESOURCED_NOTIFIER_MEM_CONTROL, lowmem_control_handler); + register_notifier(RESOURCED_NOTIFIER_LCD_OFF, lowmem_bg_reclaim_handler); return RESOURCED_ERROR_NONE; } @@ -537,6 +559,7 @@ static int lowmem_controller_initialize(void *data) static int lowmem_controller_finalize(void *data) { unregister_notifier(RESOURCED_NOTIFIER_MEM_CONTROL, lowmem_control_handler); + unregister_notifier(RESOURCED_NOTIFIER_LCD_OFF, lowmem_bg_reclaim_handler); return RESOURCED_ERROR_NONE; } diff --git a/src/resource-limiter/memory/lowmem.c b/src/resource-limiter/memory/lowmem.c index 1a68b63..e059094 100644 --- a/src/resource-limiter/memory/lowmem.c +++ b/src/resource-limiter/memory/lowmem.c @@ -315,6 +315,11 @@ static int fragmentation_size; static bool g_bg_reclaim = false; +bool is_bg_reclaim_supported(void) +{ + return g_bg_reclaim; +} + const char *lowmem_convert_cgroup_type_to_str(int type) { static const char *type_table[] = diff --git a/src/resource-limiter/memory/lowmem.h b/src/resource-limiter/memory/lowmem.h index 8fcf313..a3a8e94 100644 --- a/src/resource-limiter/memory/lowmem.h +++ b/src/resource-limiter/memory/lowmem.h @@ -139,6 +139,7 @@ int lowmem_queue_new_request(unsigned int flags, void (*callback) (struct lowmem_control *)); void lowmem_set_oom_popup(bool popup); int lowmem_get_num_max_victims(); +bool is_bg_reclaim_supported(void); #ifdef __cplusplus } -- 2.7.4