process: Restore OOM_FIXED_APPS 43/287043/5 accepted/tizen/unified/20230126.170128
authorSangYoun Kwak <sy.kwak@samsung.com>
Thu, 19 Jan 2023 03:25:55 +0000 (12:25 +0900)
committerSangYoun Kwak <sy.kwak@samsung.com>
Thu, 26 Jan 2023 01:49:11 +0000 (10:49 +0900)
The OOM_FIXED_APPS feature fixes the oom score of some applications
specified specified in the proc.conf file.

This feature was removed as follows(reverse chronological order):
    f6c9aab ("Support old style vip cgroup")
    ad81bd2 ("Rearrange memory cgroup")
    740d0f5 ("Rearrange optimizer configuration")
    f2b65a3 ("Update limiter.conf and support realtime")
    a3344a9 ("Support per app(service) management")
    574bf1b ("Add 'PerProcess' configurations")
    36a18bf ("Modify comments & remove useless things")

This feature has been restored by request.

Change-Id: I155a31722f1b5cae446663f690234faee0babe2c
Signed-off-by: SangYoun Kwak <sy.kwak@samsung.com>
conf/README
conf/proc.conf [new file with mode: 0644]
src/common/proc-common.h
src/common/procfs/procfs.c
src/common/procfs/procfs.h
src/process/proc-oom-priority.c [new file with mode: 0644]

index 6cd771c..960b6dc 100644 (file)
@@ -7,10 +7,11 @@ Index
 2. optimizer.conf          : configurations to optimize resources
 3. monitor.conf            : configurations to monitor resources
 4. process.conf            : configurations to manage process
-5. limiter.conf.d/*.conf   : configurations to limit resources, for each app
-6. optimizer.conf.d/*.conf : configurations to optimize resources, for each app
-7. process.conf.d/*.conf   : configurations to manage process, for each app
-8. vip-process.d/*.conf    : configurations to manage vip-process, for each app
+5. proc.conf               : configurations to specify the oom_score_adj for each app
+6. limiter.conf.d/*.conf   : configurations to limit resources, for each app
+7. optimizer.conf.d/*.conf : configurations to optimize resources, for each app
+8. process.conf.d/*.conf   : configurations to manage process, for each app
+9. vip-process.d/*.conf    : configurations to manage vip-process, for each app
 
 File Format
 ===========
@@ -460,10 +461,24 @@ Comment: Specify logging type.
          If DLOG and DB type, then <type> is 5 (0x01 | 0x04).
 Example: logging=5
 
-5. limiter.conf.d/*.conf
+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.1 Section: Private
+6.1 Section: Private
 ====================
 Key: App|Service|SERVICE|Process|PROCESS
 Value: <name>
@@ -493,10 +508,10 @@ Comment: Specify whether the cpu throttling is enabled.
          If (no|0|off), disable cpu throttling.
 Example: CpuThrottling=yes
 
-6. optimizer.conf.d/*.conf
+7. optimizer.conf.d/*.conf
 ==========================
 
-6.1 Section: Private
+7.1 Section: Private
 ====================
 Key: App|Service|SERVICE|Process|PROCESS
 Value: <name>
@@ -528,10 +543,10 @@ Value: (strong|medium|weak)
 Comment: Specify the boosting level of this app/service/process.
 Example: CpuBoostingLevel=medium
 
-7. process.conf.d/*.conf
+8. process.conf.d/*.conf
 ========================
 
-7.1 Section: Private
+8.1 Section: Private
 ====================
 Key: App|Service|SERVICE|Process|PROCESS
 Value: <name>
@@ -552,10 +567,10 @@ Comment: Specify an action for watchdog.
          <action> can be: ignore, kill
 Example: WatchdogAction=ignore
 
-8. vip-process.d/*.conf
+9. vip-process.d/*.conf
 =======================
 
-8.1 Section: Private|VIP_GROUP
+9.1 Section: Private|VIP_GROUP
 ==============================
 Key: App|Service|SERVICE|Process|PROCESS
 Value: <name>
diff --git a/conf/proc.conf b/conf/proc.conf
new file mode 100644 (file)
index 0000000..dfad98e
--- /dev/null
@@ -0,0 +1,2 @@
+#[OOM_FIXED_APPS]
+#org.tizen.homescreen-efl=-99
index ce9df5c..18f107a 100644 (file)
@@ -273,7 +273,7 @@ static inline void cleanup_proc_app_list_close_func(GSList **l)
  * @param[in] pid  Process ID
  * @return  1 if it is OOM-fixed app. Else, 0
  */
-//int proc_priority_is_oom_fixed_process(int pid);
+int proc_oom_priority_is_oom_fixed_process(int pid);
 
 /**
  * @desc  Check whether this process is cpu cgroup fixed app or not
index 69c7b64..44b4194 100644 (file)
@@ -159,6 +159,10 @@ int proc_set_oom_score_adj(int pid, int oom_score_adj, struct proc_app_info *pai
        struct lowmem_control_data lowmem_data;
        char buf[sizeof(PROC_OOM_SCORE_ADJ_PATH) + MAX_DEC_SIZE(int)] = {0};
 
+       /* Don't touch OOM-fixed process' score */
+       if (proc_oom_priority_is_oom_fixed_process(pid))
+               return RESOURCED_ERROR_NONE;
+
        snprintf(buf, sizeof(buf), PROC_OOM_SCORE_ADJ_PATH, pid);
        fp = fopen(buf, "r+");
        if (fp == NULL)
index c2c0f52..df1b12b 100644 (file)
@@ -34,6 +34,7 @@ extern "C" {
 
 #include "proc-common.h"
 
+#define OOMADJ_SERVICE_MIN             (-900)
 #define OOMADJ_SU                      (0)
 #define OOMADJ_INIT                    (100)
 #define OOMADJ_FOREGRD_LOCKED          (150)
diff --git a/src/process/proc-oom-priority.c b/src/process/proc-oom-priority.c
new file mode 100644 (file)
index 0000000..3acbd75
--- /dev/null
@@ -0,0 +1,159 @@
+/**
+ * resourced
+ *
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+*/
+
+/**
+ * @file proc-oom-priority.c
+ * @desc set specific oom priority to predefined application
+*/
+
+#include <glib.h>
+
+#include "config-parser.h"
+#include "notifier.h"
+#include "proc-main.h"
+#include "procfs.h"
+#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;
+       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);
+
+       /* 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);
+       }
+
+       return RESOURCED_ERROR_NONE;
+}
+
+static int proc_oom_priority_remove_pid(void *data)
+{
+       struct proc_status *ps = (struct proc_status *)data;
+       int pid = ps->pid;
+
+       if (g_hash_table_contains(oom_fixed_pid_list, &pid))
+               g_hash_table_remove(oom_fixed_pid_list, &pid);
+
+       return RESOURCED_ERROR_NONE;
+}
+
+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)
+{
+       int score;
+       gint *fixed_oom;
+
+       if (!result)
+               return RESOURCED_ERROR_INVALID_PARAMETER;
+
+       if (!strncmp(result->section, FIXED_OOM_CONF_SECTION, strlen(FIXED_OOM_CONF_SECTION) + 1)) {
+               /* Set predefined OOM score */
+               score = atoi(result->value);
+
+               switch (score) {
+                       case OOMADJ_SERVICE_MIN:
+                       case OOMADJ_SU:
+                       case OOMADJ_INIT:
+                       case OOMADJ_FOREGRD_LOCKED:
+                       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;
+                       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;
+                               }
+               }
+
+               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;
+}
+
+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);
+
+       config_parse(PRIORITY_CONF_FILE, load_fixed_oom_config, NULL);
+
+       register_notifier(RESOURCED_NOTIFIER_APP_LAUNCH, proc_oom_priority_set_fixed_oom);
+       register_notifier(RESOURCED_NOTIFIER_APP_TERMINATED, proc_oom_priority_remove_pid);
+       return RESOURCED_ERROR_NONE;
+}
+
+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);
+       unregister_notifier(RESOURCED_NOTIFIER_APP_TERMINATED, proc_oom_priority_remove_pid);
+       return RESOURCED_ERROR_NONE;
+}
+
+static const struct proc_module_ops proc_oom_priority_ops = {
+       .name           = "PROC_OOM_PRIORITY",
+       .init           = proc_oom_priority_init,
+       .exit           = proc_oom_priority_exit,
+};
+PROC_MODULE_REGISTER(&proc_oom_priority_ops)