Commit 95670001 authored by Anton Vorontsov's avatar Anton Vorontsov Committed by Greg Kroah-Hartman

staging: android/lowmemorykiller: Better mm handling

LMK should not directly check for task->mm. The reason is that the
process' threads may exit or detach its mm via use_mm(), but other
threads may still have a valid mm. To catch this we use
find_lock_task_mm(), which walks up all threads and returns an
appropriate task (with lock held).
Suggested-by: default avatarOleg Nesterov <oleg@redhat.com>
Reviewed-by: default avatarOleg Nesterov <oleg@redhat.com>
Signed-off-by: default avatarAnton Vorontsov <anton.vorontsov@linaro.org>
Acked-by: default avatarKOSAKI Motohiro <kosaki.motohiro@gmail.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 294b2711
...@@ -82,7 +82,7 @@ task_notify_func(struct notifier_block *self, unsigned long val, void *data) ...@@ -82,7 +82,7 @@ task_notify_func(struct notifier_block *self, unsigned long val, void *data)
static int lowmem_shrink(struct shrinker *s, struct shrink_control *sc) static int lowmem_shrink(struct shrinker *s, struct shrink_control *sc)
{ {
struct task_struct *p; struct task_struct *tsk;
struct task_struct *selected = NULL; struct task_struct *selected = NULL;
int rem = 0; int rem = 0;
int tasksize; int tasksize;
...@@ -134,15 +134,17 @@ static int lowmem_shrink(struct shrinker *s, struct shrink_control *sc) ...@@ -134,15 +134,17 @@ static int lowmem_shrink(struct shrinker *s, struct shrink_control *sc)
selected_oom_adj = min_adj; selected_oom_adj = min_adj;
rcu_read_lock(); rcu_read_lock();
for_each_process(p) { for_each_process(tsk) {
struct mm_struct *mm; struct task_struct *p;
struct signal_struct *sig; struct signal_struct *sig;
int oom_adj; int oom_adj;
task_lock(p); p = find_lock_task_mm(tsk);
mm = p->mm; if (!p)
continue;
sig = p->signal; sig = p->signal;
if (!mm || !sig) { if (!sig) {
task_unlock(p); task_unlock(p);
continue; continue;
} }
...@@ -151,7 +153,7 @@ static int lowmem_shrink(struct shrinker *s, struct shrink_control *sc) ...@@ -151,7 +153,7 @@ static int lowmem_shrink(struct shrinker *s, struct shrink_control *sc)
task_unlock(p); task_unlock(p);
continue; continue;
} }
tasksize = get_mm_rss(mm); tasksize = get_mm_rss(p->mm);
task_unlock(p); task_unlock(p);
if (tasksize <= 0) if (tasksize <= 0)
continue; continue;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment