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=-12.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS 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 E2989C47082 for ; Tue, 1 Jun 2021 02:39:46 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 789F26135C for ; Tue, 1 Jun 2021 02:39:46 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 789F26135C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 167116B006C; Mon, 31 May 2021 22:39:46 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1176A8E0002; Mon, 31 May 2021 22:39:46 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F21508E0001; Mon, 31 May 2021 22:39:45 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0071.hostedemail.com [216.40.44.71]) by kanga.kvack.org (Postfix) with ESMTP id C30CA6B006C for ; Mon, 31 May 2021 22:39:45 -0400 (EDT) Received: from smtpin25.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 5746C181AC9CB for ; Tue, 1 Jun 2021 02:39:45 +0000 (UTC) X-FDA: 78203599530.25.55F4015 Received: from mail-ot1-f49.google.com (mail-ot1-f49.google.com [209.85.210.49]) by imf07.hostedemail.com (Postfix) with ESMTP id ABB75A000245 for ; Tue, 1 Jun 2021 02:39:32 +0000 (UTC) Received: by mail-ot1-f49.google.com with SMTP id x41-20020a05683040a9b02903b37841177eso3279896ott.9 for ; Mon, 31 May 2021 19:39:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=66WU/OYhf8/UwAHOYjWvVcdDw9Pdav8Sh+qnUyaTJQ0=; b=iI0ft9pTkdeQ+G3YXcWQ64+QUUe2EJaVkfUFE2rQHO4oH5yrpUI/qQwPf5/YL90iIE SRQLBswZOiJVcAOot6MJCRF+lMOrVRa+/DGGvg8jQ7pjcShdaGRsXuPVVPRMA3YbMRYo jcPSA0E1qvnQq8rM66I+jR+d8jaFbApUbREvIUSb4Gn5kGQK+RaCJ5ymjvAyxdhb2ts+ CQFUlZiNPA0nC2ddGhx1yh/V/MQMxyinO+tiskMYtuEeffMevJlzyYnFFz43bhtXjIM9 qkodMlUoSgBekhrFg7+9TJCTDmqL9PedufkEJFkjH8ryUwCTxFV5Arq+KpP6hGuaSSER tUQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=66WU/OYhf8/UwAHOYjWvVcdDw9Pdav8Sh+qnUyaTJQ0=; b=XDMciEDaxdPZ3kt/RZAx6a/OE807mix1Jz2Wj6gYbAR+Y+2fEpVOiyuKVhn+Zf5nWC CNnySmZhOWaDgN6snxuDvjX5We2YkMCancF+/F7QiCjTXqTiqYKEDFJwIHuAK6Qls6hv JKf4gOzyjxmL2GlKB94Z14VzA4yucesutu9DoALpwYKuaJCfsjwmjgsnVH3lx/oDGqwR ZizwYYxVKGofYQvqONYXwXmZ0s2Att1C7+No9Kh4kxW1RpWyOfrYcYI8ib5WoUNlgxcP Fhz+JjcpFYnnKWVfMjhol0OMJOgth5+gl0AYFiL1th+gJzFhII39rEFHbFNZA1NIJu1E nGeQ== X-Gm-Message-State: AOAM5315u9PXO2p00iPLJhpNVMg55+PI8mdBq1zr1PtyQKaaCJOvR5sx 75EYFZBX3vgMkdqj3oOs2FRfAPp7kYZrttWZX6Y= X-Google-Smtp-Source: ABdhPJyaCX9j4/a2SojGeqejlEl0P1R12d7cCtEIMzCFq1CDU7S9DzIwCeoBjLRanURsESoqB84hoc+gw2uj+yIE4M8= X-Received: by 2002:a9d:4d99:: with SMTP id u25mr6678833otk.248.1622515184264; Mon, 31 May 2021 19:39:44 -0700 (PDT) MIME-Version: 1.0 References: <20210531091908.1738465-1-aisheng.dong@nxp.com> <20210531091908.1738465-4-aisheng.dong@nxp.com> <20210531143852.h226vpjrgpyo2eqw@revolver> In-Reply-To: <20210531143852.h226vpjrgpyo2eqw@revolver> From: Dong Aisheng Date: Tue, 1 Jun 2021 10:38:33 +0800 Message-ID: Subject: Re: [PATCH V2 3/6] mm/sparse: move mem_sections allocation out of memory_present() To: Liam Howlett Cc: Dong Aisheng , "linux-mm@kvack.org" , "linux-kernel@vger.kernel.org" , Andrew Morton , Mike Rapoport Content-Type: text/plain; charset="UTF-8" Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=gmail.com header.s=20161025 header.b=iI0ft9pT; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf07.hostedemail.com: domain of dongas86@gmail.com designates 209.85.210.49 as permitted sender) smtp.mailfrom=dongas86@gmail.com X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: ABB75A000245 X-Stat-Signature: 5er4gqyq68p8g6mgnnxsg4qgshcmsdfg X-HE-Tag: 1622515172-830973 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 Mon, May 31, 2021 at 10:39 PM Liam Howlett wrote: > > * Dong Aisheng [210531 05:20]: > > 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(); > > nit: The newline below is unnecessary > Can drop it , thanks Regards AIsheng > > + > > memblocks_present(); > > > > pnum_begin = first_present_section_nr(); > > -- > > 2.25.1 > > > >