static GHashTable *oom_fixed_pid_list;
+#define is_fixed_oom_score(oom_score) \
+ (oom_score <= FIXED_OOM_MAX && oom_score >= FIXED_OOM_MIN)
+
+static bool is_wrong_oom_score(int oom_score, const char *name)
+{
+ /**
+ * FIXME: Currently, resourced does not allow predefined oom_score_adj
+ * to be used as fixed oom_score_adj. This is because, resourced judges
+ * the current status of app using oom_score_adj of app (/proc/<pid>/oom_score_adj).
+ * However, it reduces resourced user experience considerably.
+ */
+ switch (oom_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:
+ _W("Do not set the fixed oom for %s with predefined value %d",
+ name, oom_score);
+ return true;
+ default:
+ if (oom_score < FIXED_OOM_MIN || oom_score > FIXED_OOM_MAX) {
+ _W("Do not set the fixed oom for %s with the out of range %d",
+ name, oom_score);
+ return true;
+ }
+
+ return false;
+ }
+}
+
static int proc_oom_priority_set_fixed_oom(void *data)
{
- int ret;
- int *fixed_oom_score = NULL;
- gint *pid, *oom_score;
struct proc_status *ps = (struct proc_status *)data;
+ gint *oom_score;
+ gint *pid;
+ int ret;
if (!ps)
return RESOURCED_ERROR_INVALID_PARAMETER;
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)
+ if (!pci)
return RESOURCED_ERROR_NONE;
- /* Make another hashtable for fast searching during proc_set_oom_score_adj */
- fixed_oom_score = &pci->oom_score;
- ret = proc_set_oom_score_adj(ps->pid, *fixed_oom_score, ps->pai);
+ if (!is_fixed_oom_score(pci->oom_score) && !(pci->is_app_in_foreground_app_list))
+ return RESOURCED_ERROR_NONE;
+
+ if (is_fixed_oom_score(pci->oom_score) && pci->is_app_in_foreground_app_list) {
+ _W("load_fixed_oom_config() should ignore OomScore before");
+ pci->oom_score = OOMADJ_APP_MAX + 10;
+ }
+
+ if (pci->is_app_in_foreground_app_list) {
+ /**
+ * TODO: Update /proc/<pid>/oom_score_adj with fixed-oom score
+ * when app status is changed to the foreground.
+ * Currently, resourced changes foreground app's oom_score_adj
+ * in the 'proc_app_info', so /proc/<pid>/oom_score_adj is not changed
+ * regardless of the configuration.
+ * This is because resourced judges the current app status by reading
+ * /proc/<pid>/oom_score_adj when process status is changed. Therefore,
+ * if /proc/<pid>/oom_score_adj is chagned with fixed oom_score_adj then,
+ * the resourced will misunderstand the process current status.
+ */
+ ps->pai->memory.foreground_oom_score_adj = OOMADJ_SERVICE_MIN;
+ return RESOURCED_ERROR_NONE;
+ }
+
+ ret = proc_set_oom_score_adj(ps->pid, pci->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);
+ _D("Set the fixed oom of %s with %d", ps->pai->appid, pci->oom_score);
+
pid = g_new(gint, 1);
- oom_score = g_new(gint, 1);
*pid = ps->pid;
- *oom_score = *fixed_oom_score;
+ oom_score = g_new(gint, 1);
+ *oom_score = pci->oom_score;
g_hash_table_insert(oom_fixed_pid_list, (gpointer)pid, (gpointer)oom_score);
return RESOURCED_ERROR_NONE;
static int load_fixed_oom_config(void)
{
- int score;
gpointer app_name;
gpointer proc_conf_ptr;
GHashTableIter app_list_iter;
continue;
}
- score = pci->oom_score;
- if (score > OOMADJ_APP_MAX)
- continue;
+ if (!is_fixed_oom_score(pci->oom_score) && !(pci->is_app_in_foreground_app_list))
+ return RESOURCED_ERROR_NONE;
- 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:
- _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) {
- _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;
- }
+ if (is_fixed_oom_score(pci->oom_score) && pci->is_app_in_foreground_app_list) {
+ _I("Ignore 'OomScore' configuration of app = %s from no on", pci->name);
+ pci->oom_score = OOMADJ_APP_MAX + 10;
}
+
+ if (!is_fixed_oom_score(pci->oom_score))
+ continue;
+
+ if (is_wrong_oom_score(pci->oom_score, pci->name))
+ pci->oom_score = OOMADJ_APP_MAX + 10;
}
return RESOURCED_ERROR_NONE;