swap: Reclaim memory when LCD is off 07/297407/2 accepted/tizen/7.0/unified/20230821.170212
authorUnsung Lee <unsung.lee@samsung.com>
Thu, 17 Aug 2023 05:34:57 +0000 (14:34 +0900)
committerUnsung Lee <unsung.lee@samsung.com>
Fri, 18 Aug 2023 02:36:40 +0000 (11:36 +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.c

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 62485850e5128a934ca46758b05e8d9ab0eace83..474d76aad31eca37003eba93bd333865461fbba3 100644 (file)
@@ -824,12 +824,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 7b990d3dcdd22d01588b6a686c7f44e355e16bc2..08c82a6f2790f6d6f7842b6d2f54ae3504b5e0de 100644 (file)
@@ -1365,6 +1365,27 @@ 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 (!g_bg_reclaim)
+                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 inline int calculate_threshold_size(double ratio)
 {
        unsigned long long size_bytes = (double)totalram_bytes * ratio / 100.0;
@@ -1498,6 +1519,7 @@ static int lowmem_init(void)
 
        register_notifier(RESOURCED_NOTIFIER_APP_PRELAUNCH, lowmem_prelaunch_handler);
        register_notifier(RESOURCED_NOTIFIER_MEM_CONTROL, lowmem_control_handler);
+       register_notifier(RESOURCED_NOTIFIER_LCD_OFF, lowmem_bg_reclaim_handler);
 
        return ret;
 }
@@ -1510,6 +1532,7 @@ static int lowmem_exit(void)
 
        unregister_notifier(RESOURCED_NOTIFIER_APP_PRELAUNCH, lowmem_prelaunch_handler);
        unregister_notifier(RESOURCED_NOTIFIER_MEM_CONTROL, lowmem_control_handler);
+       unregister_notifier(RESOURCED_NOTIFIER_LCD_OFF, lowmem_bg_reclaim_handler);
 
        return RESOURCED_ERROR_NONE;
 }