mm/thp: Do not wait for lock_page() in deferred_split_scan()
Subsystems (2)
PATCH 1/1 mm/thp: Do not wait for lock_page() in deferred_split_scan()
deferred_split_scan() gets called from reclaim path. Waiting for page lock may lead to deadlock there.
Replace lock_page() with trylock_page() and skip the page if we failed to lock it. We will get to the page on the next scan.
--- mm/huge_memory.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
mm/huge_memory.c +3 -1
@@ -2783,11 +2783,13 @@ static unsigned long deferred_split_scan(struct shrinker *shrink,list_for_each_safe (pos, next, &list) { page = list_entry((void *)pos, struct page, mapping); -lock_page (page); +if (!trylock_page (page)) + goto next;/* split_huge_page() removes page from list on success */ if (!split_huge_page (page)) split++;unlock_page (page); +next:put_page (page); }
Signature · 1 line
2.16.1
Quoted 6 lines · Kirill A. Shutemov
deferred_split_scan()gets called from reclaim path. Waiting for page lock may lead to deadlock there.Replace
lock_page()withtrylock_page()and skip the page if we failed to lock it. We will get to the page on the next scan.
and maybe even Cc: stable as this can lead to deadlocks AFAICS.
Btw. other THP shrinker does suffer from the same problem and a deadlock has been reported[1]. Thanks for Tetsuo to point that out [2].
[1] http://lkml.kernel.org/r/[email protected]
[2] http://lkml.kernel.org/r/[email protected]
Quoted 1 line
Signed-off-by Kirill A. Shutemov <[email protected]>
Anyway feel free to add
to this patch but a deeper audit is due I suspect
Quoted 25 lines
--- mm/huge_memory.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)mm/huge_memory.c +3
-1@@ -2783,11 +2783,13 @@ static unsigned long deferred_split_scan(struct shrinker *shrink,list_for_each_safe (pos, next, &list) { page = list_entry((void *)pos, struct page, mapping); -lock_page (page); +if (!trylock_page (page)) + goto next;/* split_huge_page() removes page from list on success */ if (!split_huge_page (page)) split++;unlock_page (page); +next:put_page (page); }Signature · 1 line
2.16.1
Signature · 2 lines
Michal Hocko SUSE Labs