Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3279831pxj; Tue, 1 Jun 2021 01:23:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw82qvEhKdFYxV14ceFhZ3xSuA1/d7I506ykjMOWo1kJgceHwz/uM1lFNHON8NjWHJPafHC X-Received: by 2002:a17:906:d781:: with SMTP id pj1mr8467064ejb.136.1622535826197; Tue, 01 Jun 2021 01:23:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622535826; cv=none; d=google.com; s=arc-20160816; b=xntv3cBqQ8JO/52oZLbTtN9zTk7I/l/j4+pKyJlTbMFTML/DM02A9c+JoHZrgOWNbM VtbnFhj5wrhHaw/2yBRgs54GabgQQYczgQfLokSQn9Haw/edK1XLzgi3KCSAd7zJ+7hn L5IqDWZISpn7U+d0GMXSKSS/RC5BU9PI8DGJUYjPn9nrWKcJ3V/Zwgh7gAgFZcAUdtH3 IHtgwOW1go+oe7WTaOwutmchuRJhj5n1FJTpFKijukh0Dndfc0DUFd+otwCe9gW6cKfp qTLXjOCEHOt8XUIkiRy10F/+chjSFzYxR5y7KXwy2LLImg1GDYdRI5vxdbnWc03k5JDi WieQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:organization :from:references:cc:to:subject:dkim-signature; bh=1HYvwC4LeaG6a/QIntcnBTi0zzKhYzHLInFyrkpV5ac=; b=nsTDWvKpYh7nVW59nWkO0EIYXjKOuZybdcP9JhoTbJn+PCnwQuyWYXaE2g6A2SQ/VG DFB6xOmlvmy5jSaaB0P1og0EleBA9RysFYv0OAD/z3zIMuT9yX0oWsba0B1HOXwRFzya ktj/ToPzIXm8qy7f+hP2jOwC2D1CUxk9X1yG9Xq+H8WZYTpJTOwcjiXVwx4hHLyN4RWd y64TkteKT1oFEv6hTg1pchOefQaSrKcRbp5YSsuukI+MCTIuwzwZhitAxoxLogvY/qJ5 IeRHr6aMt3/nV0OwMZcxOQzZEKXnowxMXmHbjHNGDkAZzWLSY9pVTKv4oeMUSLZrIf6l Dhjg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=JborPxX4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h8si10620718edz.253.2021.06.01.01.23.24; Tue, 01 Jun 2021 01:23:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=JborPxX4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233490AbhFAIYB (ORCPT + 99 others); Tue, 1 Jun 2021 04:24:01 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:28975 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233423AbhFAIX7 (ORCPT ); Tue, 1 Jun 2021 04:23:59 -0400 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-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-213-EuuRh-ITMKiKO1xpmMWdsA-1; Tue, 01 Jun 2021 04:22:17 -0400 X-MC-Unique: EuuRh-ITMKiKO1xpmMWdsA-1 Received: by mail-wm1-f72.google.com with SMTP id y129-20020a1c32870000b029016920cc7087so2451690wmy.4 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=Zuko9vZMUtkYt0q7x/Mje/My957hn4dTOrt9OFk5ck0FAogSGczoIlVvJuFERbftiI AqSERxlyIMS7RZrkuQ7EIPobbFtdBVy7CP97+mQZnTXNQKPasYEq7RX6f4rGcIc6QB+i vEuaGo8XyJ4cWmmQn7b1v08Wwvj6L8jSJ1fenly2zNJiSPeb8wAlIQlXwrSse86P6JPO rdMgspi74TZXTlqoffNF1Kmo8LIAchi7uKbGuyzLT3ldKklAWdKazvthDFftz6VQlG85 UEEkE/GJDoG97Fqlg52DxvbFAvSQ4Jfa9bZcZNyw25KClqjkIvRNRjUvOCmemhb/m/RJ F6Tg== X-Gm-Message-State: AOAM530tO3U8eiDIluA2AvMD3IX6k0h7MktIbCR8yMHfK5j/Ve7CCRZk YEMVW/No7cFXZ24KR1sStsTPH9d+WlFVW8lP+enj5oBF9uTURgmrsTNvJ8Aw0E1nfWCQylI3BAl 4M7vcpfqyw+xGYh2CqtXwUbS+ X-Received: by 2002:adf:ebc6:: with SMTP id v6mr23696116wrn.398.1622535735899; Tue, 01 Jun 2021 01:22:15 -0700 (PDT) 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> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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