conf: Add LmkThresholdLeave to set stop condition of LMK
authorUnsung Lee <unsung.lee@samsung.com>
Fri, 17 Nov 2023 06:28:21 +0000 (15:28 +0900)
committerChanwoo Choi <cw00.choi@samsung.com>
Tue, 21 Nov 2023 10:40:41 +0000 (19:40 +0900)
Add LmkThresholdLeave to set stop condition of LMK.
It is restoration of 'ThresholdLeave' in tizen 6.0.

Change-Id: I0fb27492d8aae4ae0807fd65e98560c025e6c057
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/conf/config-parser.c
src/common/conf/config-parser.h
src/resource-limiter/memory/lowmem.c

index accbc39..30d64f7 100644 (file)
@@ -74,6 +74,13 @@ Value: <threshold>[GMK]B
 Comment: Specify the threshold or ratio for memory level oom(out of memory).
 Example: OomLevel=160MB
 
+Key: LmkThresholdLeave
+Value: <threshold>[GMK]B
+        or
+       <ratio>%
+Comment: Specify the threshold or ratio for LMK stop.
+Example: LmkThresholdLeave=160MB
+
 1.3 Section: MemoryAppTypeLimit
 ===============================
 Key: ServicePerAppLimitAction
index 3e9852c..e3b2502 100644 (file)
@@ -3,6 +3,7 @@ MediumLevel=       25%
 LowLevel=          15%
 CriticalLevel=     10%
 OomLevel=           7%
+LmkThresholdLeave= 14%
 OomPopup=           no
 
 [MemoryAppTypeLimit]
index 7a15502..f96da14 100644 (file)
@@ -259,31 +259,43 @@ int set_mem_action_conf(struct mem_action *mem_action, const char *value)
        return RESOURCED_ERROR_NONE;
 }
 
-int set_memcg_conf_threshold(bool percent, char size, int lvl, const char *value)
+static int get_threshold_size(bool percent, char size, const char *value)
 {
        if (!percent) {
-               if (size == 'G') {
-                       memcg_conf->threshold[lvl].threshold =
-                               GBYTE_TO_MBYTE(atoi(value));
-               }
+               if (size == 'G')
+                       return GBYTE_TO_MBYTE(atoi(value));
                else if (size == 'M') {
-                       memcg_conf->threshold[lvl].threshold =
-                               atoi(value);
+                       return atoi(value);
                }
                else if (size == 'K') {
-                       memcg_conf->threshold[lvl].threshold =
-                               KBYTE_TO_MBYTE(atoi(value));
+                       return KBYTE_TO_MBYTE(atoi(value));
                }
                else {
                        _E("Memory size unit should be GB or MB or KB");
-                       return RESOURCED_ERROR_FAIL;
+                       return -1;
                }
        }
-       else {
-               memcg_conf->threshold[lvl].threshold = atoi(value);
-       }
 
+       return atoi(value);
+}
+
+int set_memcg_conf_threshold(bool percent, char size, int lvl, const char *value)
+{
        memcg_conf->threshold[lvl].percent = percent;
+       memcg_conf->threshold[lvl].threshold = get_threshold_size(percent, size, value);
+       if (memcg_conf->threshold[lvl].threshold < 0)
+               return RESOURCED_ERROR_FAIL;
+
+       return RESOURCED_ERROR_NONE;
+}
+
+int memcg_set_conf_threshold_leave(bool percent, char size, const char *value)
+{
+       memcg_conf->threshold_leave.percent = percent;
+       memcg_conf->threshold_leave.threshold = get_threshold_size(percent, size, value);
+       if (memcg_conf->threshold_leave.threshold < 0)
+               return RESOURCED_ERROR_FAIL;
+
        return RESOURCED_ERROR_NONE;
 }
 
index 4b74770..8f6b6b3 100644 (file)
@@ -182,6 +182,7 @@ struct memcg_conf {
        float cgroup_limit[MEMCG_END];  /* % */
        bool oom_popup;
        enum memcg_limit_trigger limit_trigger;
+       struct mem_threshold threshold_leave;
 };
 
 struct memcg_info {
@@ -213,6 +214,7 @@ bool memcg_memsw_is_supported(void);
 void register_totalram_bytes(unsigned long long ram_bytes);
 int set_mem_action_conf(struct mem_action *mem_action, const char *value);
 int set_memcg_conf_threshold(bool percent, char size, int lvl, const char *value);
+int memcg_set_conf_threshold_leave(bool percent, char size, const char *value);
 struct memcg_conf *get_memcg_conf(void);
 void free_memcg_conf(void);
 
index 7273802..929acda 100644 (file)
@@ -685,6 +685,10 @@ static int limiter_config(struct parse_result *result, void *user_data)
                                                strlen(OOM_LEVEL_NAME_CONF) + 1)) {
                                error = set_memcg_conf_threshold(percent, temp, MEM_LEVEL_OOM, result->value);
                        }
+                       else if (!strncmp(result->name, MEMORY_LMK_THRESHOLD_LEAVE_NAME_CONF,
+                                               strlen(MEMORY_LMK_THRESHOLD_LEAVE_NAME_CONF) + 1)) {
+                               error = memcg_set_conf_threshold_leave(percent, temp, result->value);
+                       }
                        else {
                                _E("[CONFIG] Unknown configuration name (%s) and value (%s) on section (%s)",
                                                result->name, result->value, result->section);
index 1a1af00..6f8dcc9 100644 (file)
@@ -88,6 +88,7 @@ extern "C" {
 #define BACKGROUND_PER_APP_LIMIT_ACTION_NAME_CONF    "BackgroundPerAppLimitAction"
 #define MEMORY_LIMIT_TRIGGER_NAME_CONF               "MemoryLimitTrigger"
 #define MEMORY_LMK_KILL_EXCEPTION_NAME_CONF          "LmkKillException"
+#define MEMORY_LMK_THRESHOLD_LEAVE_NAME_CONF         "LmkThresholdLeave"
 
 /* CPU specific configuration name */
 #define CPU_SCHED_NAME_CONF                          "CpuSched"
index 3562198..425dafe 100644 (file)
@@ -1411,8 +1411,6 @@ static void load_configs(void)
                                        calculate_threshold_size(memcg_conf->threshold[lvl].threshold));
 
                        if (lvl == MEM_LEVEL_OOM) {
-                               memcg_set_leave_threshold(MEMCG_ROOT,
-                                               get_memcg_info(MEMCG_ROOT)->threshold_mb[lvl] * 1.5);
                                proactive_threshold_mb = get_memcg_info(MEMCG_ROOT)->threshold_leave_mb;
                                proactive_leave_mb = proactive_threshold_mb * 1.5;
                        }
@@ -1422,14 +1420,22 @@ static void load_configs(void)
                                        memcg_conf->threshold[lvl].threshold);
 
                        if (lvl == MEM_LEVEL_OOM) {
-                               memcg_set_leave_threshold(MEMCG_ROOT,
-                                               get_memcg_info(MEMCG_ROOT)->threshold_mb[lvl] * 1.5);
                                proactive_threshold_mb = get_memcg_info(MEMCG_ROOT)->threshold_leave_mb;
                                proactive_leave_mb = proactive_threshold_mb * 1.5;
                        }
 
                }
        }
+
+       if (memcg_conf->threshold_leave.percent &&
+                       memcg_conf->threshold_leave.threshold > 0) {
+               memcg_set_leave_threshold(MEMCG_ROOT,
+                               calculate_threshold_size(memcg_conf->threshold_leave.threshold));
+       } else if (memcg_conf->threshold_leave.threshold > 0) {
+               memcg_set_leave_threshold(MEMCG_ROOT,
+                               memcg_conf->threshold_leave.threshold);
+       }
+
        oom_popup_enable = memcg_conf->oom_popup;
        set_memcg_limit_trigger(memcg_conf->limit_trigger);