conf: Remove action from all LimitAction 02/303602/1
authorUnsung Lee <unsung.lee@samsung.com>
Mon, 27 Nov 2023 04:47:28 +0000 (13:47 +0900)
committerUnsung Lee <unsung.lee@samsung.com>
Tue, 2 Jan 2024 08:46:03 +0000 (17:46 +0900)
Remove action from all LimitAction confs
(i.e., ServicePerAppLimitAction, WidgetPerAppLimitAction, GUIPerAppLimitAction,
BackgroundPerAppLimitAction and MemLimitAction).
Action will be decided only by MemoryLimitTrigger conf.
It also change type of memory in mem_action from unsigned long long to uint64_t.

Change-Id: Ieae8ed65d8d55b6a6e70e21fc1024bfaf09664f3
Signed-off-by: Unsung Lee <unsung.lee@samsung.com>
conf/README
conf/limiter.conf
src/common/cgroup/memory-cgroup.c
src/common/cgroup/memory-cgroup.h
src/common/util.h

index cef1836..9575f7d 100644 (file)
@@ -91,32 +91,36 @@ Example: LmkMaxVictimPerOom=10
 Key: ServicePerAppLimitAction
 Value: <limit>[GMK]B,<action>
 Comment: Specify the memory limitation of services.
-         <action> specifies an action to be performed when the limit is crossed.
-         <action> can be: broadcast, reclaim, kill, ignore
-Example: ServicePerAppLimitAction=128MB,kill
+         If <action> is specified, <action> overwrites the global action (reference section 1.5).
+        If <action> is not specified, action is decided by global action (i.e., MemoryLimitTrigger).
+        If <limit> size is smaller than app size during app loading time, the memory limit is not applied.
+Example: ServicePerAppLimitAction=128MB
 
 Key: WidgetPerAppLimitAction
 Value: <limit>[GMK]B,<action>
 Comment: Specify the memory limitation of widgets.
-         <action> specifies an action to be performed when the limit is crossed.
-         <action> can be: broadcast, reclaim, kill, ignore
-Example: WidgetPerAppLimitAction=160MB,kill
+         If <action> is specified, <action> overwrites the global action (reference section 1.5).
+        If <action> is not specified, action is decided by global action (i.e., MemoryLimitTrigger).
+        If <limit> size is smaller than app size during app loading time, the memory limit is not applied.
+Example: WidgetPerAppLimitAction=160MB
 
 Key: GUIPerAppLimitAction
 Value: <limit>[GMK]B,<action>
 Comment: Specify the memory limitation of GUIs.
-         <action> specifies an action to be performed when the limit is crossed.
-         <action> can be: broadcast, reclaim, kill, ignore
-Example: GUIPerAppLimitAction=160MB,kill
+         If <action> is specified, <action> overwrites the global action (reference section 1.5).
+        If <action> is not specified, action is decided by global action (i.e., MemoryLimitTrigger).
+        If <limit> size is smaller than app size during app loading time, the memory limit is not applied.
+Example: GUIPerAppLimitAction=160MB
 
 1.4 Section: MemoryAppStatusLimit
 =================================
 Key: BackgroundPerAppLimitAction
 Value: <limit>[GMK]B,<action>
 Comment: Specify the memory limitation of background apps.
-         <action> specifies an action to be performed when the limit is crossed.
-         <action> can be: broadcast, reclaim, kill, ignore
-Example: BackgroundPerAppLimitAction=768MB,kill
+         If <action> is specified, <action> overwrites the global action (reference section 1.5).
+        If <action> is not specified, action is decided by global action (i.e., MemoryLimitTrigger).
+        If <limit> size is smaller than app size during app loading time, the memory limit is not applied.
+Example: BackgroundPerAppLimitAction=768MB
 
 1.5 Section: MemoryLMKGovernor
 =============================
@@ -542,9 +546,10 @@ Example: App=org.tizen.<app>
 Key: MemLimitAction
 Value: <limit>[GMK]B,<action>
 Comment: Specify the memory limitation of this app/service/process.
-         <action> specifies an action to be performed when the limit is crossed.
-         <action> can be: broadcast, reclaim, kill, ignore
-Example: MemLimitAction=4096KB,kill
+         If <action> is specified, <action> overwrites the global action (reference section 1.5).
+        If <action> is not specified, action is decided by global action (i.e., MemoryLimitTrigger).
+        If <limit> size is smaller than app size during app loading time, the memory limit is not applied.
+Example: MemLimitAction=4096KB
 
 Key: MemoryBackgroundLru
 Value: (yes|1|ok|on|no|0|off)
index 73aaef3..f64d6d6 100644 (file)
@@ -8,12 +8,12 @@ OomLevel=           7%
 OomPopup=           no
 
 [MemoryAppTypeLimit]
-ServicePerAppLimitAction=128MB,kill
-#WidgetPerAppLimitAction=160MB,kill
-#GUIPerAppLimitAction=1024MB,kill
+ServicePerAppLimitAction=128MB
+#WidgetPerAppLimitAction=160MB
+#GUIPerAppLimitAction=1024MB
 
 [MemoryAppStatusLimit]
-#BackgroundPerAppLimitAction=768MB,kill
+#BackgroundPerAppLimitAction=768MB
 
 [MemoryBackgroundLru]
 BackgroundLruLimit=  80%
index e5973a0..5d2e6e1 100644 (file)
@@ -187,65 +187,85 @@ void register_totalram_bytes(unsigned long long ram_bytes)
        totalram_bytes = ram_bytes;
 }
 
-int set_mem_action_conf(struct mem_action *mem_action, const char *value)
+static int get_memory_bytes(const char *value, uint64_t *memory_bytes)
 {
-       char *ptr = strchr(value, ',');
-       char *second_value = ptr + 1;
-       char temp;
-
+       char size[3];
+       char *ptr = strchr(value, 'B');
        if (ptr == NULL) {
-               _E("Cannot find ',' in the string (%s)", value);
+               _E("[CONFIG] Cannot find 'B' in the string (%s)", value);
                return RESOURCED_ERROR_FAIL;
        }
 
-       if (value > (ptr - 2)) {
-               _E("Size of string should be larger than 2");
+       if (value > (ptr - 1)) {
+               _E("[CONFIG] Size of string should be larger than 1");
                return RESOURCED_ERROR_FAIL;
        }
 
-       if (*(ptr - 1) == 'B') {
-               temp = *(ptr - 2);
-               *(ptr - 2) = '\0';
+       size[0] = *(ptr - 1);
+       size[1] = *ptr;
+       size[2] = '\0';
+       *(ptr - 1) = '\0';
 
-               if (temp == 'G') {
-                       mem_action->memory_bytes = GBYTE_TO_BYTE(atoi(value));
-               }
-               else if (temp == 'M') {
-                       mem_action->memory_bytes = MBYTE_TO_BYTE(atoi(value));
-               }
-               else if (temp == 'K') {
-                       mem_action->memory_bytes = KBYTE_TO_BYTE(atoi(value));
-               }
-               else {
-                       _E("Memory size unit should be GB or MB or KB");
-                       return RESOURCED_ERROR_FAIL;
-               }
-
-               if (!strncmp(second_value, ACTION_BROADCAST_VALUE_CONF,
-                                       strlen(ACTION_BROADCAST_VALUE_CONF)+1))
-                       mem_action->action = PROC_ACTION_BROADCAST;
-               else if (!strncmp(second_value, ACTION_RECLAIM_VALUE_CONF,
-                                       strlen(ACTION_RECLAIM_VALUE_CONF)+1))
-                       mem_action->action = PROC_ACTION_RECLAIM;
-               else if (!strncmp(second_value, ACTION_KILL_VALUE_CONF,
-                                       strlen(ACTION_KILL_VALUE_CONF)+1))
-                       mem_action->action = PROC_ACTION_KILL;
-               else if (!strncmp(second_value, ACTION_IGNORE_VALUE_CONF,
-                                       strlen(ACTION_IGNORE_VALUE_CONF)+1))
-                       mem_action->action = PROC_ACTION_IGNORE;
-               else {
-                       _E("action (%s) is not supported", second_value);
-                       return RESOURCED_ERROR_FAIL;
-               }
+       if (!strncmp(size, "GB", 3))
+               *memory_bytes = GBYTE_TO_BYTE(atoi(value));
+       else if (!strncmp(size, "MB", 3))
+               *memory_bytes = MBYTE_TO_BYTE(atoi(value));
+       else if (!strncmp(size, "KB", 3))
+               *memory_bytes = KBYTE_TO_BYTE(atoi(value));
+       else {
+               _E("Memory size unit should be GB or MB or KB");
+               return RESOURCED_ERROR_FAIL;
        }
+
+       return RESOURCED_ERROR_NONE;
+}
+
+static int get_memory_action(const char *value, int *action)
+{
+       if (!strncmp(value, ACTION_BROADCAST_VALUE_CONF,
+                               strlen(ACTION_BROADCAST_VALUE_CONF) + 1))
+               *action = PROC_ACTION_BROADCAST;
+       else if (!strncmp(value, ACTION_RECLAIM_VALUE_CONF,
+                               strlen(ACTION_RECLAIM_VALUE_CONF) + 1))
+               *action = PROC_ACTION_RECLAIM;
+       else if (!strncmp(value, ACTION_KILL_VALUE_CONF,
+                               strlen(ACTION_KILL_VALUE_CONF) + 1))
+               *action = PROC_ACTION_KILL;
+       else if (!strncmp(value, ACTION_IGNORE_VALUE_CONF,
+                               strlen(ACTION_IGNORE_VALUE_CONF) + 1))
+               *action = PROC_ACTION_IGNORE;
        else {
-               _E("Memory size unit should be XB");
+               _E("action (%s) is not supported", value);
                return RESOURCED_ERROR_FAIL;
        }
 
        return RESOURCED_ERROR_NONE;
 }
 
+int set_mem_action_conf(struct mem_action *mem_action, const char *value)
+{
+       char *ptr = strchr(value, ',');
+       const char *action_ptr;
+       int result;
+
+       result = get_memory_bytes(value, &mem_action->memory_bytes);
+       if (result < 0)
+               return result;
+
+       /* Memory Limit without action value */
+       if (ptr == NULL) {
+               mem_action->action = PROC_ACTION_KILL;
+               return RESOURCED_ERROR_NONE;
+       }
+
+       action_ptr = ptr + 1;
+       result = get_memory_action(action_ptr, &mem_action->action);
+       if (result < 0)
+               return result;
+
+       return RESOURCED_ERROR_NONE;
+}
+
 static int get_threshold_size(bool percent, char size, const char *value)
 {
        if (!percent) {
index 52a0791..03e4b99 100644 (file)
@@ -162,7 +162,7 @@ struct mem_threshold {
 };
 
 struct mem_action {
-       unsigned long long memory_bytes;        /* Byte */
+       uint64_t memory_bytes;
        int action;
 };
 
index 8a66ee4..6f3ee45 100644 (file)
@@ -95,13 +95,13 @@ static inline void closedirp(DIR **d)
 #define BYTE_TO_MBYTE(b) ((b) >> 20)
 #define BYTE_TO_PAGE(b) ((b) >> 12)
 
-#define KBYTE_TO_BYTE(k) ((unsigned long long)(k) << 10)
+#define KBYTE_TO_BYTE(k) ((uint64_t)(k) << 10)
 #define KBYTE_TO_MBYTE(k) ((k) >> 10)
 
-#define MBYTE_TO_BYTE(m) ((unsigned long long)(m) << 20)
+#define MBYTE_TO_BYTE(m) ((uint64_t)(m) << 20)
 #define MBYTE_TO_KBYTE(m) ((m) << 10)
 
-#define GBYTE_TO_BYTE(g) ((unsigned long long)(g) << 30)
+#define GBYTE_TO_BYTE(g) ((uint64_t)(g) << 30)
 #define GBYTE_TO_MBYTE(g) ((g) << 10)
 
 #define streq(a, b) (strncmp((a), (b), strlen(b)+1) == 0)