linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: David Hildenbrand <david@redhat.com>
To: Michal Hocko <mhocko@kernel.org>
Cc: David Hildenbrand <david@redhat.com>,
	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 11:25:28 +0100	[thread overview]
Message-ID: <5E2F5866-0605-4DD2-9AEA-4B1C44E57D9F@redhat.com> (raw)
In-Reply-To: <20191128102051.GI26807@dhcp22.suse.cz>



> Am 28.11.2019 um 11:20 schrieb Michal Hocko <mhocko@kernel.org>:
> 
> On Wed 27-11-19 18:41:26, David Hildenbrand wrote:
>> Since commit d84f2f5a7552 ("drivers/base/node.c: simplify
>> unregister_memory_block_under_nodes()") we only have a single user of
>> get_nid_for_pfn(). Let's just inline that code and get rid of
>> get_nid_for_pfn().
>> 
>> 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>
> 
> I am not really sure this is an improvement. The code is ugly as hell
> and open coding it just makes register_mem_sect_under_node harder to
> read.

The issue I see is that this is a dangerous wrapper for pfn_to_nid() that is absolutely not obvious. The old second user on the memory removal path was completely buggy. IMHO nobody should be reusing that function. But it looks like a general „safe wrapper to get a nid“ - it‘s not.

How can we make that more obvious instead?

> 
> If anything get_nid_for_pfn deserves a comment why
> CONFIG_DEFERRED_STRUCT_PAGE_INIT calls for special case as
> early_pfn_to_nid is not bound to that config (it is defined when
> CONFIG_HAVE_ARCH_EARLY_PFN_TO_NID || CONFIG_HAVE_MEMBLOCK_NODE_MAP
> 
>> ---
>> drivers/base/node.c | 23 +++++++----------------
>> 1 file changed, 7 insertions(+), 16 deletions(-)
>> 
>> diff --git a/drivers/base/node.c b/drivers/base/node.c
>> index 98a31bafc8a2..735073fd2926 100644
>> --- a/drivers/base/node.c
>> +++ b/drivers/base/node.c
>> @@ -744,17 +744,6 @@ int unregister_cpu_under_node(unsigned int cpu, unsigned int nid)
>> }
>> 
>> #ifdef CONFIG_MEMORY_HOTPLUG_SPARSE
>> -static int __ref get_nid_for_pfn(unsigned long pfn)
>> -{
>> -    if (!pfn_valid_within(pfn))
>> -        return -1;
>> -#ifdef CONFIG_DEFERRED_STRUCT_PAGE_INIT
>> -    if (system_state < SYSTEM_RUNNING)
>> -        return early_pfn_to_nid(pfn);
>> -#endif
>> -    return pfn_to_nid(pfn);
>> -}
>> -
>> /* register memory section under specified node if it spans that node */
>> static int register_mem_sect_under_node(struct memory_block *mem_blk,
>>                     void *arg)
>> @@ -766,8 +755,6 @@ static int register_mem_sect_under_node(struct memory_block *mem_blk,
>>    unsigned long pfn;
>> 
>>    for (pfn = start_pfn; pfn <= end_pfn; pfn++) {
>> -        int page_nid;
>> -
>>        /*
>>         * memory block could have several absent sections from start.
>>         * skip pfn range from absent section
>> @@ -784,11 +771,15 @@ static int register_mem_sect_under_node(struct memory_block *mem_blk,
>>         * block belong to the same node.
>>         */
>>        if (system_state == SYSTEM_BOOTING) {
>> -            page_nid = get_nid_for_pfn(pfn);
>> -            if (page_nid < 0)
>> +            if (!pfn_valid_within(pfn))
>>                continue;
>> -            if (page_nid != nid)
>> +#ifdef CONFIG_DEFERRED_STRUCT_PAGE_INIT
>> +            if (early_pfn_to_nid(pfn) != nid)
>>                continue;
>> +#else
>> +            if (pfn_to_nid(pfn) != nid)
>> +                continue;
>> +#endif
>>        }
>> 
>>        /*
>> -- 
>> 2.21.0
> 
> -- 
> Michal Hocko
> SUSE Labs
> 



  reply	other threads:[~2019-11-28 10:25 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 [this message]
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

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=5E2F5866-0605-4DD2-9AEA-4B1C44E57D9F@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