[PATCH 4/4] staging: android: lowmemorykiller: take per file badness into account

Christian König deathsimple at vodafone.de
Fri Sep 4 05:53:33 PDT 2015


From: Christian König <christian.koenig at amd.com>

Try to make better decisions which process to kill based on per
file OOM badness.

Signed-off-by: Christian König <christian.koenig at amd.com>
Reviewed-by: Alex Deucher <alexander.deucher at amd.com>
---
 drivers/staging/android/lowmemorykiller.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/drivers/staging/android/lowmemorykiller.c b/drivers/staging/android/lowmemorykiller.c
index feafa17..baefe8f 100644
--- a/drivers/staging/android/lowmemorykiller.c
+++ b/drivers/staging/android/lowmemorykiller.c
@@ -41,6 +41,7 @@
 #include <linux/rcupdate.h>
 #include <linux/profile.h>
 #include <linux/notifier.h>
+#include <linux/fdtable.h>
 
 static uint32_t lowmem_debug_level = 1;
 static short lowmem_adj[6] = {
@@ -75,6 +76,13 @@ static unsigned long lowmem_count(struct shrinker *s,
 		global_page_state(NR_INACTIVE_FILE);
 }
 
+static int lowmem_file_badness(const void *tasksize, struct file *file, unsigned n)
+{
+	*((int*)tasksize) += atomic_long_read(&file->f_oom_badness);
+
+	return 0;
+}
+
 static unsigned long lowmem_scan(struct shrinker *s, struct shrink_control *sc)
 {
 	struct task_struct *tsk;
@@ -139,6 +147,7 @@ static unsigned long lowmem_scan(struct shrinker *s, struct shrink_control *sc)
 			continue;
 		}
 		tasksize = get_mm_rss(p->mm);
+		iterate_fd(p->files, 0, lowmem_file_badness, &tasksize);
 		task_unlock(p);
 		if (tasksize <= 0)
 			continue;
-- 
1.9.1



More information about the dri-devel mailing list