Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp10689868imu; Thu, 6 Dec 2018 05:21:09 -0800 (PST) X-Google-Smtp-Source: AFSGD/WWlTQxSSMHVwF4nbRui2HcnuUXEiebhSK+hgDFtJYTfUXbjVlPuXllJuWdG4739MDvLCU3 X-Received: by 2002:a17:902:365:: with SMTP id 92mr26814631pld.327.1544102469687; Thu, 06 Dec 2018 05:21:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544102469; cv=none; d=google.com; s=arc-20160816; b=E0DXjif6CDWn4w2W37FBRy0hlfBZOoMpCNfluvwXZKdcqUSx9EJ5ywhs69pALGbQcA zfrl3/oZ9PuQDbuoFQ36oEMJ9uXFC2uQpf+ir9ear9TLUSqZQH2WdBjj3snjsbyCSPE/ ntHJ9jvgtYAc5zb6LdvvyHPwOd0wfgZchylixjyXtM7al+1EdQrHdT2NmOrdDZ69CHlw djZUI2BnKtu8s8/lMdOcVXEOj7usNS2ucvW1sQayHko1VAVaR5bExo3c27fPl8jIpsQy jJ7A7EJWt+KILcqGXrnXlyJ9lbLMfHIEGsJWN+Qq9wQfFW1xDQRqrEmxDwfzTanrLIfk xRRA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from; bh=fjJ3cyqAJDSmFgbmbxw9FFKAxjycJu+Ajrgwmd1JvjE=; b=VXn+WO9n1vYK7n5GDXBt9ft/PJDH4QvH7/XPWwuTwENLZSsSyhf+Fr4/A6uSuFsvrF 0aSRqevi3QjAQb0zeIfy4KF5tCx71+NPEX0WoBQ0ksCkj7L8Ccd+qPkqrwT0aOvf/PC6 nOpp0/OWhRMNNmxird0J+bxnRC81IggcaRWt7dCnDksi5cVLNkBB18hyFOs05Aykzkds PyHRi2SDxdPBzkkf6pfZLDqXqnLLcU6sY22/HMiFE55kLnMmnI2Vg/lADW7V7cdK5qFv l49Bb+CZTb41lTZEzyjf/d6U4sQg8MshXwQ/530fE44cd40FCLe17vLkI2J3A54mrA+5 hw4g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f2si284066plt.101.2018.12.06.05.20.51; Thu, 06 Dec 2018 05:21:09 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729648AbeLFNTg (ORCPT + 99 others); Thu, 6 Dec 2018 08:19:36 -0500 Received: from smtp.nue.novell.com ([195.135.221.5]:52218 "EHLO smtp.nue.novell.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728346AbeLFNTf (ORCPT ); Thu, 6 Dec 2018 08:19:35 -0500 Received: from emea4-mta.ukb.novell.com ([10.120.13.87]) by smtp.nue.novell.com with ESMTP (TLS encrypted); Thu, 06 Dec 2018 14:19:33 +0100 Received: from d104.suse.de (nwb-a10-snat.microfocus.com [10.120.13.202]) by emea4-mta.ukb.novell.com with ESMTP (NOT encrypted); Thu, 06 Dec 2018 13:19:23 +0000 From: Oscar Salvador To: akpm@linux-foundation.org Cc: catalin.marinas@arm.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Oscar Salvador Subject: [PATCH] mm, kmemleak: Little optimization while scanning Date: Thu, 6 Dec 2018 14:19:18 +0100 Message-Id: <20181206131918.25099-1-osalvador@suse.de> X-Mailer: git-send-email 2.13.7 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Signed-off-by: Oscar Salvador --- mm/kmemleak.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/mm/kmemleak.c b/mm/kmemleak.c index 877de4fa0720..5ce1e6a46d77 100644 --- a/mm/kmemleak.c +++ b/mm/kmemleak.c @@ -113,6 +113,7 @@ #include #include + /* * Kmemleak configuration and common defines. */ @@ -1547,11 +1548,14 @@ static void kmemleak_scan(void) unsigned long pfn; for (pfn = start_pfn; pfn < end_pfn; pfn++) { - struct page *page; + struct page *page = pfn_to_online_page(pfn); + + if (!page) + continue; - if (!pfn_valid(pfn)) + /* only scan pages belonging to this node */ + if (page_to_nid(page) != i) continue; - page = pfn_to_page(pfn); /* only scan if page is in use */ if (page_count(page) == 0) continue; -- 2.13.7