#include "fd-handler.h"
#include "dbus-handler.h"
#include "safe-kill.h"
+#include "file-helper.h"
#define MEM_CONF_FILE RD_CONFIG_FILE(limiter)
#define MEMLIMIT_CONFIG_SECTION "MemLimit"
mle_timer_init:
mle->pid = -1;
- mle->sigterm_timer = NULL;
timer_out:
return G_SOURCE_REMOVE;
}
{
int result;
pid_t main_pid;
- uint32_t usage, anon_usage, max_mem;
+ uint32_t usage, max_mem;
uint64_t dummy_efd;
char *cg_dir = (char *)data;
struct memory_limit_event *mle;
goto remove_mle;
}
- anon_usage = mem_stat->value[CGROUP_MEMORY_STAT_RSS] +
+/* anon_usage = mem_stat->value[CGROUP_MEMORY_STAT_RSS] +
mem_stat->value[CGROUP_MEMORY_STAT_SWAP];
if (anon_usage < mle->threshold) {
_D("[DEBUG] (%s) cgroup escaped low memory status. usage(%d), anon usage (%d), threshold(%d)",
cg_dir, usage, anon_usage, mle->threshold);
return true;
- }
+ }*/
switch (mle->action) {
case PROC_ACTION_BROADCAST:
}
safe_kill(main_pid, SIGTERM);
- if (mle->sigterm_timer == NULL) {
+ if (mle->pid == -1) {
mle->pid = main_pid;
g_timeout_add_seconds(2, liveness_check_cb, mle);
}
+
break;
default:
_E("[DEBUG] Unkown action of memory threshold");
return false;
}
+static void set_limit_in_bytes(const char *dir, unsigned int limit)
+{
+ int error;
+ unsigned int prev;
+
+ error = cgroup_read_node_uint32(dir, MEMCG_LIMIT_BYTE, &prev);
+ if (error) {
+ _E("[DEBUG] Failed to get %s from %s", MEMCG_LIMIT_BYTE, dir);
+ return;
+ }
+
+ if (prev > (limit * 1.2)) {
+ cgroup_write_node_uint32(dir, MEMCG_LIMIT_BYTE, (limit * 1.2));
+ cgroup_write_node_uint32(dir, MEMCG_SWAP_LIMIT_BYTE, (limit * 1.2));
+ }
+ else {
+ cgroup_write_node_uint32(dir, MEMCG_SWAP_LIMIT_BYTE, (limit * 1.2));
+ cgroup_write_node_uint32(dir, MEMCG_LIMIT_BYTE, (limit * 1.2));
+ }
+}
+
int lowmem_reassign_limit(const char *dir,
unsigned int limit, enum proc_action action)
{
int fd;
int error;
- unsigned int prev;
+ unsigned int poo;
fd_handler_h fdh = NULL;
gpointer hash_entry;
struct memory_limit_event *mle = NULL;
}
}
- error = cgroup_read_node_uint32(dir, MEMCG_LIMIT_BYTE, &prev);
+ error = fread_uint("/proc/sys/vm/panic_on_oom", &poo);
if (error) {
- _E("[DEBUG] Failed to get %s from %s", MEMCG_LIMIT_BYTE, dir);
+ _E("[DEBUG] Failed to get %s from %s", "/proc/sys/vm/panic_on_oom", dir);
return RESOURCED_ERROR_FAIL;
}
- if (prev > (limit * 1.2)) {
- cgroup_write_node_uint32(dir, MEMCG_LIMIT_BYTE, (limit * 1.2));
- cgroup_write_node_uint32(dir, MEMCG_SWAP_LIMIT_BYTE, (limit * 1.2));
+ /* If panic_on_oom is true (> 1), oom should be disabled */
+ if (poo != 0) {
+ _I("%s's value is %d. That is, kernel panic will be inevitable, when oom happens", "proc/sys/vm/panic_on_oom", poo);
+ error = cgroup_write_node_uint32(dir, MEMCG_OOM_CONTROL, 1);
+ if (!error)
+ set_limit_in_bytes(dir, limit);
}
else {
- cgroup_write_node_uint32(dir, MEMCG_SWAP_LIMIT_BYTE, (limit * 1.2));
- cgroup_write_node_uint32(dir, MEMCG_LIMIT_BYTE, (limit * 1.2));
+ set_limit_in_bytes(dir, limit);
}
snprintf(buf, sizeof(buf), "%d", limit);
mle->action = action;
mle->threshold = limit;
mle->pid = -1;
- mle->sigterm_timer = 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,
return;
}
- lowmem_reassign_limit(path, limit, action);
+ result = lowmem_reassign_limit(path, limit, action);
+ if (result < 0) {
+ _W("Failed to reassign limit for %s", path);
+ return;
+ }
result = cgroup_write_node_uint32(path, MEMCG_MOVE_CHARGE, 3U);
if (result < 0)