From patchwork Thu Dec 6 13:19:18 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oscar Salvador X-Patchwork-Id: 10715983 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D781413BF for ; Thu, 6 Dec 2018 13:19:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C78992E7DD for ; Thu, 6 Dec 2018 13:19:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BC2422E846; Thu, 6 Dec 2018 13:19:38 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 387092E7DD for ; Thu, 6 Dec 2018 13:19:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DA1BC6B7A43; Thu, 6 Dec 2018 08:19:36 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id D51846B7A44; Thu, 6 Dec 2018 08:19:36 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C3FDB6B7A45; Thu, 6 Dec 2018 08:19:36 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-ed1-f70.google.com (mail-ed1-f70.google.com [209.85.208.70]) by kanga.kvack.org (Postfix) with ESMTP id 6C5096B7A43 for ; Thu, 6 Dec 2018 08:19:36 -0500 (EST) Received: by mail-ed1-f70.google.com with SMTP id w2so364868edc.13 for ; Thu, 06 Dec 2018 05:19:36 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id; bh=fjJ3cyqAJDSmFgbmbxw9FFKAxjycJu+Ajrgwmd1JvjE=; b=TrNJqdHBkEbdmUHECS44am4ak2bNO1tH8bNhLxhBV/CcOssc4eXHvXSYC6p39jcR7a kLlMvchq7i7FkaDpjyDlM15I0BFISiKZI8DrbXKt+r62ykwhshrMc6eaL3UOEPFtKa28 jOK5Rg+FAbbMTZReF1MAIZv6pBjKM7xvu4EBfE4pgyAsMNz2D1IDoqXWicwQcTtzaysU z8177VJ/JwjO0mAM8N+2xunt9zX9lbYyBLOBb0ArHpytvo+D8cLgRVD7pRpAHmTXiCaz zS8otNZhdMc22A9ug/t3bpcJSiJPfADeqkgft5dOMbdPKJcXtPf5iVT3fc2RbD724v2M KaSA== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of osalvador@suse.de designates 195.135.221.5 as permitted sender) smtp.mailfrom=osalvador@suse.de X-Gm-Message-State: AA+aEWY2Cri7B3x+/EI2avyJ29AnKiBfhbxIm7q9YP5BmQeQBsXXXGWT 9f8SrgpSbpwOLKieOh0Z/jjn9LWsnYDvtU//3pY81D4CO2imXSJXmolMLjwwGLD0c+uv6V7C59D nRYUrOcDDPdjqlkDBweJVQVFDSB0ejTdE4oKxoGkOEH3gAefwxgEsFE17qGn+VYEEFA== X-Received: by 2002:a50:9e43:: with SMTP id z61mr25002638ede.90.1544102375899; Thu, 06 Dec 2018 05:19:35 -0800 (PST) X-Google-Smtp-Source: AFSGD/WkDbC+cDI/X5lcdMsg2wGl19TfdQHjbjxZxJ2FvUYjc1oHnOlVHs/lXz6zJ9ZPfU8pqYfG X-Received: by 2002:a50:9e43:: with SMTP id z61mr25002579ede.90.1544102374563; Thu, 06 Dec 2018 05:19:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544102374; cv=none; d=google.com; s=arc-20160816; b=FpqIBrAWZm5kJC3nwgmJ7GseNqSFr9Fm0Z5SQf4zjr666m8xP93Bj2TZjX2980/N9q A4HHWcSes64KjhRj416o0Y2fleYuyGuCqlgBH+NyeVVKtxRokGaTmMnyb3jgMKktxt00 0VTXNwl5VL0NvjW1KO8aBj1MITrExQ2fylBqyRcVlBbI9T7aD0fDfc+z97r38kZB/KfD NpqEwD6jSHv+XPuXtVtA3GMFcjXlndUqksHueljSZ34/lCpcmaV3CtsCmZfPleziKycy YsF7K62j6ZEQ/nuewuhbv3VR1sRfbJo1lsSmog8pjEr/DhvVJgG81Bol/4Rl3be3tyx3 kSEw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:date:subject:cc:to:from; bh=fjJ3cyqAJDSmFgbmbxw9FFKAxjycJu+Ajrgwmd1JvjE=; b=Q1/VUOQjESx52Gn2Zl0zaLpjGK7FUrP/9mdDTE1qtjQv33gZ1ism1dIHHWElJaoKHE bAMSU/FfF8J3XHKkK1HyWWxUl4Fro3GCVDA8unBW/Ij4AFwMuPhmZOWZtexAW7+UIJch 7z59ESgXt8qwvYEXibeT40yto2dKhqsbewr7Y+uNADDWkWzFXh7kVOSS2TUsyDa8HRUR 9yoobT5SKTslySVpd2Sy0aKUI+1kdr6Fhc9RwS+8MIhCUCNy+IM2H3fHXrcAjiIkLrkq OAaEXlFse5BppSah+ATAtpKoJKRluUPSkoTM5i5U7xtkVW2Qr65RVispUWffUkaSRIBJ 8k/w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of osalvador@suse.de designates 195.135.221.5 as permitted sender) smtp.mailfrom=osalvador@suse.de Received: from smtp.nue.novell.com (smtp.nue.novell.com. [195.135.221.5]) by mx.google.com with ESMTPS id d1si281663edb.435.2018.12.06.05.19.34 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 06 Dec 2018 05:19:34 -0800 (PST) Received-SPF: pass (google.com: domain of osalvador@suse.de designates 195.135.221.5 as permitted sender) client-ip=195.135.221.5; Authentication-Results: mx.google.com; spf=pass (google.com: domain of osalvador@suse.de designates 195.135.221.5 as permitted sender) smtp.mailfrom=osalvador@suse.de 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 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP 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 Reviewed-by: Wei Yang Acked-by: Catalin Marinas --- 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;