lowmem-limit: Make private memcg for each app 81/298381/2
authorUnsung Lee <unsung.lee@samsung.com>
Tue, 5 Sep 2023 07:45:00 +0000 (16:45 +0900)
committerUnsung Lee <unsung.lee@samsung.com>
Wed, 6 Sep 2023 08:56:14 +0000 (17:56 +0900)
Private memory cgroup for each app is essential to monitor app information
such as working set size. This is because calculation ofworking set size
is based on memory stat in memcg.

Change-Id: Ic2d840bad0aa54eb9293ced1333c14de81917c13
Signed-off-by: Unsung Lee <unsung.lee@samsung.com>
src/resource-limiter/memory/lowmem-limit.c

index 78b944d..1c722d9 100644 (file)
@@ -49,6 +49,7 @@
 #include "fd-handler.h"
 #include "dbus-handler.h"
 #include "safe-kill.h"
+#include "memory-common.h"
 
 #define MEM_CONF_FILE                   RD_CONFIG_FILE(limiter)
 #define MEMLIMIT_CONFIG_SECTION        "MemLimit"
@@ -519,7 +520,9 @@ static int lowmem_limit_service(void *data)
 
        if (mem_service_limit_bytes && mem_service_action != PROC_ACTION_IGNORE) {
                lowmem_limit_set_app(mem_service_limit_bytes, ps->pai, mem_service_action);
-       }
+       } else
+               lowmem_limit_set_app(lowmem_get_totalram(), ps->pai, mem_service_action);
+
        return RESOURCED_ERROR_NONE;
 }
 
@@ -538,13 +541,18 @@ static int lowmem_limit_appwidget(void *data)
        if (mem_guiapp_limit_bytes && mem_guiapp_action != PROC_ACTION_IGNORE &&
            ps->pai->type == PROC_TYPE_GUI) {
                lowmem_limit_set_app(mem_guiapp_limit_bytes, ps->pai, mem_guiapp_action);
+               return RESOURCED_ERROR_NONE;
        }
 
        if (mem_widget_limit_bytes && mem_widget_action != PROC_ACTION_IGNORE &&
            ps->pai->type == PROC_TYPE_WIDGET) {
                lowmem_limit_set_app(mem_widget_limit_bytes, ps->pai, mem_widget_action);
+               return RESOURCED_ERROR_NONE;
        }
 
+       if (lmk_governor_post_is_enabled_of_wss())
+               lowmem_limit_set_app(lowmem_get_totalram(), ps->pai, PROC_ACTION_KILL);
+
        return RESOURCED_ERROR_NONE;
 }
 
@@ -623,9 +631,15 @@ void lowmem_limit_init(void)
 
        if (mem_service_limit_bytes && mem_service_action != PROC_ACTION_IGNORE)
                register_notifier(RESOURCED_NOTIFIER_SERVICE_LAUNCH, lowmem_limit_service);
+       else if (lmk_governor_post_is_enabled_of_wss())
+               register_notifier(RESOURCED_NOTIFIER_SERVICE_LAUNCH, lowmem_limit_service);
+
        if ((mem_guiapp_limit_bytes && mem_guiapp_action != PROC_ACTION_IGNORE) ||
            (mem_widget_limit_bytes && mem_widget_action != PROC_ACTION_IGNORE))
                register_notifier(RESOURCED_NOTIFIER_APP_LAUNCH, lowmem_limit_appwidget);
+       else if (lmk_governor_post_is_enabled_of_wss())
+               register_notifier(RESOURCED_NOTIFIER_APP_LAUNCH, lowmem_limit_appwidget);
+
        if (mem_bgapp_limit_bytes && mem_bgapp_action != PROC_ACTION_IGNORE) {
                if (!(mem_guiapp_limit_bytes && mem_guiapp_action != PROC_ACTION_IGNORE) ||
                    !(mem_widget_limit_bytes && mem_widget_action != PROC_ACTION_IGNORE)) {