Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

mm/page_owner: simplify zone iteration logic in init_early_allocated_pages()

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.

Link: https://lkml.kernel.org/r/20250930092153.843109-2-husong@kylinos.cn
Signed-off-by: Song Hu <husong@kylinos.cn>
Reviewed-by: Vlastimil Babka <vbabka@suse.cz>
Reviewed-by: Ye Liu <liuye@kylinos.cn>
Acked-by: Vlastimil Babka <vbabka@suse.cz>
Cc: Brendan Jackman <jackmanb@google.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Suren Baghdasaryan <surenb@google.com>
Cc: Zi Yan <ziy@nvidia.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Song Hu and committed by
Andrew Morton
ca30ac47 9686080d

+5 -18
+5 -18
mm/page_owner.c
··· 769 769 return file->f_pos; 770 770 } 771 771 772 - static void init_pages_in_zone(pg_data_t *pgdat, struct zone *zone) 772 + static void init_pages_in_zone(struct zone *zone) 773 773 { 774 774 unsigned long pfn = zone->zone_start_pfn; 775 775 unsigned long end_pfn = zone_end_pfn(zone); ··· 836 836 } 837 837 838 838 pr_info("Node %d, zone %8s: page owner found early allocated %lu pages\n", 839 - pgdat->node_id, zone->name, count); 840 - } 841 - 842 - static void init_zones_in_node(pg_data_t *pgdat) 843 - { 844 - struct zone *zone; 845 - struct zone *node_zones = pgdat->node_zones; 846 - 847 - for (zone = node_zones; zone - node_zones < MAX_NR_ZONES; ++zone) { 848 - if (!populated_zone(zone)) 849 - continue; 850 - 851 - init_pages_in_zone(pgdat, zone); 852 - } 839 + zone->zone_pgdat->node_id, zone->name, count); 853 840 } 854 841 855 842 static void init_early_allocated_pages(void) 856 843 { 857 - pg_data_t *pgdat; 844 + struct zone *zone; 858 845 859 - for_each_online_pgdat(pgdat) 860 - init_zones_in_node(pgdat); 846 + for_each_populated_zone(zone) 847 + init_pages_in_zone(zone); 861 848 } 862 849 863 850 static const struct file_operations page_owner_fops = {