reset_node_present_pages() only get called in hotadd_init_pgdat(), move
the action that clear present pages to free_area_init_core_hotplug(), so
the helper can be removed.
Signed-off-by: Haifeng Xu <[email protected]>
---
mm/memory_hotplug.c | 18 ------------------
mm/mm_init.c | 14 ++++++++++++--
2 files changed, 12 insertions(+), 20 deletions(-)
diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c
index 65e385f34679..ee1c0d9a4d5a 100644
--- a/mm/memory_hotplug.c
+++ b/mm/memory_hotplug.c
@@ -1172,16 +1172,6 @@ int __ref online_pages(unsigned long pfn, unsigned long nr_pages,
return ret;
}
-static void reset_node_present_pages(pg_data_t *pgdat)
-{
- struct zone *z;
-
- for (z = pgdat->node_zones; z < pgdat->node_zones + MAX_NR_ZONES; z++)
- z->present_pages = 0;
-
- pgdat->node_present_pages = 0;
-}
-
/* we are OK calling __meminit stuff here - we have CONFIG_MEMORY_HOTPLUG */
static pg_data_t __ref *hotadd_init_pgdat(int nid)
{
@@ -1204,14 +1194,6 @@ static pg_data_t __ref *hotadd_init_pgdat(int nid)
*/
build_all_zonelists(pgdat);
- /*
- * When memory is hot-added, all the memory is in offline state. So
- * clear all zones' present_pages because they will be updated in
- * online_pages() and offline_pages().
- * TODO: should be in free_area_init_core_hotplug?
- */
- reset_node_present_pages(pgdat);
-
return pgdat;
}
diff --git a/mm/mm_init.c b/mm/mm_init.c
index 78e67041ae9f..e24ea1db9e26 100644
--- a/mm/mm_init.c
+++ b/mm/mm_init.c
@@ -1491,6 +1491,7 @@ void __ref free_area_init_core_hotplug(struct pglist_data *pgdat)
{
int nid = pgdat->node_id;
enum zone_type z;
+ struct zone *zone;
int cpu;
pgdat_init_internals(pgdat);
@@ -1507,6 +1508,8 @@ void __ref free_area_init_core_hotplug(struct pglist_data *pgdat)
pgdat->kswapd_order = 0;
pgdat->kswapd_highest_zoneidx = 0;
pgdat->node_start_pfn = 0;
+ pgdat->node_present_pages = 0;
+
for_each_online_cpu(cpu) {
struct per_cpu_nodestat *p;
@@ -1514,8 +1517,15 @@ void __ref free_area_init_core_hotplug(struct pglist_data *pgdat)
memset(p, 0, sizeof(*p));
}
- for (z = 0; z < MAX_NR_ZONES; z++)
- zone_init_internals(&pgdat->node_zones[z], z, nid, 0);
+ /* When memory is hot-added, all the memory is in offline state. So
+ * clear all zones' present_pages and managed_pages because they will
+ * be updated in online_pages() and offline_pages().
+ */
+ for (z = 0; z < MAX_NR_ZONES; z++) {
+ zone = &pgdat->node_zones[z];
+ zone->present_pages = 0;
+ zone_init_internals(zone, z, nid, 0);
+ }
}
#endif
--
2.25.1
On 01.06.23 18:26, Haifeng Xu wrote:
> reset_node_present_pages() only get called in hotadd_init_pgdat(), move
> the action that clear present pages to free_area_init_core_hotplug(), so
> the helper can be removed.
>
> Signed-off-by: Haifeng Xu <[email protected]>
> ---
[...]
> diff --git a/mm/mm_init.c b/mm/mm_init.c
> index 78e67041ae9f..e24ea1db9e26 100644
> --- a/mm/mm_init.c
> +++ b/mm/mm_init.c
> @@ -1491,6 +1491,7 @@ void __ref free_area_init_core_hotplug(struct pglist_data *pgdat)
> {
> int nid = pgdat->node_id;
> enum zone_type z;
> + struct zone *zone;
You can declare that within the for loop.
> int cpu;
>
> pgdat_init_internals(pgdat);
> @@ -1507,6 +1508,8 @@ void __ref free_area_init_core_hotplug(struct pglist_data *pgdat)
> pgdat->kswapd_order = 0;
> pgdat->kswapd_highest_zoneidx = 0;
> pgdat->node_start_pfn = 0;
> + pgdat->node_present_pages = 0;
> +
> for_each_online_cpu(cpu) {
> struct per_cpu_nodestat *p;
>
> @@ -1514,8 +1517,15 @@ void __ref free_area_init_core_hotplug(struct pglist_data *pgdat)
> memset(p, 0, sizeof(*p));
> }
>
> - for (z = 0; z < MAX_NR_ZONES; z++)
> - zone_init_internals(&pgdat->node_zones[z], z, nid, 0);
> + /* When memory is hot-added, all the memory is in offline state. So
/*
* When ...
> + * clear all zones' present_pages and managed_pages because they will
> + * be updated in online_pages() and offline_pages().
> + */
> + for (z = 0; z < MAX_NR_ZONES; z++) {
> + zone = &pgdat->node_zones[z];
Too bad we don't have something like node_zone(pgdat, z)
Might be a reasonable cleanup staring at "git grep "pgdat->node_zones""
output ...
> + zone->present_pages = 0;
> + zone_init_internals(zone, z, nid, 0);
> + }
> }
> #endif
>
In general,
Acked-by: David Hildenbrand <[email protected]>
--
Thanks,
David / dhildenb
reset_node_present_pages() only get called in hotadd_init_pgdat(), move
the action that clear present pages to free_area_init_core_hotplug(), so
the helper can be removed.
Signed-off-by: Haifeng Xu <[email protected]>
Suggested-by: David Hildenbrand <[email protected]>
---
v2:
- declare 'struct zone' within the for loop
- fix comment layout
---
mm/memory_hotplug.c | 18 ------------------
mm/mm_init.c | 15 +++++++++++++--
2 files changed, 13 insertions(+), 20 deletions(-)
diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c
index 65e385f34679..ee1c0d9a4d5a 100644
--- a/mm/memory_hotplug.c
+++ b/mm/memory_hotplug.c
@@ -1172,16 +1172,6 @@ int __ref online_pages(unsigned long pfn, unsigned long nr_pages,
return ret;
}
-static void reset_node_present_pages(pg_data_t *pgdat)
-{
- struct zone *z;
-
- for (z = pgdat->node_zones; z < pgdat->node_zones + MAX_NR_ZONES; z++)
- z->present_pages = 0;
-
- pgdat->node_present_pages = 0;
-}
-
/* we are OK calling __meminit stuff here - we have CONFIG_MEMORY_HOTPLUG */
static pg_data_t __ref *hotadd_init_pgdat(int nid)
{
@@ -1204,14 +1194,6 @@ static pg_data_t __ref *hotadd_init_pgdat(int nid)
*/
build_all_zonelists(pgdat);
- /*
- * When memory is hot-added, all the memory is in offline state. So
- * clear all zones' present_pages because they will be updated in
- * online_pages() and offline_pages().
- * TODO: should be in free_area_init_core_hotplug?
- */
- reset_node_present_pages(pgdat);
-
return pgdat;
}
diff --git a/mm/mm_init.c b/mm/mm_init.c
index 78e67041ae9f..a02ba9a79b3d 100644
--- a/mm/mm_init.c
+++ b/mm/mm_init.c
@@ -1507,6 +1507,8 @@ void __ref free_area_init_core_hotplug(struct pglist_data *pgdat)
pgdat->kswapd_order = 0;
pgdat->kswapd_highest_zoneidx = 0;
pgdat->node_start_pfn = 0;
+ pgdat->node_present_pages = 0;
+
for_each_online_cpu(cpu) {
struct per_cpu_nodestat *p;
@@ -1514,8 +1516,17 @@ void __ref free_area_init_core_hotplug(struct pglist_data *pgdat)
memset(p, 0, sizeof(*p));
}
- for (z = 0; z < MAX_NR_ZONES; z++)
- zone_init_internals(&pgdat->node_zones[z], z, nid, 0);
+ /*
+ * When memory is hot-added, all the memory is in offline state. So
+ * clear all zones' present_pages and managed_pages because they will
+ * be updated in online_pages() and offline_pages().
+ */
+ for (z = 0; z < MAX_NR_ZONES; z++) {
+ struct zone *zone = pgdat->node_zones + z;
+
+ zone->present_pages = 0;
+ zone_init_internals(zone, z, nid, 0);
+ }
}
#endif
--
2.25.1
On Wed 07-06-23 02:50:56, Haifeng Xu wrote:
> reset_node_present_pages() only get called in hotadd_init_pgdat(), move
> the action that clear present pages to free_area_init_core_hotplug(), so
> the helper can be removed.
There is no explanation why moving the action is desirable and/or
needed. I do agree that removing this trivial helper which only has a
single caller. I guess the incentive is an overal simplification but
please spell that out.
> Signed-off-by: Haifeng Xu <[email protected]>
> Suggested-by: David Hildenbrand <[email protected]>
The patch itself makes sense
Acked-by: Michal Hocko <[email protected]>
> ---
> v2:
> - declare 'struct zone' within the for loop
> - fix comment layout
> ---
> mm/memory_hotplug.c | 18 ------------------
> mm/mm_init.c | 15 +++++++++++++--
> 2 files changed, 13 insertions(+), 20 deletions(-)
>
> diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c
> index 65e385f34679..ee1c0d9a4d5a 100644
> --- a/mm/memory_hotplug.c
> +++ b/mm/memory_hotplug.c
> @@ -1172,16 +1172,6 @@ int __ref online_pages(unsigned long pfn, unsigned long nr_pages,
> return ret;
> }
>
> -static void reset_node_present_pages(pg_data_t *pgdat)
> -{
> - struct zone *z;
> -
> - for (z = pgdat->node_zones; z < pgdat->node_zones + MAX_NR_ZONES; z++)
> - z->present_pages = 0;
> -
> - pgdat->node_present_pages = 0;
> -}
> -
> /* we are OK calling __meminit stuff here - we have CONFIG_MEMORY_HOTPLUG */
> static pg_data_t __ref *hotadd_init_pgdat(int nid)
> {
> @@ -1204,14 +1194,6 @@ static pg_data_t __ref *hotadd_init_pgdat(int nid)
> */
> build_all_zonelists(pgdat);
>
> - /*
> - * When memory is hot-added, all the memory is in offline state. So
> - * clear all zones' present_pages because they will be updated in
> - * online_pages() and offline_pages().
> - * TODO: should be in free_area_init_core_hotplug?
> - */
> - reset_node_present_pages(pgdat);
> -
> return pgdat;
> }
>
> diff --git a/mm/mm_init.c b/mm/mm_init.c
> index 78e67041ae9f..a02ba9a79b3d 100644
> --- a/mm/mm_init.c
> +++ b/mm/mm_init.c
> @@ -1507,6 +1507,8 @@ void __ref free_area_init_core_hotplug(struct pglist_data *pgdat)
> pgdat->kswapd_order = 0;
> pgdat->kswapd_highest_zoneidx = 0;
> pgdat->node_start_pfn = 0;
> + pgdat->node_present_pages = 0;
> +
> for_each_online_cpu(cpu) {
> struct per_cpu_nodestat *p;
>
> @@ -1514,8 +1516,17 @@ void __ref free_area_init_core_hotplug(struct pglist_data *pgdat)
> memset(p, 0, sizeof(*p));
> }
>
> - for (z = 0; z < MAX_NR_ZONES; z++)
> - zone_init_internals(&pgdat->node_zones[z], z, nid, 0);
> + /*
> + * When memory is hot-added, all the memory is in offline state. So
> + * clear all zones' present_pages and managed_pages because they will
> + * be updated in online_pages() and offline_pages().
> + */
> + for (z = 0; z < MAX_NR_ZONES; z++) {
> + struct zone *zone = pgdat->node_zones + z;
> +
> + zone->present_pages = 0;
> + zone_init_internals(zone, z, nid, 0);
> + }
> }
> #endif
>
> --
> 2.25.1
--
Michal Hocko
SUSE Labs
On 07.06.23 04:50, Haifeng Xu wrote:
> reset_node_present_pages() only get called in hotadd_init_pgdat(), move
> the action that clear present pages to free_area_init_core_hotplug(), so
> the helper can be removed.
>
> Signed-off-by: Haifeng Xu <[email protected]>
> Suggested-by: David Hildenbrand <[email protected]>
> ---
> v2:
> - declare 'struct zone' within the for loop
> - fix comment layout
> ---
> mm/memory_hotplug.c | 18 ------------------
> mm/mm_init.c | 15 +++++++++++++--
> 2 files changed, 13 insertions(+), 20 deletions(-)
As Michal said, we could be clearer that this simplifies the code (and
removes a TODO).
Reviewed-by: David Hildenbrand <[email protected]>
--
Cheers,
David / dhildenb