linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: David Hildenbrand <david@redhat.com>
To: Michal Hocko <mhocko@kernel.org>
Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	"Rafael J. Wysocki" <rafael@kernel.org>,
	Oscar Salvador <osalvador@suse.de>,
	Andrew Morton <akpm@linux-foundation.org>
Subject: Re: [PATCH v1] drivers/base/node.c: get rid of get_nid_for_pfn()
Date: Thu, 28 Nov 2019 15:13:06 +0100	[thread overview]
Message-ID: <3f597f0d-a0d0-4bff-28cc-3fa92aa0b70f@redhat.com> (raw)
In-Reply-To: <17785662-d004-21ad-16a6-296c82779c8f@redhat.com>

On 28.11.19 13:19, David Hildenbrand wrote:
> On 28.11.19 13:01, Michal Hocko wrote:
>> On Thu 28-11-19 12:52:16, David Hildenbrand wrote:
>>> On 28.11.19 12:50, Michal Hocko wrote:
>>>> On Thu 28-11-19 12:23:08, David Hildenbrand wrote:
>>>> [...]
>>>>> >From fc13fd540a1702592e389e821f6266098e41e2bd Mon Sep 17 00:00:00 2001
>>>>> From: David Hildenbrand <david@redhat.com>
>>>>> Date: Wed, 27 Nov 2019 16:18:42 +0100
>>>>> Subject: [PATCH] drivers/base/node.c: optimize get_nid_for_pfn()
>>>>>
>>>>> Since commit d84f2f5a7552 ("drivers/base/node.c: simplify
>>>>> unregister_memory_block_under_nodes()") we only have a single user of
>>>>> get_nid_for_pfn(). The remaining user calls this function when booting -
>>>>> where all added memory is online.
>>>>>
>>>>> Make it clearer that this function should only be used during boot (
>>>>> e.g., calling it on offline memory would be bad) by renaming the
>>>>> function to something meaningful, optimize out the ifdef and the additional
>>>>> system_state check, and add a comment why CONFIG_DEFERRED_STRUCT_PAGE_INIT
>>>>> handling is in place at all.
>>>>>
>>>>> Also, optimize the call site. There is no need to check against
>>>>> page_nid < 0 - it will never match the nid (nid >= 0).
>>>>>
>>>>> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
>>>>> Cc: "Rafael J. Wysocki" <rafael@kernel.org>
>>>>> Cc: Michal Hocko <mhocko@kernel.org>
>>>>> Cc: Oscar Salvador <osalvador@suse.de>
>>>>> Cc: Andrew Morton <akpm@linux-foundation.org>
>>>>> Signed-off-by: David Hildenbrand <david@redhat.com>
>>>>
>>>> Yes this looks much better! I am not sure this will pass all weird
>>>> config combinations because IS_ENABLED will not hide early_pfn_to_nid
>>>> from the early compiler stages so it might complain. But if this passes
>>>> 0day compile scrutiny then this is much much better. If not then we just
>>>> have to use ifdef which is a minor thing.
>>>
>>> The compiler should optimize out
>>>
>>> if (0)
>>> 	code
>>>
>>> and therefore never link to early_pfn_to_nid.
>>
>> You are right, but there is a catch. The optimization phase is much
>> later than the syntactic check so if the code doesn't make sense
>> for the syntactic point of view then it will complain. This is a notable
>> difference to #ifdef which just removes the whole block in the
>> preprocessor phase.
>>
> 
> We should always have a declaration of early_pfn_to_nid(). The
> interesting part AFAIKS is include/linux/mmzone.h:
> 
> #if !defined(CONFIG_HAVE_ARCH_EARLY_PFN_TO_NID) && \
> 	!defined(CONFIG_HAVE_MEMBLOCK_NODE_MAP)
> static inline unsigned long early_pfn_to_nid(unsigned long pfn)
> {
> 	BUILD_BUG_ON(IS_ENABLED(CONFIG_NUMA));
> 	return 0;
> }
> #endif
> 
> so we would have
> 
> if (IS_ENABLED(...))
> 	BUILD_BUG_ON(IS_ENABLED(CONFIG_NUMA));
> 
> Let's see how that will turn out :) Will do some test builds
> (CONFIG_NUMA, !CONFIG_HAVE_ARCH_EARLY_PFN_TO_NID and
> !CONFIG_HAVE_MEMBLOCK_NODE_MAP) ... if possible
> 

So ... the code is fenced by MEMORY_HOTPLUG_SPARSE, which requires
"SPARSEMEM && MEMORY_HOTPLUG". MEMORY_HOTPLUG requires
ARCH_ENABLE_MEMORY_HOTPLUG

Architectures with ARCH_ENABLE_MEMORY_HOTPLUG (conditional):
arm64, ia64, powerpc, s390, sh, x86

Architectures with HAVE_MEMBLOCK_NODE_MAP (unconditional):
arm64, ia64, mips, powerpc, riscv, s390, sh, sparc, x86


Which implies that we will always have
mm/page_alloc.c:early_pfn_to_nid() and therefore no compile issues with

if (IS_ENABLED(CONFIG_DEFERRED_STRUCT_PAGE_INIT))
	return early_pfn_to_nid(pfn);


Will do more testing and send this as an official patch. Thanks!

-- 
Thanks,

David / dhildenb



      reply	other threads:[~2019-11-28 14:13 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-27 17:41 David Hildenbrand
2019-11-28 10:20 ` Michal Hocko
2019-11-28 10:25   ` David Hildenbrand
2019-11-28 11:23     ` David Hildenbrand
2019-11-28 11:50       ` Michal Hocko
2019-11-28 11:52         ` David Hildenbrand
2019-11-28 12:01           ` Michal Hocko
2019-11-28 12:19             ` David Hildenbrand
2019-11-28 14:13               ` David Hildenbrand [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3f597f0d-a0d0-4bff-28cc-3fa92aa0b70f@redhat.com \
    --to=david@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mhocko@kernel.org \
    --cc=osalvador@suse.de \
    --cc=rafael@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox