Skip to contentSkip to conversation

mm/thp: Do not wait for lock_page() in deferred_split_scan()

PATCH Applied Kirill A. Shutemov 2 participants 2 messages Mar 15, 2018

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

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
index 87ab9b8f56b5..529cf36b7edb 100644
@@ -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
Acked-by on v1 1/1
#1 lore raw
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() with trylock_page() and skip the page if we failed to lock it. We will get to the page on the next scan.

Fixes 9a982250f773 ("thp: introduce deferred_split_huge_page()")

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

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
index 87ab9b8f56b5..529cf36b7edb 100644
@@ -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