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
===========
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>
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>
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>
<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>
--- /dev/null
+/**
+ * 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)