swap: Reclaim memory when LCD is off 20/302620/2
authorUnsung Lee <unsung.lee@samsung.com>
Thu, 17 Aug 2023 05:34:57 +0000 (14:34 +0900)
committerUnsung Lee <unsung.lee@samsung.com>
Thu, 28 Dec 2023 09:30:01 +0000 (18:30 +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 e3cd6d41c1a45e3bdeb370fbe9d19a08985309d4..676455477b8d3c8a8e57ef8319ac8b58a327f542 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 318337363585c58bdbaadf4664210e1ca50d1d49..eb188fedcf98314c895d5d72dab93c678f666af7 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 7341946f7ee2a83dcd643da0aa70fab64fde878d..ecfcf3e950389ff5d56b5ab564bfc5c111eea0b1 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 1a68b63ab8ad8d16ad96e97f82e08fc005727d8b..e059094cdbd16a7b7408437de4971dc388db7d21 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 8fcf313be3c38e8bdabfb2066ea8efb4591ae444..a3a8e94a5c4f57cc44e98f541faeeb003df8fa85 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
 }