conf: Support oom based event trigger and handler in conf 25/301325/3
authorUnsung Lee <unsung.lee@samsung.com>
Thu, 9 Nov 2023 01:12:03 +0000 (10:12 +0900)
committerUnsung Lee <unsung.lee@samsung.com>
Tue, 21 Nov 2023 03:57:30 +0000 (12:57 +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 bb337a0..696540f 100644 (file)
@@ -106,7 +106,17 @@ Comment: Specify the memory limitation of background apps.
          <action> can be: broadcast, reclaim, kill, ignore
 Example: BackgroundPerAppLimitAction=768MB,kill
 
-1.5 Section: CpuThrottling
+1.5 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.6 Section: CpuThrottling
 ==========================
 Key: CpuSched
 Value: <schedule scheme>
index cc10c53..3e9852c 100644 (file)
@@ -16,6 +16,11 @@ ServicePerAppLimitAction=128MB,kill
 [MemoryBackgroundLru]
 BackgroundLruLimit=  80%
 
+[MemoryLimitTrigger]
+MemoryLimitTrigger=oom
+#MemoryLimitTrigger=threshold
+#MemoryLimitTrigger=others
+
 [CpuThrottling]
 #CpuSched=idle
 #CpuNice=19
index e15567c..6145b8b 100644 (file)
@@ -156,6 +156,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 % */
@@ -174,6 +181,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 30b39e8..8bdf9e0 100644 (file)
@@ -207,6 +207,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)
 {
@@ -716,6 +731,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 72b09f7..e9907c5 100644 (file)
@@ -46,6 +46,7 @@ extern "C" {
 #define MEMORY_APP_STATUS_LIMIT_SECTION     "MemoryAppStatusLimit"
 #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 */
@@ -85,6 +86,7 @@ extern "C" {
 #define WIDGET_PER_APP_LIMIT_ACTION_NAME_CONF        "WidgetPerAppLimitAction"
 #define GUI_PER_APP_LIMIT_ACTION_NAME_CONF           "GUIPerAppLimitAction"
 #define BACKGROUND_PER_APP_LIMIT_ACTION_NAME_CONF    "BackgroundPerAppLimitAction"
+#define MEMORY_LIMIT_TRIGGER_NAME_CONF               "MemoryLimitTrigger"
 
 /* CPU specific configuration name */
 #define CPU_SCHED_NAME_CONF                          "CpuSched"
@@ -129,6 +131,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"