linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] mm/page_owner: Rename proc-prefixed variables for clarity
@ 2025-09-30  9:21 Hu Song
  2025-09-30  9:21 ` [PATCH 2/2] mm/page_owner: simplify zone iteration logic in init_early_allocated_pages() Hu Song
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Hu Song @ 2025-09-30  9:21 UTC (permalink / raw)
  To: Andrew Morton, Vlastimil Babka
  Cc: Song Hu, Suren Baghdasaryan, Michal Hocko, Brendan Jackman,
	Johannes Weiner, Zi Yan, linux-mm, linux-kernel

From: Song Hu <husong@kylinos.cn>

The `proc_page_owner_operations` and related variables were renamed to
`page_owner_fops` to better reflect their association with `debugfs` rather
than `/proc`. This improves code clarity and aligns with kernel naming
conventions.

Signed-off-by: Song Hu <husong@kylinos.cn>
---
 mm/page_owner.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/mm/page_owner.c b/mm/page_owner.c
index c3ca21132c2c..bb88b72b6062 100644
--- a/mm/page_owner.c
+++ b/mm/page_owner.c
@@ -848,7 +848,7 @@ static void init_early_allocated_pages(void)
 		init_zones_in_node(pgdat);
 }
 
-static const struct file_operations proc_page_owner_operations = {
+static const struct file_operations page_owner_fops = {
 	.read		= read_page_owner,
 	.llseek		= lseek_page_owner,
 };
@@ -929,7 +929,7 @@ static int page_owner_stack_open(struct inode *inode, struct file *file)
 	return seq_open_private(file, &page_owner_stack_op, 0);
 }
 
-static const struct file_operations page_owner_stack_operations = {
+static const struct file_operations page_owner_stack_fops = {
 	.open		= page_owner_stack_open,
 	.read		= seq_read,
 	.llseek		= seq_lseek,
@@ -948,7 +948,7 @@ static int page_owner_threshold_set(void *data, u64 val)
 	return 0;
 }
 
-DEFINE_SIMPLE_ATTRIBUTE(proc_page_owner_threshold, &page_owner_threshold_get,
+DEFINE_SIMPLE_ATTRIBUTE(page_owner_threshold_fops, &page_owner_threshold_get,
 			&page_owner_threshold_set, "%llu");
 
 
@@ -961,13 +961,12 @@ static int __init pageowner_init(void)
 		return 0;
 	}
 
-	debugfs_create_file("page_owner", 0400, NULL, NULL,
-			    &proc_page_owner_operations);
+	debugfs_create_file("page_owner", 0400, NULL, NULL, &page_owner_fops);
 	dir = debugfs_create_dir("page_owner_stacks", NULL);
 	debugfs_create_file("show_stacks", 0400, dir, NULL,
-			    &page_owner_stack_operations);
+			     &page_owner_stack_fops);
 	debugfs_create_file("count_threshold", 0600, dir, NULL,
-			    &proc_page_owner_threshold);
+			    &page_owner_threshold_fops);
 
 	return 0;
 }
-- 
2.25.1



^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 2/2] mm/page_owner: simplify zone iteration logic in init_early_allocated_pages()
  2025-09-30  9:21 [PATCH 1/2] mm/page_owner: Rename proc-prefixed variables for clarity Hu Song
@ 2025-09-30  9:21 ` Hu Song
  2025-10-01 13:47   ` Vlastimil Babka
  2025-10-02  2:00   ` Ye Liu
  2025-10-01 13:19 ` [PATCH 1/2] mm/page_owner: Rename proc-prefixed variables for clarity Vlastimil Babka
  2025-10-02  1:58 ` Ye Liu
  2 siblings, 2 replies; 6+ messages in thread
From: Hu Song @ 2025-09-30  9:21 UTC (permalink / raw)
  To: Andrew Morton, Vlastimil Babka
  Cc: Song Hu, Suren Baghdasaryan, Michal Hocko, Brendan Jackman,
	Johannes Weiner, Zi Yan, linux-mm, linux-kernel

From: Song Hu <husong@kylinos.cn>

The current implementation uses nested loops: first iterating over all
online nodes, then over zones within each node. This can be simplified
by using the for_each_populated_zone() macro which directly iterates
through all populated zones.

This change:
1. Removes the intermediate init_zones_in_node() function
2. Simplifies init_early_allocated_pages() to use direct zone iteration
3. Updates init_pages_in_zone() to take only zone parameter and access
   node_id via zone->zone_pgdat

The functionality remains identical, but the code is cleaner and more
maintainable.

Signed-off-by: Song Hu <husong@kylinos.cn>
---
 mm/page_owner.c | 23 +++++------------------
 1 file changed, 5 insertions(+), 18 deletions(-)

diff --git a/mm/page_owner.c b/mm/page_owner.c
index bb88b72b6062..b170b27d87a1 100644
--- a/mm/page_owner.c
+++ b/mm/page_owner.c
@@ -757,7 +757,7 @@ static loff_t lseek_page_owner(struct file *file, loff_t offset, int orig)
 	return file->f_pos;
 }
 
-static void init_pages_in_zone(pg_data_t *pgdat, struct zone *zone)
+static void init_pages_in_zone(struct zone *zone)
 {
 	unsigned long pfn = zone->zone_start_pfn;
 	unsigned long end_pfn = zone_end_pfn(zone);
@@ -824,28 +824,15 @@ static void init_pages_in_zone(pg_data_t *pgdat, struct zone *zone)
 	}
 
 	pr_info("Node %d, zone %8s: page owner found early allocated %lu pages\n",
-		pgdat->node_id, zone->name, count);
-}
-
-static void init_zones_in_node(pg_data_t *pgdat)
-{
-	struct zone *zone;
-	struct zone *node_zones = pgdat->node_zones;
-
-	for (zone = node_zones; zone - node_zones < MAX_NR_ZONES; ++zone) {
-		if (!populated_zone(zone))
-			continue;
-
-		init_pages_in_zone(pgdat, zone);
-	}
+		zone->zone_pgdat->node_id, zone->name, count);
 }
 
 static void init_early_allocated_pages(void)
 {
-	pg_data_t *pgdat;
+	struct zone *zone;
 
-	for_each_online_pgdat(pgdat)
-		init_zones_in_node(pgdat);
+	for_each_populated_zone(zone)
+		init_pages_in_zone(zone);
 }
 
 static const struct file_operations page_owner_fops = {
-- 
2.25.1



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/2] mm/page_owner: Rename proc-prefixed variables for clarity
  2025-09-30  9:21 [PATCH 1/2] mm/page_owner: Rename proc-prefixed variables for clarity Hu Song
  2025-09-30  9:21 ` [PATCH 2/2] mm/page_owner: simplify zone iteration logic in init_early_allocated_pages() Hu Song
@ 2025-10-01 13:19 ` Vlastimil Babka
  2025-10-02  1:58 ` Ye Liu
  2 siblings, 0 replies; 6+ messages in thread
From: Vlastimil Babka @ 2025-10-01 13:19 UTC (permalink / raw)
  To: Hu Song, Andrew Morton
  Cc: Suren Baghdasaryan, Michal Hocko, Brendan Jackman,
	Johannes Weiner, Zi Yan, linux-mm, linux-kernel

On 9/30/25 11:21 AM, Hu Song wrote:
> From: Song Hu <husong@kylinos.cn>
> 
> The `proc_page_owner_operations` and related variables were renamed to
> `page_owner_fops` to better reflect their association with `debugfs` rather
> than `/proc`. This improves code clarity and aligns with kernel naming
> conventions.
> 
> Signed-off-by: Song Hu <husong@kylinos.cn>

Acked-by: Vlastimil Babka <vbabka@suse.cz>

how bout going even further and renaming to:

show_stacks_fops
count_threshold_fops

static means we can't collide with other files using the same name so no
need for page_owner prefix everywhere

> ---
>  mm/page_owner.c | 13 ++++++-------
>  1 file changed, 6 insertions(+), 7 deletions(-)
> 
> diff --git a/mm/page_owner.c b/mm/page_owner.c
> index c3ca21132c2c..bb88b72b6062 100644
> --- a/mm/page_owner.c
> +++ b/mm/page_owner.c
> @@ -848,7 +848,7 @@ static void init_early_allocated_pages(void)
>  		init_zones_in_node(pgdat);
>  }
>  
> -static const struct file_operations proc_page_owner_operations = {
> +static const struct file_operations page_owner_fops = {
>  	.read		= read_page_owner,
>  	.llseek		= lseek_page_owner,
>  };
> @@ -929,7 +929,7 @@ static int page_owner_stack_open(struct inode *inode, struct file *file)
>  	return seq_open_private(file, &page_owner_stack_op, 0);
>  }
>  
> -static const struct file_operations page_owner_stack_operations = {
> +static const struct file_operations page_owner_stack_fops = {
>  	.open		= page_owner_stack_open,
>  	.read		= seq_read,
>  	.llseek		= seq_lseek,
> @@ -948,7 +948,7 @@ static int page_owner_threshold_set(void *data, u64 val)
>  	return 0;
>  }
>  
> -DEFINE_SIMPLE_ATTRIBUTE(proc_page_owner_threshold, &page_owner_threshold_get,
> +DEFINE_SIMPLE_ATTRIBUTE(page_owner_threshold_fops, &page_owner_threshold_get,
>  			&page_owner_threshold_set, "%llu");
>  
>  
> @@ -961,13 +961,12 @@ static int __init pageowner_init(void)
>  		return 0;
>  	}
>  
> -	debugfs_create_file("page_owner", 0400, NULL, NULL,
> -			    &proc_page_owner_operations);
> +	debugfs_create_file("page_owner", 0400, NULL, NULL, &page_owner_fops);
>  	dir = debugfs_create_dir("page_owner_stacks", NULL);
>  	debugfs_create_file("show_stacks", 0400, dir, NULL,
> -			    &page_owner_stack_operations);
> +			     &page_owner_stack_fops);
>  	debugfs_create_file("count_threshold", 0600, dir, NULL,
> -			    &proc_page_owner_threshold);
> +			    &page_owner_threshold_fops);
>  
>  	return 0;
>  }



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 2/2] mm/page_owner: simplify zone iteration logic in init_early_allocated_pages()
  2025-09-30  9:21 ` [PATCH 2/2] mm/page_owner: simplify zone iteration logic in init_early_allocated_pages() Hu Song
@ 2025-10-01 13:47   ` Vlastimil Babka
  2025-10-02  2:00   ` Ye Liu
  1 sibling, 0 replies; 6+ messages in thread
From: Vlastimil Babka @ 2025-10-01 13:47 UTC (permalink / raw)
  To: Hu Song, Andrew Morton
  Cc: Suren Baghdasaryan, Michal Hocko, Brendan Jackman,
	Johannes Weiner, Zi Yan, linux-mm, linux-kernel

On 9/30/25 11:21 AM, Hu Song wrote:
> From: Song Hu <husong@kylinos.cn>
> 
> The current implementation uses nested loops: first iterating over all
> online nodes, then over zones within each node. This can be simplified
> by using the for_each_populated_zone() macro which directly iterates
> through all populated zones.
> 
> This change:
> 1. Removes the intermediate init_zones_in_node() function
> 2. Simplifies init_early_allocated_pages() to use direct zone iteration
> 3. Updates init_pages_in_zone() to take only zone parameter and access
>    node_id via zone->zone_pgdat
> 
> The functionality remains identical, but the code is cleaner and more
> maintainable.
> 
> Signed-off-by: Song Hu <husong@kylinos.cn>

LGTM.

Reviewed-by: Vlastimil Babka <vbabka@suse.cz>



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/2] mm/page_owner: Rename proc-prefixed variables for clarity
  2025-09-30  9:21 [PATCH 1/2] mm/page_owner: Rename proc-prefixed variables for clarity Hu Song
  2025-09-30  9:21 ` [PATCH 2/2] mm/page_owner: simplify zone iteration logic in init_early_allocated_pages() Hu Song
  2025-10-01 13:19 ` [PATCH 1/2] mm/page_owner: Rename proc-prefixed variables for clarity Vlastimil Babka
@ 2025-10-02  1:58 ` Ye Liu
  2 siblings, 0 replies; 6+ messages in thread
From: Ye Liu @ 2025-10-02  1:58 UTC (permalink / raw)
  To: Hu Song, Andrew Morton, Vlastimil Babka
  Cc: Suren Baghdasaryan, Michal Hocko, Brendan Jackman,
	Johannes Weiner, Zi Yan, linux-mm, linux-kernel


在 2025/9/30 17:21, Hu Song 写道:
> From: Song Hu <husong@kylinos.cn>
>
> The `proc_page_owner_operations` and related variables were renamed to
> `page_owner_fops` to better reflect their association with `debugfs` rather
> than `/proc`. This improves code clarity and aligns with kernel naming
> conventions.
>
> Signed-off-by: Song Hu <husong@kylinos.cn>


Reviewed-by: Ye Liu <liuye@kylinos.cn>

> ---
>  mm/page_owner.c | 13 ++++++-------
>  1 file changed, 6 insertions(+), 7 deletions(-)
>
> diff --git a/mm/page_owner.c b/mm/page_owner.c
> index c3ca21132c2c..bb88b72b6062 100644
> --- a/mm/page_owner.c
> +++ b/mm/page_owner.c
> @@ -848,7 +848,7 @@ static void init_early_allocated_pages(void)
>  		init_zones_in_node(pgdat);
>  }
>  
> -static const struct file_operations proc_page_owner_operations = {
> +static const struct file_operations page_owner_fops = {
>  	.read		= read_page_owner,
>  	.llseek		= lseek_page_owner,
>  };
> @@ -929,7 +929,7 @@ static int page_owner_stack_open(struct inode *inode, struct file *file)
>  	return seq_open_private(file, &page_owner_stack_op, 0);
>  }
>  
> -static const struct file_operations page_owner_stack_operations = {
> +static const struct file_operations page_owner_stack_fops = {
>  	.open		= page_owner_stack_open,
>  	.read		= seq_read,
>  	.llseek		= seq_lseek,
> @@ -948,7 +948,7 @@ static int page_owner_threshold_set(void *data, u64 val)
>  	return 0;
>  }
>  
> -DEFINE_SIMPLE_ATTRIBUTE(proc_page_owner_threshold, &page_owner_threshold_get,
> +DEFINE_SIMPLE_ATTRIBUTE(page_owner_threshold_fops, &page_owner_threshold_get,
>  			&page_owner_threshold_set, "%llu");
>  
>  
> @@ -961,13 +961,12 @@ static int __init pageowner_init(void)
>  		return 0;
>  	}
>  
> -	debugfs_create_file("page_owner", 0400, NULL, NULL,
> -			    &proc_page_owner_operations);
> +	debugfs_create_file("page_owner", 0400, NULL, NULL, &page_owner_fops);
>  	dir = debugfs_create_dir("page_owner_stacks", NULL);
>  	debugfs_create_file("show_stacks", 0400, dir, NULL,
> -			    &page_owner_stack_operations);
> +			     &page_owner_stack_fops);
>  	debugfs_create_file("count_threshold", 0600, dir, NULL,
> -			    &proc_page_owner_threshold);
> +			    &page_owner_threshold_fops);
>  
>  	return 0;
>  }

-- 
Thanks,
Ye Liu



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 2/2] mm/page_owner: simplify zone iteration logic in init_early_allocated_pages()
  2025-09-30  9:21 ` [PATCH 2/2] mm/page_owner: simplify zone iteration logic in init_early_allocated_pages() Hu Song
  2025-10-01 13:47   ` Vlastimil Babka
@ 2025-10-02  2:00   ` Ye Liu
  1 sibling, 0 replies; 6+ messages in thread
From: Ye Liu @ 2025-10-02  2:00 UTC (permalink / raw)
  To: Hu Song, Andrew Morton, Vlastimil Babka
  Cc: Suren Baghdasaryan, Michal Hocko, Brendan Jackman,
	Johannes Weiner, Zi Yan, linux-mm, linux-kernel


在 2025/9/30 17:21, Hu Song 写道:
> From: Song Hu <husong@kylinos.cn>
>
> The current implementation uses nested loops: first iterating over all
> online nodes, then over zones within each node. This can be simplified
> by using the for_each_populated_zone() macro which directly iterates
> through all populated zones.
>
> This change:
> 1. Removes the intermediate init_zones_in_node() function
> 2. Simplifies init_early_allocated_pages() to use direct zone iteration
> 3. Updates init_pages_in_zone() to take only zone parameter and access
>    node_id via zone->zone_pgdat
>
> The functionality remains identical, but the code is cleaner and more
> maintainable.
>
> Signed-off-by: Song Hu <husong@kylinos.cn>


Reviewed-by: Ye Liu <liuye@kylinos.cn>

> ---
>  mm/page_owner.c | 23 +++++------------------
>  1 file changed, 5 insertions(+), 18 deletions(-)
>
> diff --git a/mm/page_owner.c b/mm/page_owner.c
> index bb88b72b6062..b170b27d87a1 100644
> --- a/mm/page_owner.c
> +++ b/mm/page_owner.c
> @@ -757,7 +757,7 @@ static loff_t lseek_page_owner(struct file *file, loff_t offset, int orig)
>  	return file->f_pos;
>  }
>  
> -static void init_pages_in_zone(pg_data_t *pgdat, struct zone *zone)
> +static void init_pages_in_zone(struct zone *zone)
>  {
>  	unsigned long pfn = zone->zone_start_pfn;
>  	unsigned long end_pfn = zone_end_pfn(zone);
> @@ -824,28 +824,15 @@ static void init_pages_in_zone(pg_data_t *pgdat, struct zone *zone)
>  	}
>  
>  	pr_info("Node %d, zone %8s: page owner found early allocated %lu pages\n",
> -		pgdat->node_id, zone->name, count);
> -}
> -
> -static void init_zones_in_node(pg_data_t *pgdat)
> -{
> -	struct zone *zone;
> -	struct zone *node_zones = pgdat->node_zones;
> -
> -	for (zone = node_zones; zone - node_zones < MAX_NR_ZONES; ++zone) {
> -		if (!populated_zone(zone))
> -			continue;
> -
> -		init_pages_in_zone(pgdat, zone);
> -	}
> +		zone->zone_pgdat->node_id, zone->name, count);
>  }
>  
>  static void init_early_allocated_pages(void)
>  {
> -	pg_data_t *pgdat;
> +	struct zone *zone;
>  
> -	for_each_online_pgdat(pgdat)
> -		init_zones_in_node(pgdat);
> +	for_each_populated_zone(zone)
> +		init_pages_in_zone(zone);
>  }
>  
>  static const struct file_operations page_owner_fops = {

-- 
Thanks,
Ye Liu



^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2025-10-02  2:00 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-09-30  9:21 [PATCH 1/2] mm/page_owner: Rename proc-prefixed variables for clarity Hu Song
2025-09-30  9:21 ` [PATCH 2/2] mm/page_owner: simplify zone iteration logic in init_early_allocated_pages() Hu Song
2025-10-01 13:47   ` Vlastimil Babka
2025-10-02  2:00   ` Ye Liu
2025-10-01 13:19 ` [PATCH 1/2] mm/page_owner: Rename proc-prefixed variables for clarity Vlastimil Babka
2025-10-02  1:58 ` Ye Liu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox