process: Support fixed oom for app via Private config 10/288410/3 accepted/tizen/unified/20230220.174507
authorUnsung Lee <unsung.lee@samsung.com>
Thu, 16 Feb 2023 06:39:01 +0000 (15:39 +0900)
committerUnsung Lee <unsung.lee@samsung.com>
Fri, 17 Feb 2023 01:54:59 +0000 (10:54 +0900)
This patch includes
  - Parsing config from Private Section (config-parser.c/h)
  - Elimination of old style fixed oom config (proc.conf, README)
  - Replacement of oom_fixed_app_list using fixed_app_list
    (a.k.a. an hashtable which manages all apps in the Private Section)

Difference between old style fixed oom config and the current one
  - old style: Add app name directly in the common configuration file
  - the current style: Add app name in the Private Section (xxx.conf.d/yyy.conf)
    That is, any developer can add new configurations with making
private conf files.

Change-Id: I367f6b6e0a7315c1e84b1b3871f6bb7bcc4a005a
Signed-off-by: Unsung Lee <unsung.lee@samsung.com>
conf/README
conf/proc.conf [deleted file]
packaging/resourced.spec
src/CMakeLists.txt
src/common/conf/config-parser.c
src/common/conf/config-parser.h
src/common/proc-common.h
src/process/proc-oom-priority.c

index 8fba6a4..c61c470 100644 (file)
@@ -461,24 +461,10 @@ Comment: Specify logging type.
          If DLOG and DB type, then <type> is 5 (0x01 | 0x04).
 Example: logging=5
 
-5. proc.conf
-============
-
-5.1 OOM_FIXED_APPS
-==================
-Key: <app name>
-Value: <oom_score_adj>
-Comment: Specify the oom_score_adj.
-         oom_score_adj is an integer value between -900 to 250.
-         Predefined values cannot be used.
-         Predefined values are: -900, 0, 100, 150, 200, 230, 250
-         (Please refer to procfs.h)
-Example: org.tizen.homescreen-efl=-99
-
-6. limiter.conf.d/*.conf
+5. limiter.conf.d/*.conf
 ========================
 
-6.1 Section: Private
+5.1 Section: Private
 ====================
 Key: App|Service|SERVICE|Process|PROCESS
 Value: <name>
@@ -508,10 +494,10 @@ Comment: Specify whether the cpu throttling is enabled.
          If (no|0|off), disable cpu throttling.
 Example: CpuThrottling=yes
 
-7. optimizer.conf.d/*.conf
+6. optimizer.conf.d/*.conf
 ==========================
 
-7.1 Section: Private
+6.1 Section: Private
 ====================
 Key: App|Service|SERVICE|Process|PROCESS
 Value: <name>
@@ -548,10 +534,10 @@ Value: (cpu id|min cpu id-max cpu id|cpu_id,cpu_id)
 Comment: Specify the cpu affinity of this app
 Example: CpuAffinity=1,3-5,8
 
-8. process.conf.d/*.conf
+7. process.conf.d/*.conf
 ========================
 
-8.1 Section: Private
+7.1 Section: Private
 ====================
 Key: App|Service|SERVICE|Process|PROCESS
 Value: <name>
@@ -572,10 +558,19 @@ Comment: Specify an action for watchdog.
          <action> can be: ignore, kill
 Example: WatchdogAction=ignore
 
-9. vip-process.d/*.conf
+Key: OomScore
+Value: <oom_score_adj>
+Comment: Specify the oom_score_adj.
+         oom_score_adj is an integer value between -900 to 250.
+         Predefined values cannot be used.
+         Predefined values are: -900, 0, 100, 150, 200, 230, 250
+         (Please refer to procfs.h)
+Example: OomScore=125
+
+8. vip-process.d/*.conf
 =======================
 
-9.1 Section: Private|VIP_GROUP
+8.1 Section: Private|VIP_GROUP
 ==============================
 Key: App|Service|SERVICE|Process|PROCESS
 Value: <name>
diff --git a/conf/proc.conf b/conf/proc.conf
deleted file mode 100644 (file)
index dfad98e..0000000
+++ /dev/null
@@ -1,2 +0,0 @@
-#[OOM_FIXED_APPS]
-#org.tizen.homescreen-efl=-99
index 0b5b404..ee41391 100644 (file)
@@ -164,7 +164,6 @@ mv %{confdir}/optimizer-profile-tv.conf %{confdir}/optimizer.conf
 %{confdir}/optimizer.conf
 %{confdir}/process.conf
 %{confdir}/monitor.conf
-%{confdir}/proc.conf
 
 %files config-tv
 %manifest resourced.manifest
index 593dde6..6ac5538 100644 (file)
@@ -260,5 +260,3 @@ ENDIF()
 
 INSTALL(FILES ${CONF_DIR}/process.conf
        DESTINATION ${RD_CONFIG_PATH} RENAME process.conf)
-INSTALL(FILES ${CONF_DIR}/proc.conf
-       DESTINATION ${RD_CONFIG_PATH} RENAME proc.conf)
index 3a60e99..5027245 100644 (file)
@@ -31,6 +31,7 @@
 #include "dedup-common.h"
 #include "compact-common.h"
 #include "cpu-common.h"
+#include "procfs.h"
 
 #define MAX_SECTION            64
 
@@ -776,6 +777,7 @@ static int vendor_config(struct parse_result *result, void *user_data)
                        pci->watchdog_action = PROC_ACTION_KILL;
                        pci->fail_action = PROC_ACTION_IGNORE;
                        pci->cpu_boosting_level = CPU_BOOSTING_LEVEL_NONE;
+                       pci->oom_score = OOMADJ_APP_MAX + 10;
                        strncpy(pci->name, result->value, sizeof(pci->name)-1);
 
                        if (result->name[0] == 'A')
@@ -917,6 +919,21 @@ static int vendor_config(struct parse_result *result, void *user_data)
                }
                pci->cpu_sched_info.rt_period_us = config_parse_time_us(result->value);
        }*/
+       else if (!strncmp(result->name, OOM_SCORE_NAME_CONF, strlen(OOM_SCORE_NAME_CONF) + 1)
+                       && *config_type == PROCESS_CONFIG) {
+               if (!pci) {
+                       _E("process configuration information pointer should not be NULL");
+                       return RESOURCED_ERROR_FAIL;
+               }
+
+               int oom_score = atoi(result->value);
+               if (oom_score < OOMADJ_SERVICE_MIN || oom_score > OOMADJ_APP_MAX) {
+                       _E("invalid parameter (oom_score = %d)", oom_score);
+                       return RESOURCED_ERROR_INVALID_PARAMETER;
+               }
+
+               pci->oom_score = oom_score;
+       }
        else if (!strncmp(result->name, ACTION_ON_FAILURE_NAME_CONF,
                                strlen(ACTION_ON_FAILURE_NAME_CONF)+1) && *config_type == PROCESS_CONFIG) {
                if (!pci) {
index 60d1642..e774635 100644 (file)
@@ -73,6 +73,7 @@ extern "C" {
 #define ACTION_ON_FAILURE_NAME_CONF                  "ActionOnFailure"
 #define OLD_ACTION_ON_FAILURE_NAME_CONF              "ACTION_ON_FAILURE"
 #define        WATCHDOG_ACTION_NAME_CONF                    "WatchdogAction"
+#define OOM_SCORE_NAME_CONF                          "OomScore"
 #define THROTTLING_LIMIT_NAME_CONF                   "ThrottlingLimit"
 #define MEDIUM_LEVEL_NAME_CONF                       "MediumLevel"
 #define LOW_LEVEL_NAME_CONF                          "LowLevel"
index 5a00c71..c635a47 100644 (file)
@@ -68,6 +68,7 @@ struct proc_conf_info {
        struct mem_action mem_action;
        struct cpu_sched_info cpu_sched_info;
        struct cpuset_info cpuset_info;
+       int oom_score;
        bool memory_throttling_enable;
        bool cpu_throttling_enable;
        cpu_boosting_level_e cpu_boosting_level;
index 3acbd75..1391d8a 100644 (file)
 #include "resourced.h"
 #include "trace.h"
 
-#define PRIORITY_CONF_FILE     RD_CONFIG_FILE(proc)
-
-#define FIXED_OOM_CONF_SECTION "OOM_FIXED_APPS"
-
 #define FIXED_OOM_MIN          OOMADJ_SERVICE_MIN
 #define FIXED_OOM_MAX          OOMADJ_BACKGRD_LOCKED
 
-static GHashTable *oom_fixed_app_list;
 static GHashTable *oom_fixed_pid_list;
 
 static int proc_oom_priority_set_fixed_oom(void *data)
 {
        int ret;
-       int *fixed_oom = NULL;
-       gint *key, *val;
+       int *fixed_oom_score = NULL;
+       gint *pid, *oom_score;
        struct proc_status *ps = (struct proc_status *)data;
 
        if (!ps)
                return RESOURCED_ERROR_INVALID_PARAMETER;
 
-       fixed_oom = (int *)g_hash_table_lookup(oom_fixed_app_list, ps->pai->appid);
+       struct proc_conf_info *pci = fixed_app_and_service_exist_check(ps->pai->appid, APP_TYPE);
+       /* This app is not interested in the fixed oom configuration */
+       if (!pci || pci->oom_score > OOMADJ_APP_MAX)
+               return RESOURCED_ERROR_NONE;
 
        /* Make another hashtable for fast searching during proc_set_oom_score_adj */
-       if (fixed_oom) {
-               ret = proc_set_oom_score_adj(ps->pid, *fixed_oom, ps->pai);
-               if (ret != RESOURCED_ERROR_NONE) {
-                       _E("Failed to set the fixed oom for %s", ps->pai->appid);
-                       return ret;
-               }
-
-               _D("Set the fixed oom of %s with %d", ps->pai->appid, *fixed_oom);
-               key = g_new(gint, 1);
-               val = g_new(gint, 1);
-               *key = ps->pid;
-               *val = *fixed_oom;
-               g_hash_table_insert(oom_fixed_pid_list, (gpointer)key, (gpointer)val);
+       fixed_oom_score = &pci->oom_score;
+       ret = proc_set_oom_score_adj(ps->pid, *fixed_oom_score, ps->pai);
+       if (ret != RESOURCED_ERROR_NONE) {
+               _E("Failed to set the fixed oom for %s", ps->pai->appid);
+               return ret;
        }
 
+       _D("Set the fixed oom of %s with %d", ps->pai->appid, *fixed_oom_score);
+       pid = g_new(gint, 1);
+       oom_score = g_new(gint, 1);
+       *pid = ps->pid;
+       *oom_score = *fixed_oom_score;
+       g_hash_table_insert(oom_fixed_pid_list, (gpointer)pid, (gpointer)oom_score);
+
        return RESOURCED_ERROR_NONE;
 }
 
@@ -88,17 +85,25 @@ int proc_oom_priority_is_oom_fixed_process(int pid)
        return g_hash_table_contains(oom_fixed_pid_list, &pid);
 }
 
-static int load_fixed_oom_config(struct parse_result *result, void *user_data)
+static int load_fixed_oom_config(void)
 {
        int score;
-       gint *fixed_oom;
+       gpointer app_name;
+       gpointer proc_conf_ptr;
+       GHashTableIter app_list_iter;
 
-       if (!result)
-               return RESOURCED_ERROR_INVALID_PARAMETER;
+       g_hash_table_iter_init(&app_list_iter, fixed_app_list_get());
+       while (g_hash_table_iter_next(&app_list_iter, &app_name, &proc_conf_ptr)) {
+               struct proc_conf_info *pci = (struct proc_conf_info *)proc_conf_ptr;
+
+               if (!pci) {
+                       _W("[CPU-SCHED] Process configuration information is NULL");
+                       continue;
+               }
 
-       if (!strncmp(result->section, FIXED_OOM_CONF_SECTION, strlen(FIXED_OOM_CONF_SECTION) + 1)) {
-               /* Set predefined OOM score */
-               score = atoi(result->value);
+               score = pci->oom_score;
+               if (score > OOMADJ_APP_MAX)
+                       continue;
 
                switch (score) {
                        case OOMADJ_SERVICE_MIN:
@@ -108,20 +113,15 @@ static int load_fixed_oom_config(struct parse_result *result, void *user_data)
                        case OOMADJ_FOREGRD_UNLOCKED:
                        case OOMADJ_BACKGRD_PERCEPTIBLE:
                        case OOMADJ_BACKGRD_LOCKED:
-                               _E("You can't set the fixed oom for %s with predefined value %d", result->name, score);
-                               return RESOURCED_ERROR_INVALID_PARAMETER;
+                               _W("You can't set the fixed oom for %s with predefined value %d", pci->name, score);
+                               pci->oom_score = OOMADJ_APP_MAX + 10;
+                               break;
                        default:
                                if (score < FIXED_OOM_MIN || score > FIXED_OOM_MAX) {
-                                       _E("You can't set the fixed oom for %s with the out of range %d", result->name, score);
-                                       return RESOURCED_ERROR_INVALID_PARAMETER;
+                                       _W("You can't set the fixed oom for %s with the out of range %d", pci->name, score);
+                                       pci->oom_score = OOMADJ_APP_MAX + 10;
                                }
                }
-
-               fixed_oom = g_new(gint, 1);
-               *fixed_oom = score;
-               g_hash_table_insert(oom_fixed_app_list,
-                               g_strndup(result->name, strlen(result->name)),
-                               (gpointer)fixed_oom);
        }
 
        return RESOURCED_ERROR_NONE;
@@ -129,11 +129,10 @@ static int load_fixed_oom_config(struct parse_result *result, void *user_data)
 
 static int proc_oom_priority_init(void *data)
 {
-       oom_fixed_app_list = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
        oom_fixed_pid_list = g_hash_table_new_full(g_int_hash, g_int_equal, g_free, g_free);
-       g_assert(oom_fixed_app_list && oom_fixed_pid_list);
+       g_assert(oom_fixed_pid_list);
 
-       config_parse(PRIORITY_CONF_FILE, load_fixed_oom_config, NULL);
+       load_fixed_oom_config();
 
        register_notifier(RESOURCED_NOTIFIER_APP_LAUNCH, proc_oom_priority_set_fixed_oom);
        register_notifier(RESOURCED_NOTIFIER_APP_TERMINATED, proc_oom_priority_remove_pid);
@@ -142,8 +141,6 @@ static int proc_oom_priority_init(void *data)
 
 static int proc_oom_priority_exit(void *data)
 {
-       if (oom_fixed_app_list)
-               g_hash_table_destroy(oom_fixed_app_list);
        if (oom_fixed_pid_list)
                g_hash_table_destroy(oom_fixed_pid_list);
        unregister_notifier(RESOURCED_NOTIFIER_APP_LAUNCH, proc_oom_priority_set_fixed_oom);