Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp172655imu; Thu, 6 Dec 2018 22:08:55 -0800 (PST) X-Google-Smtp-Source: AFSGD/VNmYHuPviL5a0ew6LAfWQY7eTxfkeRYqJtWmtwpq0J4aKnTDHdGDoLF5cpJs8pxWAZGwgR X-Received: by 2002:a62:345:: with SMTP id 66mr973720pfd.189.1544162935334; Thu, 06 Dec 2018 22:08:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544162935; cv=none; d=google.com; s=arc-20160816; b=oG1KrQq35wdK4qXSh4naYhm+76A1DCTVV4bKDNjNaaMpI7JuI7caANVe5LhYpklLNv RJh0pshC6F4oHQgoTIy/wkas5+tqqdnMbvGOK791e1Y2fkh9Oxx+5EEBjDUOwwF7W3+b w8QXF/ov6Ic/d3lAPs2jd9BOWZ8BGfTNE4XZLSwHzpSHv9zhyYD5kMGhmOjI13WySirl uljdOSNT645un3IevyMtfjZdWhovChZHnhPG3gG8X2qiMmEn0xJ3X1QOzPr3SjK2VVZI Rif5WtqykUu0JFmnawZjFkUN6HKfx04XHAbFIqrmaUx59SZ8MA4m8yJCKGALjexArBIk aJRQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:date:cc:to:from:subject:message-id; bh=Wm+eC2ipAm7EbgiOaJOruEiTdy2ViYpgxQrDAlxBF04=; b=I/dqQfL0dPa8pNT0u9Z5mkkdXjrOi0rv3jcsR0/SYFlQnA6Ne0RHQixKWtTfRIHB9V +O3/w1ZhpAboBuL+4EkmwoOqF1JooNGZ2KvGbeA1d/efddEkpTT3vj4tW+ppCnKBE5mw 0fUHqkd0e7bgdE41qDZMMYpVe1K26DaT4L7jpja2RrI2yAbHbivpLt8dQHZQLu6o5jeB oCfw4VtueggbGJAXK3CHHJV4P0kYEHY5JQulEQA5oFBg6gIhPExB2lgtU918B2dn9V9/ mxzHCTOeumTPzRCgBPgslHON7uUIOMQEhsdJJfbH1VmO+yHdFv+WRfNjOKreglRyzMwD IOdw== 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 f65si2360887pfb.194.2018.12.06.22.08.39; Thu, 06 Dec 2018 22:08:55 -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 S1725996AbeLGGG0 (ORCPT + 99 others); Fri, 7 Dec 2018 01:06:26 -0500 Received: from mx2.suse.de ([195.135.220.15]:54226 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725950AbeLGGGZ (ORCPT ); Fri, 7 Dec 2018 01:06:25 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 6F3E3AF8C; Fri, 7 Dec 2018 06:06:23 +0000 (UTC) Message-ID: <1544162765.3008.1.camel@suse.de> Subject: Re: [PATCH] mm, kmemleak: Little optimization while scanning From: Oscar Salvador To: akpm@linux-foundation.org Cc: catalin.marinas@arm.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, mhocko@suse.com Date: Fri, 07 Dec 2018 07:06:05 +0100 In-Reply-To: <20181206131918.25099-1-osalvador@suse.de> References: <20181206131918.25099-1-osalvador@suse.de> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.26.1 Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org I just realized I forgot to add that this was suggested by Michal. Sorry, I was a but rushy. On Thu, 2018-12-06 at 14:19 +0100, Oscar Salvador wrote: > 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 Suggested-by: Michal Hocko > --- > 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; -- Oscar Salvador SUSE L3