conf: Support oom based event trigger and handler in conf 91/303591/1
authorUnsung Lee <unsung.lee@samsung.com>
Thu, 9 Nov 2023 01:12:03 +0000 (10:12 +0900)
committerUnsung Lee <unsung.lee@samsung.com>
Tue, 2 Jan 2024 08:44:32 +0000 (17:44 +0900)
Add 'MemoryLimitTrigger' conf to support oom based event trigger and handler.
If conf value is oom then, memory limit is handled by kernel oom. On the other hand,
reosurced handles memory limit directly with threshold value in the conf.

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

index 3f4ad12..535951f 100644 (file)
@@ -120,7 +120,17 @@ Comment: Specify whether LMK working set size post governor is turned on or not.
          If (yes|1|ok|on), rearrange LMK victim list according to the post governor.
          If (no|0|off), skip the corresponding post governor.
 
-1.6 Section: CpuThrottling
+1.6 Section: MemoryLimitTrigger
+===============================
+Key: MemoryLimitTrigger
+Value: oom or threshold or others
+Comment: Specify the type of memory limit trigger type.
+         oom: If memory usage reaches limit, then cgroup oom will handle the situation.
+         threshold: If memory usage reaches limit, then resourced will kill the target without page reclaim.
+         others: If 'MemLimit(Action)' is turned on, just set memory limit.
+Example: MemoryLimitTrigger=oom
+
+1.7 Section: CpuThrottling
 ==========================
 Key: CpuSched
 Value: <schedule scheme>
index 285e0fd..96a603c 100644 (file)
@@ -20,6 +20,11 @@ BackgroundLruLimit=  80%
 ForegroundAppListPostGovernor=no
 WorkingSetSizePostGovernor=no
 
+[MemoryLimitTrigger]
+MemoryLimitTrigger=oom
+#MemoryLimitTrigger=threshold
+#MemoryLimitTrigger=others
+
 [CpuThrottling]
 #CpuSched=idle
 #CpuNice=19
index d300af9..843921c 100644 (file)
@@ -149,6 +149,13 @@ enum cgroup_type {
        MEMCG_END,
 };
 
+enum memcg_limit_trigger {
+       MEMCG_TRIGGER_NONE,
+       MEMCG_TRIGGER_OOM,
+       MEMCG_TRIGGER_THRESHOLD,
+       MEMCG_TRIGGER_MAX,
+};
+
 struct mem_threshold {
        bool percent;
        int threshold;                  /* MB or % */
@@ -167,6 +174,7 @@ struct memcg_conf {
        struct mem_action background;
        float cgroup_limit[MEMCG_END];  /* % */
        bool oom_popup;
+       enum memcg_limit_trigger limit_trigger;
 };
 
 struct memcg_info {
index 98f535d..805c886 100644 (file)
@@ -208,6 +208,21 @@ static cpu_boosting_level_e config_parse_boosting_level(const char *value)
                return CPU_BOOSTING_LEVEL_NONE;
 }
 
+static enum memcg_limit_trigger parse_limit_trigger_type(const char *value)
+{
+
+       if (!strncmp(value, MEMORY_LIMIT_TRIGGER_OOM_VALUE_CONF,
+                               strlen(MEMORY_LIMIT_TRIGGER_OOM_VALUE_CONF) + 1)) {
+               return MEMCG_TRIGGER_OOM;
+       }
+       else if (!strncmp(value, MEMORY_LIMIT_TRIGGER_THRESHOLD_VALUE_CONF,
+                               strlen(MEMORY_LIMIT_TRIGGER_THRESHOLD_VALUE_CONF) + 1)) {
+               return MEMCG_TRIGGER_THRESHOLD;
+       }
+
+       return MEMCG_TRIGGER_NONE;
+}
+
 /* Create a single cpu_info struct representation */
 static int cpu_sched_new_cpu_info(struct cpuset_info *set, int cpu_id)
 {
@@ -845,6 +860,17 @@ static int limiter_config(struct parse_result *result, void *user_data)
 
                return error;
        }
+       else if (!strncmp(result->section, MEMORY_LIMIT_TRIGGER_SECTION,
+                               strlen(MEMORY_LIMIT_TRIGGER_SECTION ) + 1)) {
+               if (!strncmp(result->name, MEMORY_LIMIT_TRIGGER_NAME_CONF,
+                               strlen(MEMORY_LIMIT_TRIGGER_NAME_CONF ) + 1)) {
+                       memcg_conf->limit_trigger = parse_limit_trigger_type(result->value);
+               }
+               else {
+                       _E("[CONFIG] Unknown configuration name (%s) and value (%s) on section (%s)",
+                                       result->name, result->value, result->section);
+               }
+       }
        else if (!strncmp(result->section, CPU_THROTTLING_SECTION,
                                strlen(CPU_THROTTLING_SECTION)+1)) {
                if (!cpu_throttling_conf->enable)
index c0fdef6..4e5e703 100644 (file)
@@ -51,6 +51,7 @@ extern "C" {
 #define MEMORY_LMK_GOVERNOR_SECTION         "MemoryLMKGovernor"
 #define MEMORY_BACKGROUND_LRU_SECTION       "MemoryBackgroundLru"
 #define CPU_THROTTLING_SECTION              "CpuThrottling"
+#define MEMORY_LIMIT_TRIGGER_SECTION        "MemoryLimitTrigger"
 #define OLD_VIP_GROUP_SECTION               "VIP_GROUP"
 
 /* optimizer.conf */
@@ -97,6 +98,7 @@ extern "C" {
 #define BACKGROUND_PER_APP_LIMIT_ACTION_NAME_CONF    "BackgroundPerAppLimitAction"
 #define FOREGROUND_APP_LIST_POST_GOVERNOR_NAME_CONF  "ForegroundAppListPostGovernor"
 #define WORKING_SET_SIZE_POST_GOVERNOR_NAME_CONF     "WorkingSetSizePostGovernor"
+#define MEMORY_LIMIT_TRIGGER_NAME_CONF               "MemoryLimitTrigger"
 
 /* CPU specific configuration name */
 #define CPU_SCHED_NAME_CONF                          "CpuSched"
@@ -142,6 +144,10 @@ extern "C" {
 #define ACTION_REBOOT_VALUE_CONF                     "reboot"
 #define ACTION_IGNORE_VALUE_CONF                     "ignore"
 
+/* Memory specific configuration name */
+#define MEMORY_LIMIT_TRIGGER_OOM_VALUE_CONF          "oom"
+#define MEMORY_LIMIT_TRIGGER_THRESHOLD_VALUE_CONF    "threshold"
+
 /* CPU specific configuration name */
 #define RT_RUNTIME_SHARE_VALUE_CONF                  "rt_runtime_share"
 #define NO_RT_RUNTIME_SHARE_VALUE_CONF               "no_rt_runtime_share"