From 16b6099476078feb6da54ef4789f2a0ff569b6db Mon Sep 17 00:00:00 2001 From: Todd Poynor Date: Mon, 16 Sep 2013 19:26:47 -0700 Subject: low memory killer: switch to kernel oom_score_adj interface Use oom_score_adj for setting OOM score adjustment values instead of the older, deprecated oom_adj interface. Change-Id: I5ba7801d4b8971be092b31ae0fd8af8c3001d613 --- lmkd/lmkd.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'lmkd') diff --git a/lmkd/lmkd.c b/lmkd/lmkd.c index 376410b..e489e81 100644 --- a/lmkd/lmkd.c +++ b/lmkd/lmkd.c @@ -75,6 +75,10 @@ static int maxevents; #define OOM_ADJUST_MIN (-16) #define OOM_ADJUST_MAX 15 +/* kernel OOM score values */ +#define OOM_SCORE_ADJ_MIN (-1000) +#define OOM_SCORE_ADJ_MAX 1000 + static int lowmem_adj[MAX_TARGETS]; static int lowmem_minfree[MAX_TARGETS]; static int lowmem_targets_size; @@ -116,6 +120,14 @@ static time_t kill_lasttime; /* PAGE_SIZE / 1024 */ static long page_k; +static int lowmem_oom_adj_to_oom_score_adj(int oom_adj) +{ + if (oom_adj == OOM_ADJUST_MAX) + return OOM_SCORE_ADJ_MAX; + else + return (oom_adj * OOM_SCORE_ADJ_MAX) / -OOM_DISABLE; +} + static struct proc *pid_lookup(int pid) { struct proc *procp; @@ -219,8 +231,8 @@ static void cmd_procprio(int pid, int oomadj) { return; } - snprintf(path, sizeof(path), "/proc/%d/oom_adj", pid); - snprintf(val, sizeof(val), "%d", oomadj); + snprintf(path, sizeof(path), "/proc/%d/oom_score_adj", pid); + snprintf(val, sizeof(val), "%d", lowmem_oom_adj_to_oom_score_adj(oomadj)); writefilestring(path, val); if (use_inkernel_interface) -- cgit v1.1