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=-18.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,NICE_REPLY_A, SPF_HELO_NONE,USER_AGENT_SANE_1 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 C63F7C47092 for ; Tue, 1 Jun 2021 08:22:20 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 4F176613AF for ; Tue, 1 Jun 2021 08:22:20 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4F176613AF Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id D788B6B0080; Tue, 1 Jun 2021 04:22:19 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D2CD96B0081; Tue, 1 Jun 2021 04:22:19 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BA2446B0082; Tue, 1 Jun 2021 04:22:19 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0135.hostedemail.com [216.40.44.135]) by kanga.kvack.org (Postfix) with ESMTP id 7FEAF6B0080 for ; Tue, 1 Jun 2021 04:22:19 -0400 (EDT) Received: from smtpin30.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 1411399B3 for ; Tue, 1 Jun 2021 08:22:19 +0000 (UTC) X-FDA: 78204462798.30.C72DE65 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf14.hostedemail.com (Postfix) with ESMTP id 154D1C00CBEE for ; Tue, 1 Jun 2021 08:22:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1622535738; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1HYvwC4LeaG6a/QIntcnBTi0zzKhYzHLInFyrkpV5ac=; b=JborPxX4gCbF76H6H2kHLEK+kw+Sb93jjDp4d7+9eZZKuGAKhy25lwm7CFl32MZcspwJZ/ Iabv+XjmCBgD9NnGilVTR53WwfnXho3GeMSggnath+J0fDXF2tmWWHEYJyWrPd2OFdyY4y 6q/Eq8vPTjurAd0/fXNoYnL+sKKtO0o= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-52-4f5UBVzlOO-31WziwHfImg-1; Tue, 01 Jun 2021 04:22:17 -0400 X-MC-Unique: 4f5UBVzlOO-31WziwHfImg-1 Received: by mail-wr1-f72.google.com with SMTP id y11-20020adfe6cb0000b0290114d1db9b88so3684400wrm.19 for ; Tue, 01 Jun 2021 01:22:16 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:organization :message-id:date:user-agent:mime-version:in-reply-to :content-language:content-transfer-encoding; bh=1HYvwC4LeaG6a/QIntcnBTi0zzKhYzHLInFyrkpV5ac=; b=LSgwonjiKnNL61g0U/qrCAMLXuiRhNpzS9/oPe/ZGmk8DwyF3l1WSHRiFAK7bT6rmM LMo980ujzZFpILYPXaeQ+Z6Oyra//vEXc6tmDVPEul41N1oPoIflqo+fcQsUOB1IRYgI oe2NaalUxiwPwqTEDiu8rs5SJPoSlexCUCCtq5jKOlD3exZUGDGvLmv914w77zHWGzUD a0CZNP2BN59a1n1Kgd3udtpvutre9pMbEA9cYolSTnvoqFPS8EhkhXVTSgdeF/HmifW+ ZE27NNCRueHs13aOiXWEXPR1e3u8XQLCdXd4Sx8v4+aO77F/geHFqpxI4R8h821aSBkW rkaw== X-Gm-Message-State: AOAM530bF4qMF+8fOkma9+FhcZjinV3Y6ZbsZbVVGupVffazjIgEJyjW +PbBeRoq0LmUROL17lyA2NiuXGwz1ANz65m1NKEDMpmXX0AXvMSGzg+SxDltt/Ycc1F8MXgk+y9 QsCR85+ksLvM= X-Received: by 2002:adf:ebc6:: with SMTP id v6mr23696112wrn.398.1622535735898; Tue, 01 Jun 2021 01:22:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx+CHHKTTiLAMmYpOGvNt15P9iM9jI3x6ac5muDu4VAi6OyM2btTWtASZ/Tm4IUhbSdEh9heQ== X-Received: by 2002:adf:ebc6:: with SMTP id v6mr23696101wrn.398.1622535735744; Tue, 01 Jun 2021 01:22:15 -0700 (PDT) Received: from [192.168.3.132] (p5b0c69ce.dip0.t-ipconnect.de. [91.12.105.206]) by smtp.gmail.com with ESMTPSA id e8sm2341767wrt.30.2021.06.01.01.22.15 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 01 Jun 2021 01:22:15 -0700 (PDT) Subject: Re: [PATCH V2 3/6] mm/sparse: move mem_sections allocation out of memory_present() To: Dong Aisheng , linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org, dongas86@gmail.com, Andrew Morton , Mike Rapoport References: <20210531091908.1738465-1-aisheng.dong@nxp.com> <20210531091908.1738465-4-aisheng.dong@nxp.com> From: David Hildenbrand Organization: Red Hat Message-ID: <64078986-3f46-9d2a-ee60-5581931eebbc@redhat.com> Date: Tue, 1 Jun 2021 10:22:14 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.10.1 MIME-Version: 1.0 In-Reply-To: <20210531091908.1738465-4-aisheng.dong@nxp.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Rspamd-Queue-Id: 154D1C00CBEE Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=JborPxX4; spf=none (imf14.hostedemail.com: domain of david@redhat.com has no SPF policy when checking 170.10.133.124) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-Rspamd-Server: rspam04 X-Stat-Signature: yxfbpo34pjqwqynucd3bcrxdz5tmg4f8 X-HE-Tag: 1622535725-262882 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 31.05.21 11:19, Dong Aisheng wrote: > The only path to call memory_present() is from memblocks_present(). > The struct mem_section **mem_section only needs to be initialized once, > so no need put the initialization/allocation code in memory_present() > which will be called multiple times for each section. > > After moving, the 'unlikely' condition statement becomes to be > meaningless as it's only initialized one time, so dropped as well. > > Cc: Andrew Morton > Cc: Mike Rapoport > Signed-off-by: Dong Aisheng > --- > ChangeLog: > v1->v2: > * split into a helper function and called directly from sparse_init > --- > mm/sparse.c | 29 ++++++++++++++++------------- > 1 file changed, 16 insertions(+), 13 deletions(-) > > diff --git a/mm/sparse.c b/mm/sparse.c > index 408b737e168e..d02ee6bb7cbc 100644 > --- a/mm/sparse.c > +++ b/mm/sparse.c > @@ -60,6 +60,18 @@ static inline void set_section_nid(unsigned long section_nr, int nid) > #endif > > #ifdef CONFIG_SPARSEMEM_EXTREME > +static void __init sparse_alloc_section_roots(void) > +{ > + unsigned long size, align; > + > + size = sizeof(struct mem_section *) * NR_SECTION_ROOTS; > + align = 1 << (INTERNODE_CACHE_SHIFT); > + mem_section = memblock_alloc(size, align); > + if (!mem_section) > + panic("%s: Failed to allocate %lu bytes align=0x%lx\n", > + __func__, size, align); > +} > + > static noinline struct mem_section __ref *sparse_index_alloc(int nid) > { > struct mem_section *section = NULL; > @@ -107,6 +119,8 @@ static inline int sparse_index_init(unsigned long section_nr, int nid) > { > return 0; > } > + > +static inline void sparse_alloc_section_roots(void) {} > #endif > > #ifdef CONFIG_SPARSEMEM_EXTREME > @@ -254,19 +268,6 @@ static void __init memory_present(int nid, unsigned long start, unsigned long en > { > unsigned long pfn; > > -#ifdef CONFIG_SPARSEMEM_EXTREME > - if (unlikely(!mem_section)) { > - unsigned long size, align; > - > - size = sizeof(struct mem_section *) * NR_SECTION_ROOTS; > - align = 1 << (INTERNODE_CACHE_SHIFT); > - mem_section = memblock_alloc(size, align); > - if (!mem_section) > - panic("%s: Failed to allocate %lu bytes align=0x%lx\n", > - __func__, size, align); > - } > -#endif > - > start &= PAGE_SECTION_MASK; > mminit_validate_memmodel_limits(&start, &end); > for (pfn = start; pfn < end; pfn += PAGES_PER_SECTION) { > @@ -582,6 +583,8 @@ void __init sparse_init(void) > unsigned long pnum_end, pnum_begin, map_count = 1; > int nid_begin; > > + sparse_alloc_section_roots(); > + > memblocks_present(); > > pnum_begin = first_present_section_nr(); > Acked-by: David Hildenbrand -- Thanks, David / dhildenb