2015-08-03 08:26:47

by Wang, Biao

[permalink] [raw]
Subject: [PATCH V3] staging: android: lowmemorykiller: imporve lmk to avoid deadlock issue

Consider the following case:
Task A trigger lmk with a lock held, while task B try to get this lock, but unfortunately B is the very culprit task lmk select to kill. Then B will never be killed, and A will forever select B to kill.
Such dead lock will trigger softlock up issue.

This patch try to pick the next task to break this loop.

Signed-off-by: Wang Biao <[email protected]>
Reviewed-by: Zhang Di <[email protected]>
---
drivers/staging/android/lowmemorykiller.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/android/lowmemorykiller.c b/drivers/staging/android/lowmemorykiller.c
index feafa17..23d9832 100644
--- a/drivers/staging/android/lowmemorykiller.c
+++ b/drivers/staging/android/lowmemorykiller.c
@@ -127,9 +127,10 @@ static unsigned long lowmem_scan(struct shrinker *s, struct shrink_control *sc)
if (!p)
continue;

- if (test_tsk_thread_flag(p, TIF_MEMDIE) &&
- time_before_eq(jiffies, lowmem_deathpending_timeout)) {
+ if (test_tsk_thread_flag(p, TIF_MEMDIE)) {
task_unlock(p);
+ if (time_after(jiffies, lowmem_deathpending_timeout))
+ continue;
rcu_read_unlock();
return 0;
}
--
1.7.9.5


2015-08-05 18:50:20

by Greg Kroah-Hartman

[permalink] [raw]
Subject: Re: [PATCH V3] staging: android: lowmemorykiller: imporve lmk to avoid deadlock issue

On Mon, Aug 03, 2015 at 08:26:40AM +0000, Wang, Biao wrote:
> Consider the following case:
> Task A trigger lmk with a lock held, while task B try to get this lock, but unfortunately B is the very culprit task lmk select to kill. Then B will never be killed, and A will forever select B to kill.
> Such dead lock will trigger softlock up issue.
>
> This patch try to pick the next task to break this loop.
>
> Signed-off-by: Wang Biao <[email protected]>
> Reviewed-by: Zhang Di <[email protected]>
> ---
> drivers/staging/android/lowmemorykiller.c | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)

Please address Dave's review comments, I'll not take this as-is, sorry.

greg k-h