Skip to content

Commit 9f1eb38

Browse files
osalvadorvilardagatorvalds
authored andcommitted
mm, kmemleak: little optimization while scanning
kmemleak_scan() goes through all online nodes and tries to scan all used pages. We can do better and use pfn_to_online_page(), so in case we have CONFIG_MEMORY_HOTPLUG, offlined pages will be skiped automatically. For boxes where CONFIG_MEMORY_HOTPLUG is not present, pfn_to_online_page() will fallback to pfn_valid(). Another little optimization is to check if the page belongs to the node we are currently checking, so in case we have nodes interleaved we will not check the same pfn multiple times. I ran some tests: Add some memory to node1 and node2 making it interleaved: (qemu) object_add memory-backend-ram,id=ram0,size=1G (qemu) device_add pc-dimm,id=dimm0,memdev=ram0,node=1 (qemu) object_add memory-backend-ram,id=ram1,size=1G (qemu) device_add pc-dimm,id=dimm1,memdev=ram1,node=2 (qemu) object_add memory-backend-ram,id=ram2,size=1G (qemu) device_add pc-dimm,id=dimm2,memdev=ram2,node=1 Then, we offline that memory: # for i in {32..39} ; do echo "offline" > /sys/devices/system/node/node1/memory$i/state;done # for i in {48..55} ; do echo "offline" > /sys/devices/system/node/node1/memory$i/state;don # for i in {40..47} ; do echo "offline" > /sys/devices/system/node/node2/memory$i/state;done And we run kmemleak_scan: # echo "scan" > /sys/kernel/debug/kmemleak before the patch: kmemleak: time spend: 41596 us after the patch: kmemleak: time spend: 34899 us [akpm@linux-foundation.org: remove stray newline, per Oscar] Link: http://lkml.kernel.org/r/20181206131918.25099-1-osalvador@suse.de Signed-off-by: Oscar Salvador <osalvador@suse.de> Reviewed-by: Wei Yang <richard.weiyang@gmail.com> Suggested-by: Michal Hocko <mhocko@suse.com> Acked-by: Catalin Marinas <catalin.marinas@arm.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 8e2d434 commit 9f1eb38

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

mm/kmemleak.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1547,11 +1547,14 @@ static void kmemleak_scan(void)
15471547
unsigned long pfn;
15481548

15491549
for (pfn = start_pfn; pfn < end_pfn; pfn++) {
1550-
struct page *page;
1550+
struct page *page = pfn_to_online_page(pfn);
15511551

1552-
if (!pfn_valid(pfn))
1552+
if (!page)
1553+
continue;
1554+
1555+
/* only scan pages belonging to this node */
1556+
if (page_to_nid(page) != i)
15531557
continue;
1554-
page = pfn_to_page(pfn);
15551558
/* only scan if page is in use */
15561559
if (page_count(page) == 0)
15571560
continue;

0 commit comments

Comments
 (0)