From patchwork Mon Jul 5 08:55:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?6raM7Jik7ZuI?= X-Patchwork-Id: 12358543 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-20.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B111CC07E9A for ; Mon, 5 Jul 2021 08:59:35 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 55A0861260 for ; Mon, 5 Jul 2021 08:59:35 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 55A0861260 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=samsung.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 0AB926B006C; Mon, 5 Jul 2021 04:59:35 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 00D336B0073; Mon, 5 Jul 2021 04:59:34 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DA5246B0072; Mon, 5 Jul 2021 04:59:34 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0033.hostedemail.com [216.40.44.33]) by kanga.kvack.org (Postfix) with ESMTP id A01AC6B006C for ; Mon, 5 Jul 2021 04:59:34 -0400 (EDT) Received: from smtpin39.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 2446321962 for ; Mon, 5 Jul 2021 08:59:34 +0000 (UTC) X-FDA: 78327935868.39.DAB5618 Received: from mailout1.samsung.com (mailout1.samsung.com [203.254.224.24]) by imf18.hostedemail.com (Postfix) with ESMTP id 5ECFF4002093 for ; Mon, 5 Jul 2021 08:59:33 +0000 (UTC) Received: from epcas1p4.samsung.com (unknown [182.195.41.48]) by mailout1.samsung.com (KnoxPortal) with ESMTP id 20210705085920epoutp01ee90aa546aff1184b07218e30e88ea0c~O2WkV3BM52713527135epoutp01q for ; Mon, 5 Jul 2021 08:59:20 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.samsung.com 20210705085920epoutp01ee90aa546aff1184b07218e30e88ea0c~O2WkV3BM52713527135epoutp01q DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1625475560; bh=Nu7PfJjCtWVRTW61Q4wznKtwiU60A+jrReXpZWdnrew=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Tb74QFL0PpEdef9oGX2mRQXWUeZVVIxFhvUTwSkkFy8rovlklnRkXcBgkMtPgM4Dq 5kRBhq8sobSGAGrcom1hiJv9Ufv3PKgXF7zDWT1Ua84fjfHICm3bHQCHKn8u8Sr5xF IvfYDSj8fJJTvIGqrVHtrXMFuLI4QpGy4lFle81Q= Received: from epsnrtp1.localdomain (unknown [182.195.42.162]) by epcas1p3.samsung.com (KnoxPortal) with ESMTP id 20210705085920epcas1p3c5bd47189ebc75d43ceb42bb52964cf5~O2WkDHkHL0462004620epcas1p3z; Mon, 5 Jul 2021 08:59:20 +0000 (GMT) Received: from epsmges1p1.samsung.com (unknown [182.195.40.160]) by epsnrtp1.localdomain (Postfix) with ESMTP id 4GJKPM36wCz4x9Q1; Mon, 5 Jul 2021 08:59:19 +0000 (GMT) Received: from epcas1p4.samsung.com ( [182.195.41.48]) by epsmges1p1.samsung.com (Symantec Messaging Gateway) with SMTP id 99.DA.09952.6E9C2E06; Mon, 5 Jul 2021 17:59:18 +0900 (KST) Received: from epsmtrp1.samsung.com (unknown [182.195.40.13]) by epcas1p3.samsung.com (KnoxPortal) with ESMTPA id 20210705085918epcas1p3fdaf2bc0de2f1017c3057aeb6e8c82a7~O2Wh-QiQU0407404074epcas1p3z; Mon, 5 Jul 2021 08:59:18 +0000 (GMT) Received: from epsmgms1p1new.samsung.com (unknown [182.195.42.41]) by epsmtrp1.samsung.com (KnoxPortal) with ESMTP id 20210705085918epsmtrp1e6e6368dc4bde7f82e981771bb7d74ef~O2Wh_is8F0607106071epsmtrp1D; Mon, 5 Jul 2021 08:59:18 +0000 (GMT) X-AuditID: b6c32a35-447ff700000026e0-10-60e2c9e67810 Received: from epsmtip2.samsung.com ( [182.195.34.31]) by epsmgms1p1new.samsung.com (Symantec Messaging Gateway) with SMTP id DC.C4.08394.6E9C2E06; Mon, 5 Jul 2021 17:59:18 +0900 (KST) Received: from localhost.localdomain (unknown [10.253.98.78]) by epsmtip2.samsung.com (KnoxPortal) with ESMTPA id 20210705085918epsmtip20004ee30010958c1ff2d1d456c582996~O2WhyS4X_2653026530epsmtip2k; Mon, 5 Jul 2021 08:59:18 +0000 (GMT) From: Ohhoon Kwon To: david@redhat.com, ohoono.kwon@samsung.com, akpm@linux-foundation.org, mhocko@suse.com Cc: bhe@redhat.com, rppt@linux.ibm.com, ohkwon1043@gmail.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 2/3] mm: sparse: pass section_nr to find_memory_block Date: Mon, 5 Jul 2021 17:55:37 +0900 Message-Id: <20210705085538.14557-3-ohoono.kwon@samsung.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210705085538.14557-1-ohoono.kwon@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrIKsWRmVeS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3z8juUuHbykZcpsJJ7atN6+OrBcpsvuxp+aD+fTb30ltKLMUZiYZazEXFiQCWUt6u vAIAAA== X-CMS-MailID: 20210705085918epcas1p3fdaf2bc0de2f1017c3057aeb6e8c82a7 X-Msg-Generator: CA X-Sendblock-Type: SVC_REQ_APPROVE CMS-TYPE: 101P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20210705085918epcas1p3fdaf2bc0de2f1017c3057aeb6e8c82a7 References: <20210705085538.14557-1-ohoono.kwon@samsung.com> Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=samsung.com header.s=mail20170921 header.b=Tb74QFL0; spf=pass (imf18.hostedemail.com: domain of ohoono.kwon@samsung.com designates 203.254.224.24 as permitted sender) smtp.mailfrom=ohoono.kwon@samsung.com; dmarc=pass (policy=none) header.from=samsung.com X-Stat-Signature: wjnigun1qju8d4wqb5w8tczkzfjoyiez X-Rspamd-Queue-Id: 5ECFF4002093 X-Rspamd-Server: rspam06 X-HE-Tag: 1625475573-356456 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: With CONFIG_SPARSEMEM_EXTREME enabled, __section_nr() which converts mem_section to section_nr could be costly since it iterates all section roots to check if the given mem_section is in its range. On the other hand, __nr_to_section() which converts section_nr to mem_section can be done in O(1). Let's pass section_nr instead of mem_section ptr to find_memory_block() in order to reduce needless iterations. Signed-off-by: Ohhoon Kwon Acked-by: Michal Hocko Acked-by: Mike Rapoport Reviewed-by: David Hildenbrand --- arch/powerpc/platforms/pseries/hotplug-memory.c | 4 +--- drivers/base/memory.c | 4 ++-- include/linux/memory.h | 2 +- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/arch/powerpc/platforms/pseries/hotplug-memory.c b/arch/powerpc/platforms/pseries/hotplug-memory.c index 377d852f5a9a..d4f28ee4d5dc 100644 --- a/arch/powerpc/platforms/pseries/hotplug-memory.c +++ b/arch/powerpc/platforms/pseries/hotplug-memory.c @@ -211,13 +211,11 @@ static int update_lmb_associativity_index(struct drmem_lmb *lmb) static struct memory_block *lmb_to_memblock(struct drmem_lmb *lmb) { unsigned long section_nr; - struct mem_section *mem_sect; struct memory_block *mem_block; section_nr = pfn_to_section_nr(PFN_DOWN(lmb->base_addr)); - mem_sect = __nr_to_section(section_nr); - mem_block = find_memory_block(mem_sect); + mem_block = find_memory_block(section_nr); return mem_block; } diff --git a/drivers/base/memory.c b/drivers/base/memory.c index d5ffaab3cb61..e31598955cc4 100644 --- a/drivers/base/memory.c +++ b/drivers/base/memory.c @@ -578,9 +578,9 @@ static struct memory_block *find_memory_block_by_id(unsigned long block_id) /* * Called under device_hotplug_lock. */ -struct memory_block *find_memory_block(struct mem_section *section) +struct memory_block *find_memory_block(unsigned long section_nr) { - unsigned long block_id = memory_block_id(__section_nr(section)); + unsigned long block_id = memory_block_id(section_nr); return find_memory_block_by_id(block_id); } diff --git a/include/linux/memory.h b/include/linux/memory.h index 97e92e8b556a..d9a0b61cd432 100644 --- a/include/linux/memory.h +++ b/include/linux/memory.h @@ -90,7 +90,7 @@ int create_memory_block_devices(unsigned long start, unsigned long size, void remove_memory_block_devices(unsigned long start, unsigned long size); extern void memory_dev_init(void); extern int memory_notify(unsigned long val, void *v); -extern struct memory_block *find_memory_block(struct mem_section *); +extern struct memory_block *find_memory_block(unsigned long section_nr); typedef int (*walk_memory_blocks_func_t)(struct memory_block *, void *); extern int walk_memory_blocks(unsigned long start, unsigned long size, void *arg, walk_memory_blocks_func_t func);