Modify bugs on configuration 67/273667/7
authorUnsung Lee <unsung.lee@samsung.com>
Tue, 12 Apr 2022 01:35:19 +0000 (10:35 +0900)
committerUnsung Lee <unsung.lee@samsung.com>
Tue, 12 Apr 2022 08:00:18 +0000 (17:00 +0900)
Modify bugs on memory and cpu cgrups of per app or service
Update each configurations

Change-Id: Ide9810e1250b85d375b1881d9b087f0712d5ae45
Signed-off-by: Unsung Lee <unsung.lee@samsung.com>
conf/README
conf/limiter-profile-iot-headless.conf
conf/limiter-profile-tv.conf
conf/limiter.conf
conf/optimizer.conf
conf/optimizer.conf.d/0-optimizer.conf
src/common/cgroup/memory-cgroup.c
src/resource-limiter/memory/lowmem-handler.h
src/resource-limiter/memory/lowmem-limit.c
src/resource-limiter/memory/vmpressure-lowmem-handler.c
src/resource-optimizer/cpu/cpu-sched.c

index 9ab1b08..731aed5 100644 (file)
@@ -1,3 +1,4 @@
+Old Version
 Resourced Configurations
 ========================
 
index 7fe7de7..aa83b44 100644 (file)
@@ -1,20 +1,20 @@
 [MemoryGroupLimit]
 VipGroupLimit=     100%
 HighGroupLimit=    100%
-MediumGroupLimit=  90%
-LowestGroupLimit=  70%
+MediumGroupLimit=  100%
+LowestGroupLimit=  100%
 
 [MemoryLevelThreshold]
-MediumLevel=       400MB
-LowLevel=          300MB
-CriticalLevel=     200MB
-OomLevel=          160MB
-OomPopup=          no
+#MediumLevel=     400MB
+#LowLevel=        300MB
+#CriticalLevel=   200MB
+#OomLevel=        160MB
+OomPopup=            no
 
 [MemoryAppTypeLimit]
 ServicePerAppLimitAction=128MB,kill
-WidgetPerAppLimitAction=160MB,kill
-GUIPerAppLimitAction=1024MB,kill
+#WidgetPerAppLimitAction=160MB,kill
+#GUIPerAppLimitAction=1024MB,kill
 
 [MemoryAppStatusLimit]
-BackgroundPerAppLimitAction=768MB,kill
+#BackgroundPerAppLimitAction=768MB,kill
index 7fe7de7..ebefc4d 100644 (file)
@@ -1,20 +1,17 @@
 [MemoryGroupLimit]
 VipGroupLimit=     100%
 HighGroupLimit=    100%
-MediumGroupLimit=  90%
-LowestGroupLimit=  70%
+MediumGroupLimit=  100%
+LowestGroupLimit=  100%
 
 [MemoryLevelThreshold]
-MediumLevel=       400MB
-LowLevel=          300MB
-CriticalLevel=     200MB
-OomLevel=          160MB
-OomPopup=          no
+#MediumLevel=     400MB
+#LowLevel=        300MB
+#CriticalLevel=   200MB
+#OomLevel=        160MB
+#OomPopup=           no
 
 [MemoryAppTypeLimit]
-ServicePerAppLimitAction=128MB,kill
-WidgetPerAppLimitAction=160MB,kill
-GUIPerAppLimitAction=1024MB,kill
+ServicePerAppLimitAction=128MB,ignore
 
 [MemoryAppStatusLimit]
-BackgroundPerAppLimitAction=768MB,kill
index da00d89..b79044e 100644 (file)
@@ -1,20 +1,20 @@
 [MemoryGroupLimit]
 VipGroupLimit=     100%
 HighGroupLimit=    100%
-MediumGroupLimit=  90%
-LowestGroupLimit=  70%
+MediumGroupLimit=  100%
+LowestGroupLimit=  100%
 
 [MemoryLevelThreshold]
-MediumLevel=       20%
-LowLevel=          15%
-CriticalLevel=     10%
-OomLevel=          7%
-OomPopup=          no
+#MediumLevel=       20%
+#LowLevel=          15%
+#CriticalLevel=     10%
+#OomLevel=           7%
+OomPopup=            no
 
 [MemoryAppTypeLimit]
 ServicePerAppLimitAction=128MB,kill
-WidgetPerAppLimitAction=160MB,kill
-GUIPerAppLimitAction=1024MB,kill
+#WidgetPerAppLimitAction=160MB,kill
+#GUIPerAppLimitAction=1024MB,kill
 
 [MemoryAppStatusLimit]
-BackgroundPerAppLimitAction=768MB,kill
+#BackgroundPerAppLimitAction=768MB,kill
index 192024b..0af613e 100644 (file)
@@ -1,11 +1,11 @@
 [MemorySwap]
 SwapEnable=1
 ReclaimAtBoot=yes
-SwapType=zram+zswap
+SwapType=zram
 VipGroupSwappiness=0
-HighGroupSwappiness=5
-MediumGroupSwappiness=10
-LowestGroupSwappiness=20
+HighGroupSwappiness=0
+MediumGroupSwappiness=0
+LowestGroupSwappiness=0
 
 [MemoryZram]
 CompAlgorithm=zstd
@@ -17,7 +17,7 @@ PoolType=z3fold
 
 [MemoryDedup]
 DedupEnable=1
-DedupAtBoot=no
+DedupAtBoot=yes
 ScanOnLowmem=true
 
 [MemoryKsm]
@@ -25,16 +25,16 @@ KsmMode=oneshot
 #KsmMode=periodic
 
 PagesToScan=100
-PagesToScanWithBoost=1500
+PagesToScanWithBoost=1000
 
 [MemoryCompaction]
 CompactionEnable=1
 FragLevel=800
 
 [CpuSched]
-CpuSchedFeature=no_rt_runtime_share
-CpuRTRunTime=915ms
-CpuRTPeriod=1000ms
+#CpuSchedFeature=no_rt_runtime_share
+#CpuRTRunTime=915ms
+#CpuRTPeriod=1000ms
 
 [CpuAffinity]
-ForegroundApps=1,2,4-6
+#ForegroundApps=1,2,4-6
index 87e60a9..5798ba2 100644 (file)
@@ -2,11 +2,15 @@
 Service=dbus.service
 CpuSched=fifo
 CpuRTPriority=5
+CpuRTRunTime=100ms
+CpuRTPeriod=300ms
 
 [PerProcess]
 Service=alarm-server.service
 CpuSched=rr
 CpuRTPriority=10
+CpuRTRunTime=100ms
+CpuRTPeriod=300ms
 
 [PerProcess]
 Service=ac.service
index 1a44fd4..8d71f66 100644 (file)
@@ -113,6 +113,9 @@ int set_mem_action_conf(struct mem_action *mem_action, const char *value)
                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;
@@ -214,17 +217,19 @@ int check_oom_and_set_limit(const char *dir, unsigned int limit)
                }
        }
 
-       /* If panic_on_oom is true (> 1), oom should be disabled  */
+       /* If panic_on_oom is true (> 1), turn of panic_on_oom */
        if (poo != 0) {
-               _I("[DEBUG] %s's value is %d. That is, kernel panic will be inevitable on %s, when oom happens", "proc/sys/vm/panic_on_oom", poo, dir);
-               error = cgroup_write_node_uint32(dir, MEMCG_OOM_CONTROL, 1);
+               _I("[DEBUG] %s's value is %d. That is, kernel panic will be inevitable on %s, when oom happens", "/proc/sys/vm/panic_on_oom", poo, dir);
+               error = fwrite_uint("/proc/sys/vm/panic_on_oom", 0);
                if (!error)
-                       set_limit_in_bytes(dir, limit);
-       }
-       else {
-               set_limit_in_bytes(dir, limit);
+                       fread_uint("/proc/sys/vm/panic_on_oom", &poo);
+               else {
+                       _E("[DEBUG] Failed to update %s", "/proc/sys/vm/panic_on_oom");
+                       return RESOURCED_ERROR_FAIL;
+               }
        }
 
+       set_limit_in_bytes(dir, limit);
        return RESOURCED_ERROR_NONE;
 }
 
index 8d330b1..442ef91 100644 (file)
@@ -65,7 +65,7 @@ struct memory_limit_event {
        unsigned int threshold;         /* byte */
        char *path;
        enum proc_action action;
-       int pid;
+       GArray *pids_array;
 };
 
 /**
index 7f5061a..a752999 100644 (file)
 #define MEMLIMIT_CONFIG_BGAPP   MEMLIMIT_CONFIG_LIM_PFX "BgApp"
 #define MIN_LIMIT_VALUE                MBYTE_TO_BYTE(1) /* Byte */
 
-enum mem_limit_type {
-       /* check only swap usage also */
+/*enum mem_limit_type {
        MEM_LIMIT_NONE,
-       /* register OOM event and control application in kernel side */
        MEM_LIMIT_OOM,
-       /* register threshold event and control application in resourced*/
        MEM_LIMIT_TRHESHOLD,
 };
 
-static enum mem_limit_type mem_limit;
+static enum mem_limit_type mem_limit;*/
 
 
 static GHashTable *memory_limit_hash;
@@ -82,75 +79,10 @@ static unsigned int mem_widget_limit;
 static unsigned int mem_guiapp_limit;
 static unsigned int mem_bgapp_limit;
 
-static int mem_service_action = PROC_ACTION_KILL;
-static int mem_widget_action = PROC_ACTION_KILL;
-static int mem_guiapp_action = PROC_ACTION_KILL;
-static int mem_bgapp_action = PROC_ACTION_KILL;
-
-struct memory_info {
-       pid_t pid;
-       unsigned int size;
-};
-
-struct memory_limit_log {
-       pid_t pid;
-       char *appname;
-       char *cgdir;
-};
-
-static int get_pid_use_max_memory(GArray *pids_array, unsigned int *max_mem)
-{
-       int i, ret;
-       struct memory_info mi = {0, 0};
-
-       if (!pids_array->len)
-               return RESOURCED_ERROR_NO_DATA;
-
-       for (i = 0; i < pids_array->len; i++) {
-               pid_t mpid = 0;
-               unsigned int size;
-
-               mpid = g_array_index(pids_array, pid_t, i);
-               if (!mpid)
-                       continue;
-
-               ret = proc_get_mem_usage(mpid, &size);
-               if (ret != RESOURCED_ERROR_NONE)
-                       continue;
-
-               _D("%d used %d memory", mpid, size);
-
-               if (size > mi.size) {
-                       mi.pid = mpid;
-                       mi.size = size;
-               }
-       }
-       *max_mem = mi.size;
-       _D("%d used max %d memory", mi.pid, mi.size);
-       return mi.pid;
-}
-
-static pid_t get_main_pid(const char *dir, unsigned int *max_mem)
-{
-       GArray *pids_array = NULL;
-       _cleanup_free_ char *path = NULL;
-       int ret;
-       pid_t main_pid;
-
-       ret = asprintf(&path, "%s/", dir);
-       if (ret < 0)
-               return -ENOMEM;
-
-       ret = cgroup_get_pids(path, &pids_array);
-       if (ret < 0 || !pids_array->len) {
-               g_array_free(pids_array, true);
-               return RESOURCED_ERROR_NO_DATA;
-       }
-
-       main_pid = get_pid_use_max_memory(pids_array, max_mem);
-       g_array_free(pids_array, true);
-       return main_pid;
-}
+static int mem_service_action = PROC_ACTION_IGNORE;
+static int mem_widget_action = PROC_ACTION_IGNORE;
+static int mem_guiapp_action = PROC_ACTION_IGNORE;
+static int mem_bgapp_action = PROC_ACTION_IGNORE;
 
 static void memory_limit_hash_destroy(gpointer data)
 {
@@ -216,17 +148,26 @@ static gboolean liveness_check_cb(gpointer data)
                goto timer_out;
        }
 
-       if (mle->pid <= 0) {
-               _E("[DEBUG] pid should be larger than 0");
+       if (mle->pids_array == NULL) {
+               _E("[DEBUG] pids array should not be NULL");
                goto mle_timer_init;
        }
 
-       if (kill(mle->pid, 0) == 0) {
-               safe_kill(mle->pid, SIGKILL);
+       for (int i = 0; i < mle->pids_array->len; i++) {
+               pid_t pid = g_array_index(mle->pids_array, pid_t, i);
+               if (!pid)
+                       continue;
+
+               if (kill(pid, 0) == 0) {
+                       _I("[DEBUG] dir %s's pid (%d) is still avlie, so kill forcely", mle->path, pid);
+                       safe_kill(pid, SIGKILL);
+               }
        }
 
+       g_array_free(mle->pids_array, true);
+
 mle_timer_init:
-       mle->pid = -1;
+       mle->pids_array = NULL;
 timer_out:
        return G_SOURCE_REMOVE;
 }
@@ -234,12 +175,12 @@ timer_out:
 static bool memory_action_cb(int fd, void *data)
 {
        int result;
-       pid_t main_pid;
-       uint32_t usage, max_mem;
+       pid_t pid;
+       GArray *pids_array = NULL;
+       uint32_t usage;
        uint64_t dummy_efd;
        char *cg_dir = (char *)data;
        struct memory_limit_event *mle;
-       _cleanup_free_ struct cgroup_memory_stat *mem_stat = NULL;
 
        mle = g_hash_table_lookup(memory_limit_hash, cg_dir);
        if (!mle) {
@@ -273,40 +214,51 @@ static bool memory_action_cb(int fd, void *data)
                return true;
        }
 
-       result = memcg_get_memory_stat(cg_dir, &mem_stat);
-       if (result < 0) {
-               _E("[DEBUG] Failed to get memory status : %s", cg_dir);
-               goto remove_mle;
-       }
-
        switch (mle->action) {
                case PROC_ACTION_BROADCAST:
-                       main_pid = get_main_pid(cg_dir, &max_mem);
-                       if (main_pid <= 0) {
-                               _D("[DEBUG] there is no victim, removed cgroup : %s", cg_dir);
+                       result = cgroup_get_pids(cg_dir, &pids_array);
+                       if (result < 0 || !pids_array->len) {
+                               g_array_free(pids_array, true);
                                goto remove_mle;
                        }
 
-                       if (lowmem_limit_broadcast(main_pid)) {
-                               _E("[DEBUG] Failed to broadcast of process (%s)", cg_dir);
-                               return false;
+                       for (int i = 0; i < pids_array->len; i++) {
+                               pid = g_array_index(pids_array, pid_t, i);
+                               if (!pid)
+                                       continue;
+
+                               if (lowmem_limit_broadcast(pid)) {
+                                       _E("[DEBUG] Failed to broadcast of process (%s)", cg_dir);
+                                       safe_kill(pid, SIGTERM);
+                               }
                        }
+
+                       g_array_free(pids_array, true);
                        break;
                case PROC_ACTION_RECLAIM:
                        lowmem_trigger_swap(0, cg_dir, false);
                        break;
                case PROC_ACTION_KILL:
-                       main_pid = get_main_pid(cg_dir, &max_mem);
-                       if (main_pid <= 0) {
-                               _D("[DEBUG] there is no victim, removed cgroup : %s", cg_dir);
+                       result = cgroup_get_pids(cg_dir, &pids_array);
+                       if (result < 0 || !pids_array->len) {
+                               g_array_free(pids_array, true);
                                goto remove_mle;
                        }
-                       safe_kill(main_pid, SIGTERM);
 
-                       if (mle->pid == -1) {
-                               mle->pid = main_pid;
+                       for (int i = 0; i < pids_array->len; i++) {
+                               pid = g_array_index(pids_array, pid_t, i);
+                               if (!pid)
+                                       continue;
+
+                               safe_kill(pid, SIGTERM);
+                       }
+
+                       if (mle->pids_array == NULL) {
+                               mle->pids_array = pids_array;
                                g_timeout_add_seconds(2, liveness_check_cb, mle);
                        }
+                       else
+                               g_array_free(pids_array, true);
 
                        break;
                default:
@@ -376,7 +328,7 @@ int lowmem_reassign_limit(const char *dir,
                }
                mle->action = action;
                mle->threshold = limit;
-               mle->pid = -1;
+               mle->pids_array = NULL;
                add_fd_read_handler(fd, memory_action_cb, mle->path, NULL, &fdh);
                mle->fdh = fdh;
                g_hash_table_insert(memory_limit_hash, (gpointer)mle->path,
@@ -425,6 +377,9 @@ void lowmem_limit_set_system_service(pid_t pid, unsigned int limit,
                return;
        }
 
+       if (action == PROC_ACTION_IGNORE)
+               return;
+
        if (!name) {
                _E("[DEBUG] service name is NULL");
                return;
@@ -541,7 +496,7 @@ static int lowmem_limit_service(void *data)
        if (ps->pai && ps->pai->memory.memlimit_update_exclude)
                return RESOURCED_ERROR_NONE;
 
-       if (mem_service_limit) {
+       if (mem_service_limit && mem_service_action != PROC_ACTION_IGNORE) {
                lowmem_limit_set_app(mem_service_limit, ps->pai, mem_service_action);
        }
        return RESOURCED_ERROR_NONE;
@@ -556,10 +511,13 @@ static int lowmem_limit_appwidget(void *data)
        if (ps->pai && ps->pai->memory.memlimit_update_exclude)
                return RESOURCED_ERROR_NONE;
 
-       if (mem_guiapp_limit && ps->pai->type == PROC_TYPE_GUI) {
+       if (mem_guiapp_limit && mem_guiapp_action != PROC_ACTION_IGNORE &&
+           ps->pai->type == PROC_TYPE_GUI) {
                lowmem_limit_set_app(mem_guiapp_limit, ps->pai, mem_guiapp_action);
        }
-       if (mem_widget_limit && ps->pai->type == PROC_TYPE_WIDGET) {
+
+       if (mem_widget_limit && mem_widget_action != PROC_ACTION_IGNORE &&
+           ps->pai->type == PROC_TYPE_WIDGET) {
                lowmem_limit_set_app(mem_widget_limit, ps->pai, mem_widget_action);
        }
 
@@ -625,7 +583,6 @@ void lowmem_limit_init(void)
        int result;
        unsigned int usage;
 
-       mem_limit = MEM_LIMIT_TRHESHOLD;
        result = cgroup_read_node_uint32(MEMCG_PATH, MEMCG_SWAP_USAGE, &usage);
        if (result == RESOURCED_ERROR_NONE)
                registerpath = MEMCG_SWAP_USAGE;
@@ -634,16 +591,16 @@ void lowmem_limit_init(void)
 
        register_notifier(RESOURCED_NOTIFIER_LIMIT_SYSTEM_SERVICE, lowmem_limit_system_service);
        register_notifier(RESOURCED_NOTIFIER_LIMIT_APP, lowmem_limit_app);
-       if (mem_limit == MEM_LIMIT_NONE)
-               return;
 
-       if (mem_service_limit)
+       if (mem_service_limit && mem_service_action != PROC_ACTION_IGNORE)
                register_notifier(RESOURCED_NOTIFIER_SERVICE_LAUNCH, lowmem_limit_service);
-       if (mem_guiapp_limit || mem_widget_limit)
+       if ((mem_guiapp_limit && mem_guiapp_action != PROC_ACTION_IGNORE) ||
+           (mem_widget_limit && mem_widget_action != PROC_ACTION_IGNORE))
                register_notifier(RESOURCED_NOTIFIER_APP_LAUNCH, lowmem_limit_appwidget);
-       if (mem_bgapp_limit) {
-               if (!mem_guiapp_limit || !mem_widget_limit) {
-                       _W("Background app limit requires that both GUIApp and Widget limits to be set to work properly. Ignoring.");
+       if (mem_bgapp_limit && mem_bgapp_action != PROC_ACTION_IGNORE) {
+               if (!(mem_guiapp_limit && mem_guiapp_action != PROC_ACTION_IGNORE) ||
+                   !(mem_widget_limit && mem_widget_action != PROC_ACTION_IGNORE)) {
+                       _W("[DEBUG] Background app limit requires that both GUIApp and Widget limits to be set to work properly. Ignoring.");
                } else {
                        register_notifier(RESOURCED_NOTIFIER_APP_BACKGRD, lowmem_limit_bgapp);
                        register_notifier(RESOURCED_NOTIFIER_APP_FOREGRD, lowmem_limit_fgapp);
index 85684dc..cb822ee 100644 (file)
@@ -1876,7 +1876,7 @@ static void load_configs(const char *path)
 
                        if (lvl == MEM_LEVEL_OOM)
                                memcg_set_leave_threshold(CGROUP_ROOT,
-                                               get_memcg_info(CGROUP_ROOT)->threshold[lvl] * 1.5);
+                                               get_memcg_info(CGROUP_ROOT)->threshold[lvl] * 2);
                }
                else if (memcg_conf->threshold[lvl].threshold > 0) {
                        memcg_set_threshold(CGROUP_ROOT, lvl,
@@ -1884,7 +1884,7 @@ static void load_configs(const char *path)
 
                        if (lvl == MEM_LEVEL_OOM)
                                memcg_set_leave_threshold(CGROUP_ROOT,
-                                               get_memcg_info(CGROUP_ROOT)->threshold[lvl] * 1.5);
+                                               get_memcg_info(CGROUP_ROOT)->threshold[lvl] * 2);
                }
        }
        oom_popup_enable = memcg_conf->oom_popup;
index 3741858..2f5d84c 100644 (file)
@@ -537,29 +537,32 @@ static int cpu_sched_rt_scheduler(void *data)
 {
        _cleanup_free_ char *path = NULL;
        int result;
-       int32_t temp;
+       int32_t runtime;
        struct proc_status *ps = (struct proc_status *)data;
 
        assert(ps);
        assert(ps->pci);
        assert(ps->pci->name);
 
-       result = cgroup_read_node_int32(MEMCG_HIGH_PP_PATH, CPUCG_RT_CONTROL_BANDWIDTH, &temp);
+       result = cgroup_read_node_int32(CPUCG_PATH, CPUCG_RT_CONTROL_BANDWIDTH, &runtime);
        if (result < 0) {
                _W("[DEBUG] rt_runtime_us is not supported");
                return RESOURCED_ERROR_FAIL;
        }
 
-       result = asprintf(&path, "%s/%s", MEMCG_HIGH_PP_PATH, ps->pci->name);
+       cgroup_write_node_int32(CPUCG_VIP_PP_PATH, CPUCG_RT_CONTROL_BANDWIDTH, runtime);
+       cgroup_write_node_int32(CPUCG_HIGH_PP_PATH, CPUCG_RT_CONTROL_BANDWIDTH, runtime);
+
+       result = asprintf(&path, "%s/%s", CPUCG_HIGH_PP_PATH, ps->pci->name);
        if (result < 0) {
                _E("[DEBUG] not enough memory");
                return RESOURCED_ERROR_OUT_OF_MEMORY;
        }
 
-       result = cgroup_make_subdir(MEMCG_HIGH_PP_PATH, ps->pci->name, NULL);
+       result = cgroup_make_subdir(CPUCG_HIGH_PP_PATH, ps->pci->name, NULL);
        if (result < 0) {
                _E("[DEBUG] Failed to create cgroup subdir '%s/%s'",
-                               MEMCG_HIGH_PP_PATH, ps->pci->name);
+                               CPUCG_HIGH_PP_PATH, ps->pci->name);
                return RESOURCED_ERROR_FAIL;
        }