conf: Add LmkThresholdLeave to set stop condition of LMK 98/303598/1
authorUnsung Lee <unsung.lee@samsung.com>
Fri, 17 Nov 2023 06:28:21 +0000 (15:28 +0900)
committerUnsung Lee <unsung.lee@samsung.com>
Tue, 2 Jan 2024 08:45:35 +0000 (17:45 +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 c11e050..cf12bd2 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 96a603c..b0dfe1d 100644 (file)
@@ -3,6 +3,7 @@ MediumLevel=       25%
 LowLevel=          15%
 CriticalLevel=     10%
 OomLevel=           7%
+LmkThresholdLeave= 14%
 OomPopup=           no
 
 [MemoryAppTypeLimit]
index 51aeb53..e5973a0 100644 (file)
@@ -246,31 +246,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 6a64274..f28afbb 100644 (file)
@@ -175,6 +175,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 {
@@ -206,6 +207,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 bd93f23..a4fe1df 100644 (file)
@@ -794,6 +794,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 6ce08e9..1a82e5b 100644 (file)
@@ -100,6 +100,7 @@ extern "C" {
 #define WORKING_SET_SIZE_POST_GOVERNOR_NAME_CONF     "WorkingSetSizePostGovernor"
 #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 9d5e62a..1ef02d4 100644 (file)
@@ -1600,8 +1600,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;
                        }
@@ -1611,14 +1609,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);