char fpath[BUF_MAX];
char *fname;
char *dir = (char*)data;
- int len = strlen(dir);
+ int len;
- if (!dir || len <= 0) {
- _E("Invalid parameter");
+ if (!dir) {
+ _E("Invalid parameter - dir is NULL");
return RESOURCED_ERROR_INVALID_PARAMETER;
}
- if (len >= BUF_MAX - 1) {
- _E("Directory path is too long");
- return RESOURCED_ERROR_FAIL;
+ len = strlen(dir);
+ if (len <= 0 || len >= BUF_MAX -1) {
+ _E("Invalid parameter - Directory path is too short or too long");
+ return RESOURCED_ERROR_INVALID_PARAMETER;
}
n = scandir(dir, &namelist, memps_file_select, alphasort);
lowmem_drain_queue(&lmw);
ctl = LOWMEM_NEW_REQUEST();
+ if (!ctl) {
+ _E("Critical - g_slice alloc failed - Lowmem cannot be deactivated");
+ return;
+ }
ctl->flags = OOM_DROP;
g_async_queue_push(lmw.queue, ctl);
g_async_queue_unref(lmw.queue);
}
}
+static bool lowmem_fragmentated(void)
+{
+ struct buddyinfo bi;
+ int ret;
+
+ ret = proc_get_buddyinfo("Normal", &bi);
+ if (ret < 0)
+ return false;
+
+ if (bi.page[PAGE_32K] + bi.page[PAGE_64K] + bi.page[PAGE_128K] == 0) {
+ _I("fragmentation detected, need to execute proactive oom killer");
+ return true;
+ }
+ return false;
+}
+
static void lowmem_proactive_oom_killer(int flags, char *appid)
{
unsigned int before;
}
#endif
- /*
- * When there is no history data for the launching app but it is
- * indicated as PROC_LARGEMEMORY, run oom killer based on proactive
- * threshold.
- */
- if (!(flags & PROC_LARGEMEMORY))
- return;
/*
* run proactive oom killer only when available is larger than
* proactive threshold
if (!proactive_threshold || before >= proactive_threshold)
return;
+ /*
+ * When there is no history data for the launching app,
+ * it is necessary to check current fragmentation state or application manifest file.
+ * So, resourced feels proactive LMK is required, run oom killer based on dynamic
+ * threshold.
+ */
+ if (!lowmem_fragmentated() && !(flags & PROC_LARGEMEMORY))
+ return;
+
/*
* free THRESHOLD_MARGIN more than real should be freed,
* because launching app is consuming up the memory.