Skip to contentSkip to conversation

mm/kmemleak: Move up cond_resched() call in page scanning loop

PATCH Applied Waiman Long 2 participants 2 messages Aug 25, 2023 – Aug 27, 2023

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

PATCH 1/1 mm/kmemleak: Move up cond_resched() call in page scanning loop

Commit bde5f6bc68db ("kmemleak: add scheduling point to kmemleak_scan()") added a cond_resched() call to the struct page scanning loop to prevent soft lockup from happening. However, soft lockup can still happen in that loop in some corner cases when the pages that satisfy the "!(pfn & 63)" check are skipped for some reasons.

Fix this corner case by moving up the cond_resched() check so that it will be called every 64 pages unconditionally.

Fixes bde5f6bc68db ("kmemleak: add scheduling point to kmemleak_scan()")
---
 mm/kmemleak.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
mm/kmemleak.c +3 -2
index a2d34226e3c8..114d8dcdcf70 100644
@@ -1579,6 +1579,9 @@ static void kmemleak_scan(void)
 		for (pfn = start_pfn; pfn < end_pfn; pfn++) {
 			struct page *page = pfn_to_online_page(pfn);
 
+			if (!(pfn & 63))
+				cond_resched();
+
 			if (!page)
 				continue;
 
@@ -1589,8 +1592,6 @@ static void kmemleak_scan(void)
 			if (page_count(page) == 0)
 				continue;
 			scan_block(page, page + 1, NULL);
-			if (!(pfn & 63))
-				cond_resched();
 		}
 	}
 	put_online_mems();
Signature · 1 line
2.31.1
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 11 lines · Waiman Long

Commit bde5f6bc68db ("kmemleak: add scheduling point to kmemleak_scan()") added a cond_resched() call to the struct page scanning loop to prevent soft lockup from happening. However, soft lockup can still happen in that loop in some corner cases when the pages that satisfy the "!(pfn & 63)" check are skipped for some reasons.

Fix this corner case by moving up the cond_resched() check so that it will be called every 64 pages unconditionally.

Fixes bde5f6bc68db ("kmemleak: add scheduling point to kmemleak_scan()")