From mboxrd@z Thu Jan 1 00:00:00 1970 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=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham 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 B6B8DC11F68 for ; Fri, 2 Jul 2021 12:17:33 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 4959D61427 for ; Fri, 2 Jul 2021 12:17:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4959D61427 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=suse.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 985626B0011; Fri, 2 Jul 2021 08:17:32 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 90E8B6B0036; Fri, 2 Jul 2021 08:17:32 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7874F6B005D; Fri, 2 Jul 2021 08:17:32 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0196.hostedemail.com [216.40.44.196]) by kanga.kvack.org (Postfix) with ESMTP id 4B7516B0011 for ; Fri, 2 Jul 2021 08:17:32 -0400 (EDT) Received: from smtpin10.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id D0F981804DF99 for ; Fri, 2 Jul 2021 12:17:31 +0000 (UTC) X-FDA: 78317548302.10.646B339 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by imf14.hostedemail.com (Postfix) with ESMTP id 55B6A6001AAF for ; Fri, 2 Jul 2021 12:17:31 +0000 (UTC) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id 6D10422983; Fri, 2 Jul 2021 12:17:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1625228250; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=AVHSMXF0Qe6z5X1aYrWSnwSZI6rHsSpkp/txd0qcOcc=; b=JDsyaSelsP4XpNfIqBErJjN0khgCMBMHw/VEE0FpP3myQtmjEEuYRvWDmEjHUVV3FbGgic kBQJAi//EsEKblNipEulzeWrOHmja7sbTd0ph7SXrB+rDP6vNIBCw+OqRm13VhJoWmMhhl RQGlA1UDPPMiMPFxMOMbXbxb0m4V9Cg= Received: from suse.cz (unknown [10.100.201.86]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id 2FCB1A3B87; Fri, 2 Jul 2021 12:17:30 +0000 (UTC) Date: Fri, 2 Jul 2021 14:17:28 +0200 From: Michal Hocko To: Ohhoon Kwon Cc: david@redhat.com, akpm@linux-foundation.org, bhe@redhat.com, rppt@linux.ibm.com, ohkwon1043@gmail.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 2/3] mm: sparse: pass section_nr to find_memory_block Message-ID: References: <20210702094132.6276-1-ohoono.kwon@samsung.com> <20210702094132.6276-3-ohoono.kwon@samsung.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210702094132.6276-3-ohoono.kwon@samsung.com> Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=suse.com header.s=susede1 header.b=JDsyaSel; spf=pass (imf14.hostedemail.com: domain of mhocko@suse.com designates 195.135.220.28 as permitted sender) smtp.mailfrom=mhocko@suse.com; dmarc=pass (policy=quarantine) header.from=suse.com X-Stat-Signature: mqsgfebd6nug6a3xymzdstgnmm49cazs X-Rspamd-Queue-Id: 55B6A6001AAF X-Rspamd-Server: rspam06 X-HE-Tag: 1625228251-171403 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: On Fri 02-07-21 18:41:31, Ohhoon Kwon wrote: > 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. Yeah, it seems like the only existing user (maybe there used to be more in the past - haven't checked) is just doing pointless translation to comply with the API that doesn't fit it. Just to undo all that work in find_memory_block Nice cleanup and potentially even a performance improvement! > Signed-off-by: Ohhoon Kwon Acked-by: Michal Hocko > --- > 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 8377f1f7c78e..905790092e0e 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); > -- > 2.17.1 -- Michal Hocko SUSE Labs