static gboolean liveness_check_cb(gpointer data)
{
- struct memory_limit_event *mle = (struct memory_limit_event *)data;
+ GArray *pids_array = (GArray *)data;
- if (!mle) {
- _E("[MEMORY-LIMIT] memory limit event structure is NULL");
+ if (pids_array == NULL) {
+ _E("[MEMORY-LIMIT] pids array should not be NULL");
goto timer_out;
}
- if (mle->pids_array == NULL) {
- _E("[MEMORY-LIMIT] pids array should not be NULL");
- goto timer_out;
+ if (!pids_array->len) {
+ _E("[MEMORY-LIMIT] pids array size should be larger than 0");
+ goto array_free;
}
- for (int i = 0; i < mle->pids_array->len; i++) {
- pid_t pid = g_array_index(mle->pids_array, pid_t, i);
+ for (int i = 0; i < pids_array->len; i++) {
+ pid_t pid = g_array_index(pids_array, pid_t, i);
if (!pid)
continue;
+ _I("[MEMORY-LIMIT] Check target pid (%d)'s liveness - %d procs/%d procs", pid, i + 1, pids_array->len);
+
if (kill(pid, 0) == 0) {
- _I("[MEMORY-LIMIT] dir %s's pid (%d) is still avlie, so kill forcely", mle->path, pid);
+ _I("[MEMORY-LIMIT] pid (%d) is still alive, so kill forcibly", pid);
safe_kill(pid, SIGKILL);
}
}
- g_array_free(mle->pids_array, true);
-
- mle->pids_array = NULL;
+array_free:
+ g_array_free(pids_array, true);
timer_out:
return G_SOURCE_REMOVE;
}
safe_kill(pid, SIGTERM);
}
-
- if (mle->pids_array == NULL) {
- mle->pids_array = pids_array;
- g_timeout_add_seconds(2, liveness_check_cb, mle);
- }
- else
- g_array_free(pids_array, true);
+ g_timeout_add_seconds(2, liveness_check_cb, pids_array);
break;
default:
gpointer hash_entry;
struct memory_limit_event *mle = NULL;
char buf[MAX_DEC_SIZE(int)] = {0};
- unsigned long long max_limit_bytes;
+ unsigned long long max_limit_bytes = limit_bytes;
+
+
+ if (lowmem_get_totalram() > 0) {
+ if (limit_bytes > lowmem_get_totalram()) {
+ max_limit_bytes = lowmem_get_totalram();
+ limit_bytes = lowmem_get_totalram();
+ }
+ else if (limit_bytes * 1.2 > lowmem_get_totalram()) {
+ max_limit_bytes = lowmem_get_totalram();
+ }
+ else
+ max_limit_bytes = limit_bytes * 1.2;
+ }
if (memory_limit_hash) {
/* TO DO: currently concurrent processes with same app name are located
}
}
- if (limit_bytes > lowmem_get_totalram()) {
- max_limit_bytes = lowmem_get_totalram();
- limit_bytes = lowmem_get_totalram();
- }
- else if (limit_bytes * 1.2 > lowmem_get_totalram()) {
- max_limit_bytes = lowmem_get_totalram();
- }
- else
- max_limit_bytes = limit_bytes * 1.2;
check_oom_and_set_limit(dir, max_limit_bytes);
}
mle->action = action;
mle->threshold_bytes = limit_bytes;
- mle->pids_array = NULL;
add_fd_read_handler(fd, memory_action_cb, mle->path, NULL, &fdh);
mle->fdh = fdh;
g_hash_table_insert(memory_limit_hash, (gpointer)mle->path,