aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnton Vorontsov <anton.vorontsov@linaro.org>2012-02-06 20:29:47 +0400
committerZiyan <jaraidaniel@gmail.com>2015-10-25 16:26:28 +0100
commit7a7003ad727b25b877bf63d25e5c742d035a8cac (patch)
tree2574ca2a1fbfd65a550f1697e753511129cc7f55
parent313dc7dfdc96f455a9bddab8a4ac0b69cdccf082 (diff)
downloadkernel_samsung_espresso10-7a7003ad727b25b877bf63d25e5c742d035a8cac.zip
kernel_samsung_espresso10-7a7003ad727b25b877bf63d25e5c742d035a8cac.tar.gz
kernel_samsung_espresso10-7a7003ad727b25b877bf63d25e5c742d035a8cac.tar.bz2
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: Oleg Nesterov <oleg@redhat.com> Reviewed-by: Oleg Nesterov <oleg@redhat.com> Signed-off-by: Anton Vorontsov <anton.vorontsov@linaro.org> Acked-by: KOSAKI Motohiro <kosaki.motohiro@gmail.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r--drivers/staging/android/lowmemorykiller.c16
1 files changed, 9 insertions, 7 deletions
diff --git a/drivers/staging/android/lowmemorykiller.c b/drivers/staging/android/lowmemorykiller.c
index dca18aa..cfc76b6 100644
--- a/drivers/staging/android/lowmemorykiller.c
+++ b/drivers/staging/android/lowmemorykiller.c
@@ -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)
{
- struct task_struct *p;
+ struct task_struct *tsk;
struct task_struct *selected = NULL;
int rem = 0;
int tasksize;
@@ -133,15 +133,17 @@ static int lowmem_shrink(struct shrinker *s, struct shrink_control *sc)
selected_oom_adj = min_adj;
rcu_read_lock();
- for_each_process(p) {
- struct mm_struct *mm;
+ for_each_process(tsk) {
+ struct task_struct *p;
struct signal_struct *sig;
int oom_adj;
- task_lock(p);
- mm = p->mm;
+ p = find_lock_task_mm(tsk);
+ if (!p)
+ continue;
+
sig = p->signal;
- if (!mm || !sig) {
+ if (!sig) {
task_unlock(p);
continue;
}
@@ -150,7 +152,7 @@ static int lowmem_shrink(struct shrinker *s, struct shrink_control *sc)
task_unlock(p);
continue;
}
- tasksize = get_mm_rss(mm);
+ tasksize = get_mm_rss(p->mm);
task_unlock(p);
if (tasksize <= 0)
continue;