public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Mike Rapoport <rppt@kernel.org>
To: Donet Tom <donettom@linux.ibm.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	linux-kernel@vger.kernel.org,
	David Hildenbrand <david@redhat.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	linux-mm@kvack.org, Ritesh Harjani <ritesh.list@gmail.com>,
	rafael@kernel.org, Danilo Krummrich <dakr@kernel.org>
Subject: Re: [PATCH 2/2] base/node: Use curr_node_memblock_intersect_memory_block to Get Memory Block NID if CONFIG_DEFERRED_STRUCT_PAGE_INIT is Set
Date: Thu, 10 Apr 2025 11:07:43 +0300	[thread overview]
Message-ID: <Z_d8T3QtnZVeH3HF@kernel.org> (raw)
In-Reply-To: <d10d1a9f11e9f8752c7ec5ff5bb262b3f6c6bb85.1744175097.git.donettom@linux.ibm.com>

On Wed, Apr 09, 2025 at 10:57:57AM +0530, Donet Tom wrote:
> In the current implementation, when CONFIG_DEFERRED_STRUCT_PAGE_INIT is
> set, we iterate over all PFNs in the memory block and use
> early_pfn_to_nid to find the NID until a match is found.
> 
> This patch we are using curr_node_memblock_intersect_memory_block() to
> check if the current node's memblock intersects with the memory block
> passed when CONFIG_DEFERRED_STRUCT_PAGE_INIT is set. If an intersection
> is found, the memory block is added to the current node.
> 
> If CONFIG_DEFERRED_STRUCT_PAGE_INIT is not set, the existing mechanism
> for finding the NID will continue to be used.

I don't think we really need different mechanisms for different settings of
CONFIG_DEFERRED_STRUCT_PAGE_INIT. 

node_dev_init() runs after all struct pages are already initialized and can
always use pfn_to_nid().

kernel_init_freeable() ->
	page_alloc_init_late(); /* completes initialization of deferred pages */
	...
	do_basic_setup() ->
		driver_init() ->
			node_dev_init();

The next step could be refactoring register_mem_block_under_node_early() to
loop over memblock regions rather than over pfns.
 
> Signed-off-by: Donet Tom <donettom@linux.ibm.com>
> ---
>  drivers/base/node.c | 37 +++++++++++++++++++++++++++++--------
>  1 file changed, 29 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/base/node.c b/drivers/base/node.c
> index cd13ef287011..5c5dd02b8bdd 100644
> --- a/drivers/base/node.c
> +++ b/drivers/base/node.c
> @@ -20,6 +20,8 @@
>  #include <linux/pm_runtime.h>
>  #include <linux/swap.h>
>  #include <linux/slab.h>
> +#include <linux/memblock.h>
> +
>  
>  static const struct bus_type node_subsys = {
>  	.name = "node",
> @@ -782,16 +784,19 @@ static void do_register_memory_block_under_node(int nid,
>  				    ret);
>  }
>  
> -/* register memory section under specified node if it spans that node */
> -static int register_mem_block_under_node_early(struct memory_block *mem_blk,
> -					       void *arg)
> +static int register_mem_block_early_if_dfer_page_init(struct memory_block *mem_blk,
> +				unsigned long start_pfn, unsigned long end_pfn, int nid)
>  {
> -	unsigned long memory_block_pfns = memory_block_size_bytes() / PAGE_SIZE;
> -	unsigned long start_pfn = section_nr_to_pfn(mem_blk->start_section_nr);
> -	unsigned long end_pfn = start_pfn + memory_block_pfns - 1;
> -	int nid = *(int *)arg;
> -	unsigned long pfn;
>  
> +	if (curr_node_memblock_intersect_memory_block(start_pfn, end_pfn, nid))
> +		do_register_memory_block_under_node(nid, mem_blk, MEMINIT_EARLY);
> +	return 0;
> +}
> +
> +static int register_mem_block_early__normal(struct memory_block *mem_blk,
> +				unsigned long start_pfn, unsigned long end_pfn, int nid)
> +{
> +	unsigned long pfn;
>  	for (pfn = start_pfn; pfn <= end_pfn; pfn++) {
>  		int page_nid;
>  
> @@ -821,6 +826,22 @@ static int register_mem_block_under_node_early(struct memory_block *mem_blk,
>  	/* mem section does not span the specified node */
>  	return 0;
>  }
> +/* register memory section under specified node if it spans that node */
> +static int register_mem_block_under_node_early(struct memory_block *mem_blk,
> +					       void *arg)
> +{
> +	unsigned long memory_block_pfns = memory_block_size_bytes() / PAGE_SIZE;
> +	unsigned long start_pfn = section_nr_to_pfn(mem_blk->start_section_nr);
> +	unsigned long end_pfn = start_pfn + memory_block_pfns - 1;
> +	int nid = *(int *)arg;
> +
> +#ifdef CONFIG_DEFERRED_STRUCT_PAGE_INIT
> +	if (system_state < SYSTEM_RUNNING)
> +		return register_mem_block_early_if_dfer_page_init(mem_blk, start_pfn, end_pfn, nid);
> +#endif
> +	return register_mem_block_early__normal(mem_blk, start_pfn, end_pfn, nid);
> +
> +}
>  
>  /*
>   * During hotplug we know that all pages in the memory block belong to the same
> -- 
> 2.48.1
> 

-- 
Sincerely yours,
Mike.

  reply	other threads:[~2025-04-10  8:07 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-09  5:27 [PATCH 1/2] mm/memblock: Added a New Memblock Function to Check if the Current Node's Memblock Region Intersects with a Memory Block Donet Tom
2025-04-09  5:27 ` [PATCH 2/2] base/node: Use curr_node_memblock_intersect_memory_block to Get Memory Block NID if CONFIG_DEFERRED_STRUCT_PAGE_INIT is Set Donet Tom
2025-04-10  8:07   ` Mike Rapoport [this message]
2025-04-10 18:57     ` Donet Tom
2025-04-11 10:59       ` Mike Rapoport
2025-04-11 11:36         ` Donet Tom
2025-04-15  9:46           ` Mike Rapoport
2025-04-15 10:08             ` Donet Tom
2025-04-10  2:20 ` [PATCH 1/2] mm/memblock: Added a New Memblock Function to Check if the Current Node's Memblock Region Intersects with a Memory Block Andrew Morton
2025-04-10  4:35   ` Donet Tom
2025-04-10  7:03 ` kernel test robot
2025-04-10  7:25 ` kernel test robot
2025-04-10  7:49 ` Mike Rapoport
2025-04-10 19:06   ` Donet Tom

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=Z_d8T3QtnZVeH3HF@kernel.org \
    --to=rppt@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=dakr@kernel.org \
    --cc=david@redhat.com \
    --cc=donettom@linux.ibm.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=rafael@kernel.org \
    --cc=ritesh.list@gmail.com \
    /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