memlimit: Introduce limit for background apps 47/253847/6 accepted/tizen/unified/20210301.130200 submit/tizen/20210225.162154
authorKarol Lewandowski <k.lewandowsk@samsung.com>
Thu, 18 Feb 2021 11:54:04 +0000 (12:54 +0100)
committerKarol Lewandowski <k.lewandowsk@samsung.com>
Wed, 24 Feb 2021 11:47:18 +0000 (12:47 +0100)
Use MemLimitBgApp to set memory limit for any kind of application
(gui, widget).

Change-Id: I9879601ef214ef2e68ede1496084e2f99d27b221

packaging/resourced.spec
src/memory/lowmem-limit.c
src/memory/memory.conf

index 576193d..b60cf5f 100644 (file)
@@ -14,7 +14,7 @@
 
 Name:       resourced
 Summary:    Resource management daemon
-Version:    6.5.1
+Version:    6.5.2
 Release:    1
 Group:      System/Libraries
 License:    Apache-2.0
index 5fc7948..a0f70a6 100644 (file)
@@ -60,6 +60,7 @@
 #define MEMLIMIT_CONFIG_SERVICE MEMLIMIT_CONFIG_LIM_PFX "Service"
 #define MEMLIMIT_CONFIG_GUIAPP  MEMLIMIT_CONFIG_LIM_PFX "GUIApp"
 #define MEMLIMIT_CONFIG_WIDGET  MEMLIMIT_CONFIG_LIM_PFX "Widget"
+#define MEMLIMIT_CONFIG_BGAPP   MEMLIMIT_CONFIG_LIM_PFX "BgApp"
 #define MIN_LIMIT_VALUE                1 /* MB */
 
 enum mem_limit_type {
@@ -79,6 +80,7 @@ static char *registerpath;
 static int mem_service_limit;
 static int mem_guiapp_limit;
 static int mem_widget_limit;
+static int mem_bgapp_limit;
 
 struct memory_limit_event {
        fd_handler_h fdh;
@@ -585,6 +587,8 @@ static int memlimit_config_parse(struct parse_result *result, void *user_data)
                        mem_guiapp_limit = limit;
                else if (!strcmp(result->name, MEMLIMIT_CONFIG_WIDGET))
                        mem_widget_limit = limit;
+               else if (!strcmp(result->name, MEMLIMIT_CONFIG_BGAPP))
+                       mem_bgapp_limit = limit;
        }
 
        return RESOURCED_ERROR_NONE;
@@ -684,6 +688,31 @@ static int lowmem_limit_appwidget(void *data)
        return RESOURCED_ERROR_NONE;
 }
 
+static int lowmem_limit_bgapp(void *data)
+{
+       assert(data);
+
+       struct proc_status *ps = (struct proc_status *)data;
+
+       lowmem_limit_set(ps->pid, mem_bgapp_limit);
+
+       return RESOURCED_ERROR_NONE;
+}
+
+static int lowmem_limit_fgapp(void *data)
+{
+       assert(data);
+
+       struct proc_status *ps = (struct proc_status *)data;
+
+       if ((mem_guiapp_limit && ps->pai->type == PROC_TYPE_GUI) ||
+           (mem_widget_limit && ps->pai->type == PROC_TYPE_WIDGET))
+               return lowmem_limit_appwidget(data);
+
+       _E("Unable to set foreground app limit - app type not supported");
+
+       return RESOURCED_ERROR_NONE;
+}
 void lowmem_limit_init(void)
 {
        /* Load configuration */
@@ -697,6 +726,16 @@ void lowmem_limit_init(void)
                register_notifier(RESOURCED_NOTIFIER_SERVICE_LAUNCH, lowmem_limit_service);
        if (mem_guiapp_limit || mem_widget_limit)
                register_notifier(RESOURCED_NOTIFIER_APP_LAUNCH, lowmem_limit_appwidget);
+       if (mem_bgapp_limit) {
+               if (!mem_guiapp_limit || !mem_widget_limit) {
+                       _W("Background app limit requires that both GUIApp and Widget limits to be set to work properly. Ignoring.");
+               } else {
+                       register_notifier(RESOURCED_NOTIFIER_APP_BACKGRD, lowmem_limit_bgapp);
+                       register_notifier(RESOURCED_NOTIFIER_APP_FOREGRD, lowmem_limit_fgapp);
+                       register_notifier(RESOURCED_NOTIFIER_WIDGET_FOREGRD, lowmem_limit_fgapp);
+                       register_notifier(RESOURCED_NOTIFIER_WIDGET_BACKGRD, lowmem_limit_bgapp);
+               }
+       }
 }
 
 void lowmem_limit_exit(void)
@@ -710,4 +749,8 @@ void lowmem_limit_exit(void)
 
        unregister_notifier(RESOURCED_NOTIFIER_SERVICE_LAUNCH, lowmem_limit_service);
        unregister_notifier(RESOURCED_NOTIFIER_APP_LAUNCH, lowmem_limit_appwidget);
+       unregister_notifier(RESOURCED_NOTIFIER_APP_BACKGRD, lowmem_limit_bgapp);
+       unregister_notifier(RESOURCED_NOTIFIER_APP_FOREGRD, lowmem_limit_fgapp);
+       unregister_notifier(RESOURCED_NOTIFIER_WIDGET_FOREGRD, lowmem_limit_fgapp);
+       unregister_notifier(RESOURCED_NOTIFIER_WIDGET_BACKGRD, lowmem_limit_bgapp);
 }
index b6cc5cd..2eb59e1 100644 (file)
@@ -210,6 +210,11 @@ MemLimitService=128                # MB
 # MemLimitWidget=160            # MB
 # MemLimitGUIApp=1024           # MB
 
+# Following configuration option sets memory limit for background GUI
+# and Widget applications.  It's valid to set this option only if
+# both MemLimitWidget and MemLimitGUIApp are set.
+# MemLimitBgApp=768             # MB
+
 [Logging]
 Enable=1
 # memps logpath