swap: Reclaim memory when LCD is off 90/303590/1
authorUnsung Lee <unsung.lee@samsung.com>
Thu, 17 Aug 2023 05:34:57 +0000 (14:34 +0900)
committerUnsung Lee <unsung.lee@samsung.com>
Tue, 2 Jan 2024 08:44:24 +0000 (17:44 +0900)
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 <unsung.lee@samsung.com>
src/common/notifier.h
src/process/proc-monitor.c
src/resource-limiter/memory/lowmem-controller.c
src/resource-limiter/memory/lowmem.c
src/resource-limiter/memory/lowmem.h

index e3cd6d4..6764554 100644 (file)
@@ -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,
index 3183373..eb188fe 100644 (file)
@@ -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)
index 7341946..ecfcf3e 100644 (file)
@@ -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;
 }
index 1a68b63..e059094 100644 (file)
@@ -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[] =
index 8fcf313..a3a8e94 100644 (file)
@@ -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
 }