diff mbox series

[2/2] mm/mm_init.c: count nr_initialised only for last zone

Message ID 20240522072959.23741-2-richard.weiyang@gmail.com (mailing list archive)
State New
Headers show
Series [1/2] mm/mm_init.c: use memblock_region_memory_base_pfn() to get startpfn | expand

Commit Message

Wei Yang May 22, 2024, 7:29 a.m. UTC
Since we always populate low zones, it is not necessary to count
nr_initialised for them. Let's move the last zone check ahead to skip
the nr_initialised reset.

Assume low zones counts for 4G, this change may reduce 1M times
comparison of prev_end_pfn and end_pfn.

Signed-off-by: Wei Yang <richard.weiyang@gmail.com>
---
 mm/mm_init.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

Comments

Mike Rapoport May 23, 2024, 2:53 p.m. UTC | #1
On Wed, May 22, 2024 at 07:29:59AM +0000, Wei Yang wrote:
> Since we always populate low zones, it is not necessary to count
> nr_initialised for them. Let's move the last zone check ahead to skip
> the nr_initialised reset.

We also don't need to count initialized pfns after first_deferred_pfn is
detected, so the reset of nr_initialised can be moved even lower.

> Assume low zones counts for 4G, this change may reduce 1M times
> comparison of prev_end_pfn and end_pfn.
> 
> Signed-off-by: Wei Yang <richard.weiyang@gmail.com>
> ---
>  mm/mm_init.c | 9 +++++----
>  1 file changed, 5 insertions(+), 4 deletions(-)
> 
> diff --git a/mm/mm_init.c b/mm/mm_init.c
> index 2dfb87841fdb..4cc627b4ebfe 100644
> --- a/mm/mm_init.c
> +++ b/mm/mm_init.c
> @@ -676,6 +676,11 @@ defer_init(int nid, unsigned long pfn, unsigned long end_pfn)
>  
>  	if (early_page_ext_enabled())
>  		return false;
> +
> +	/* Always populate low zones for address-constrained allocations */
> +	if (end_pfn < pgdat_end_pfn(NODE_DATA(nid)))
> +		return false;
> +
>  	/*
>  	 * prev_end_pfn static that contains the end of previous zone
>  	 * No need to protect because called very early in boot before smp_init.
> @@ -685,10 +690,6 @@ defer_init(int nid, unsigned long pfn, unsigned long end_pfn)
>  		nr_initialised = 0;
>  	}
>  
> -	/* Always populate low zones for address-constrained allocations */
> -	if (end_pfn < pgdat_end_pfn(NODE_DATA(nid)))
> -		return false;
> -
>  	if (NODE_DATA(nid)->first_deferred_pfn != ULONG_MAX)
>  		return true;
>  	/*
> -- 
> 2.34.1
>
Wei Yang May 24, 2024, 12:59 a.m. UTC | #2
On Thu, May 23, 2024 at 05:53:09PM +0300, Mike Rapoport wrote:
>On Wed, May 22, 2024 at 07:29:59AM +0000, Wei Yang wrote:
>> Since we always populate low zones, it is not necessary to count
>> nr_initialised for them. Let's move the last zone check ahead to skip
>> the nr_initialised reset.
>
>We also don't need to count initialized pfns after first_deferred_pfn is
>detected, so the reset of nr_initialised can be moved even lower.
>

Agree, will update in v2.
diff mbox series

Patch

diff --git a/mm/mm_init.c b/mm/mm_init.c
index 2dfb87841fdb..4cc627b4ebfe 100644
--- a/mm/mm_init.c
+++ b/mm/mm_init.c
@@ -676,6 +676,11 @@  defer_init(int nid, unsigned long pfn, unsigned long end_pfn)
 
 	if (early_page_ext_enabled())
 		return false;
+
+	/* Always populate low zones for address-constrained allocations */
+	if (end_pfn < pgdat_end_pfn(NODE_DATA(nid)))
+		return false;
+
 	/*
 	 * prev_end_pfn static that contains the end of previous zone
 	 * No need to protect because called very early in boot before smp_init.
@@ -685,10 +690,6 @@  defer_init(int nid, unsigned long pfn, unsigned long end_pfn)
 		nr_initialised = 0;
 	}
 
-	/* Always populate low zones for address-constrained allocations */
-	if (end_pfn < pgdat_end_pfn(NODE_DATA(nid)))
-		return false;
-
 	if (NODE_DATA(nid)->first_deferred_pfn != ULONG_MAX)
 		return true;
 	/*