OSDN Git Service

lowmemorykiller: fix scan_mutex contention
authorPrakash Gupta <guptap@codeaurora.org>
Tue, 18 Apr 2017 02:02:20 +0000 (07:32 +0530)
committerPrakash Gupta <guptap@codeaurora.org>
Tue, 18 Apr 2017 02:02:31 +0000 (07:32 +0530)
commit1b8bb0da0b2dad2cc884580d1b38aab4cca78532
treef86b0b7f0f9bff5a091ca6566d01edbd1e483755
parentd5311c5d4300455a7597b7edae08caba84c0a7f8
lowmemorykiller: fix scan_mutex contention

A livelock can be created in the system by lowmemorykiller trying to kill
the same task again and again.  Below is the livelock condition.

P0 -> binder_main_lock(W)
P1 -> binder_main_lock(T)-> mmap_sem(W)
P2 -> mmap_sem(T) -> lowmem_scan::scan_mutex(W)
P3 -> lowmem_scan::scan_mutex(T) -> send SIGKILL P0

Here multiple tasks are contending on scan_mutex, and binder_main_lock.
Change lowmem_scan mutex_lock with mutex_trylock, so in case of lowmem_scan
lock contention, task will be allowed to reclaim from other shrinkers. This
will also maintain the serialization of lowmemorykiller trigger.

If a task is pending MEMDIE'ing, remove sleep before falling back on other
shrinkers.

If the task selected to be killed is MEMDIE'ing and in un-interruptible
sleep state, do not repeat kill but fallback on other shrinkers without any
delay.

Change-Id: I12131622f7fa7b422c6d5d09f782af848300e412
Signed-off-by: Prakash Gupta <guptap@codeaurora.org>
drivers/staging/android/lowmemorykiller.c