#define FIXED_OOM_MAX OOMADJ_BACKGRD_LOCKED
static GHashTable *oom_fixed_app_list;
+static GHashTable *oom_fixed_pid_list;
static int proc_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);
- if (ret != RESOURCED_ERROR_NONE)
+ if (ret != RESOURCED_ERROR_NONE) {
_E("Failed to set the fixed oom for %s", ps->pai->appid);
- else
- _D("Set the fixed oom of %s with %d", ps->pai->appid, *fixed_oom);
+ 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_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_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)) {
- fixed_oom = g_new(gint, 1);
- *fixed_oom = atoi(result->value);
+ /* Set predefined OOM score */
+ score = atoi(result->value);
- switch (*fixed_oom) {
+ switch (score) {
case OOMADJ_SERVICE_MIN:
case OOMADJ_SU:
case OOMADJ_INIT:
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, *fixed_oom);
- g_free(fixed_oom);
+ _E("You can't set the fixed oom for %s with predefined value %d", result->name, score);
return RESOURCED_ERROR_INVALID_PARAMETER;
- break;
default:
- if (*fixed_oom < FIXED_OOM_MIN || *fixed_oom > FIXED_OOM_MAX) {
- _E("You can't set the fixed oom for %s with the out of range %d", result->name, *fixed_oom);
- g_free(fixed_oom);
- return RESOURCED_ERROR_INVALID_PARAMETER;
+ 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;
}
- break;
}
+ 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);
static int proc_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_priority_set_fixed_oom);
+ register_notifier(RESOURCED_NOTIFIER_APP_TERMINATED, proc_priority_remove_pid);
return RESOURCED_ERROR_NONE;
}
{
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_priority_set_fixed_oom);
+ unregister_notifier(RESOURCED_NOTIFIER_APP_TERMINATED, proc_priority_remove_pid);
return RESOURCED_ERROR_NONE;
}