summaryrefslogtreecommitdiffstats
path: root/lmkd
diff options
context:
space:
mode:
authorTodd Poynor <toddpoynor@google.com>2013-09-16 19:26:47 -0700
committerTodd Poynor <toddpoynor@google.com>2013-09-23 18:32:02 +0000
commit16b6099476078feb6da54ef4789f2a0ff569b6db (patch)
treee07b2666952eb57a654f8082ac5c885353c81855 /lmkd
parentcae02657be05e7f016cb261fc9fffdc96dd1b9cd (diff)
downloadsystem_core-16b6099476078feb6da54ef4789f2a0ff569b6db.zip
system_core-16b6099476078feb6da54ef4789f2a0ff569b6db.tar.gz
system_core-16b6099476078feb6da54ef4789f2a0ff569b6db.tar.bz2
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
Diffstat (limited to 'lmkd')
-rw-r--r--lmkd/lmkd.c16
1 files changed, 14 insertions, 2 deletions
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)