Skip to content

Commit e68d343

Browse files
Waiman-Longakpm00
authored andcommitted
mm/kmemleak: move up cond_resched() call in page scanning loop
Commit bde5f6b ("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. Link: https://lkml.kernel.org/r/20230825164947.1317981-1-longman@redhat.com Fixes: bde5f6b ("kmemleak: add scheduling point to kmemleak_scan()") Signed-off-by: Waiman Long <longman@redhat.com> Cc: Catalin Marinas <catalin.marinas@arm.com> Cc: Yisheng Xie <xieyisheng1@huawei.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent f945116 commit e68d343

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

mm/kmemleak.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1584,6 +1584,9 @@ static void kmemleak_scan(void)
15841584
for (pfn = start_pfn; pfn < end_pfn; pfn++) {
15851585
struct page *page = pfn_to_online_page(pfn);
15861586

1587+
if (!(pfn & 63))
1588+
cond_resched();
1589+
15871590
if (!page)
15881591
continue;
15891592

@@ -1594,8 +1597,6 @@ static void kmemleak_scan(void)
15941597
if (page_count(page) == 0)
15951598
continue;
15961599
scan_block(page, page + 1, NULL);
1597-
if (!(pfn & 63))
1598-
cond_resched();
15991600
}
16001601
}
16011602
put_online_mems();

0 commit comments

Comments
 (0)