kmemleak: add scheduling point to kmemleak_scan()
Subsystems (2)
[email protected]
maintainerPATCH 21/28 kmemleak: add scheduling point to kmemleak_scan()
From: Yisheng Xie <[email protected]>
Subject: kmemleak: add scheduling point to kmemleak_scan()
kmemleak_scan() will scan struct page for each node and it can be really large and resulting in a soft lockup. We have seen a soft lockup when do scan while compile kernel:
[ 220.561051] watchdog: BUG: soft lockup - CPU#53 stuck for 22s! [bash:10287] [...] [ 220.753837] Call Trace: [ 220.756296] kmemleak_scan+0x21a/0x4c0 [ 220.760034] kmemleak_write+0x312/0x350 [ 220.763866] ? do_wp_page+0x147/0x4c0 [ 220.767521] full_proxy_write+0x5a/0xa0 [ 220.771351] __vfs_write+0x33/0x150 [ 220.774833] ? __inode_security_revalidate+0x4c/0x60 [ 220.779782] ? selinux_file_permission+0xda/0x130 [ 220.784479] ? _cond_resched+0x15/0x30 [ 220.788221] vfs_write+0xad/0x1a0 [ 220.791529] SyS_write+0x52/0xc0 [ 220.794758] do_syscall_64+0x61/0x1a0 [ 220.798411] entry_SYSCALL64_slow_path+0x25/0x25
Fix this by adding cond_resched every MAX_SCAN_SIZE.
---
mm/kmemleak.c | 2 ++ 1 file changed, 2 insertions(+)
mm/kmemleak.c renamed from mm/kmemleak.c~kmemleak-add-scheduling-point-to-kmemleak_scan +2 -0
@@ -1523,6 +1523,8 @@ static void kmemleak_scan(void)if (page_count (page) ==0 )continue ;scan_block (page, page +1 ,NULL ); +if (!(pfn % (MAX_SCAN_SIZE /sizeof (*page)))) +cond_resched (); } }put_online_mems ();
_
A message that is not in the archive (sent off-list or not yet received): CA+55aFx2T-mEEqV=Jwy+sZvgiLWCM6E=GVNeFrS9V+K=-KO3fA@mail.gmail.com
Andrew Morton
maintainerQuoted 18 lines · On Thu, 30 Nov 2017 04:10:34 -0800 Linus Torvalds…
Quoted 3 lines · On Wed, Nov 29, 2017 at 4:11 PM, <[email protected]> wrote:
kmemleak_scan()will scan struct page for each node and it can be really large and resulting in a soft lockup...
Review
Quoted 2 lines
(quoted diff) +2
-0+ if (!(pfn % (MAX_SCAN_SIZE / sizeof(*page)))) + cond_resched();I applied this already, but looking at it, doesn't the above cause a completely pointless divide to get the remainder?
It seems like it's a pretty damn arbitrary scheduling point too.
Why isn't it just something like
if (!(pfn & 63)) cond_resched();
Quoted 7 lines
which is also entirely arbitrary, but at least generates ok code?
I guess that depending on config options etc, 'sizeof(struct page)' could be just right to hide this all, but it still just seems silly and pointless to use some arbitrary and possibly expensive modulus operation.
Yup. In fact it's probably more efficient to just do a bare cond_resched() on each pass through the loop.
I did this:
From: Andrew Morton <[email protected]>
Subject: mm/kmemleak.c: make cond_resched() rate-limiting more efficient
bde5f6bc68db5 ("kmemleak: add scheduling point to kmemleak_scan()") tries to rate-limit the frequency of cond_resched() calls, but does it in a way which might incur an expensive division operation in the inner loop. Simplify this.
---
mm/kmemleak.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
mm/kmemleak.c renamed from mm/kmemleak.c~a +1 -1
@@ -1523,7 +1523,7 @@ static void kmemleak_scan(void)if (page_count (page) ==0 )continue ;scan_block (page, page +1 ,NULL ); -if (!(pfn % (MAX_SCAN_SIZE /sizeof (*page)))) +if (!(pfn &63 ))cond_resched (); } }
_