Skip to contentSkip to conversation

memblock: use for_each_zone() in reset_all_zones_managed_pages()

PATCH Applied Sang-Heon Jeon 2 participants 7 messages Sep 8 – Sep 15

Subsystems (2)

v1 of 2 Applied Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 memblock: use for_each_zone() in reset_all_zones_managed_pages()

reset_all_zones_managed_pages() iterates over the zones of every online node with a nested loop. for_each_zone() iterates over the same zones in the same order.

So use for_each_zone() instead and remove reset_node_managed_pages().

No functional change.

---
 mm/memblock.c | 12 ++----------
 1 file changed, 2 insertions(+), 10 deletions(-)
mm/memblock.c +2 -10
index 4302fb4ab85c..ed6937be8d9f 100644
@@ -2465,22 +2465,14 @@ static unsigned long __init free_low_memory_core_early(void)
 	return count;
 }
 
-static void __init reset_node_managed_pages(pg_data_t *pgdat)
+static void __init reset_all_zones_managed_pages(void)
 {
 	struct zone *z;
 
-	for (z = pgdat->node_zones; z < pgdat->node_zones + MAX_NR_ZONES; z++)
+	for_each_zone(z)
 		atomic_long_set(&z->managed_pages, 0);
 }
 
-static void __init reset_all_zones_managed_pages(void)
-{
-	struct pglist_data *pgdat;
-
-	for_each_online_pgdat(pgdat)
-		reset_node_managed_pages(pgdat);
-}
-
 /**
  * memblock_free_all - release free pages to the buddy allocator
  */

base-commit: dbffc67777cd752ef3f77818109e1d2ef13e2949

Signature · 1 line
2.43.0
maintainer Applied
#1 lore raw
Quoted 1 line · Sang-Heon Jeon

memblock: use for_each_zone() in reset_all_zones_managed_pages()

Applied to for-next branch of memblock.git tree, thanks!

[1/1] memblock: use for_each_zone() in reset_all_zones_managed_pages()

      commit: 0876b2d8794913c867a1bb0dc3fd22ea1c5f0a95

tree: https://git.kernel.org/pub/scm/linux/kernel/git/rppt/memblock
branch: for-next

--
Sincerely yours,
Mike.

maintainer
#2 lore raw
Quoted 10 lines · Mike Rapoport
Quoted 1 line · Sang-Heon Jeon

memblock: use for_each_zone() in reset_all_zones_managed_pages()

Applied to for-next branch of memblock.git tree, thanks!

[1/1] memblock: use for_each_zone() in reset_all_zones_managed_pages()

      commit: 0876b2d8794913c867a1bb0dc3fd22ea1c5f0a95

tree: https://git.kernel.org/pub/scm/linux/kernel/git/rppt/memblock
branch: for-next

Hmm, I was too hasty.
This breaks mmemblock tests, so I dropped it for now.

Quoted 8 lines

--
Sincerely yours,
Mike.

#3 lore raw
Quoted 7 lines · Mike Rapoport
Quoted 5 lines · Mike Rapoport
Quoted 1 line · Sang-Heon Jeon

memblock: use for_each_zone() in reset_all_zones_managed_pages()

Applied to for-next branch of memblock.git tree, thanks!

Quoted 8 lines
Quoted 5 lines

[1/1] memblock: use for_each_zone() in reset_all_zones_managed_pages()

      commit: 0876b2d8794913c867a1bb0dc3fd22ea1c5f0a95

tree: https://git.kernel.org/pub/scm/linux/kernel/git/rppt/memblock
branch: for-next

Hmm, I was too hasty.
This breaks mmemblock tests, so I dropped it for now.

Sorry for the noise. I missed it. I will keep it in mind next time. Just give me a second to check.

Quoted 10 lines
Quoted 8 lines

--
Sincerely yours,
Mike.

Best regards
Sang-Heon Jeon

#4 lore raw
Quoted 12 lines · Sang-Heon Jeon
Quoted 10 lines · Mike Rapoport
Quoted 8 lines · Mike Rapoport
Quoted 1 line · Sang-Heon Jeon

memblock: use for_each_zone() in reset_all_zones_managed_pages()

Applied to for-next branch of memblock.git tree, thanks!

[1/1] memblock: use for_each_zone() in reset_all_zones_managed_pages()

      commit: 0876b2d8794913c867a1bb0dc3fd22ea1c5f0a95
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

tree: https://git.kernel.org/pub/scm/linux/kernel/git/rppt/memblock
branch: for-next

Hmm, I was too hasty.
This breaks mmemblock tests, so I dropped it for now.

Sorry for the noise. I missed it. I will keep it in mind next time. Just give me a second to check.

With the below fixes, tests will be fine again. Is it okay to send the v2 patchset with below fixes?

(quoted diff) +0 -0

b/tools/testing/memblock/linux/mmzone.h
index 8d934ff5b080..631fe07923e7 100644

tools/testing/memblock/linux/mmzone.h +8 -0
@@ -7,13 +7,20 @@
 
 struct pglist_data *first_online_pgdat(void);
 struct pglist_data *next_online_pgdat(struct pglist_data *pgdat);
+struct zone *next_zone(struct zone *zone);
 
 #define for_each_online_pgdat(pgdat)                   \
        for (pgdat = first_online_pgdat();              \
             pgdat;                                     \
             pgdat = next_online_pgdat(pgdat))
 
+#define for_each_zone(zone)                            \
+       for (zone = (first_online_pgdat())->node_zones; \
+            zone;                                      \
+            zone = next_zone(zone))
+
 enum zone_type {
+       ZONE_NORMAL,
        __MAX_NR_ZONES
 };
 
@@ -27,6 +34,7 @@ enum zone_type {
 #define pageblock_start_pfn(pfn)       ALIGN_DOWN((pfn), pageblock_nr_pages)
 
 struct zone {
+       struct pglist_data      *zone_pgdat;
        atomic_long_t           managed_pages;
 };
 
tools/testing/memblock/mmzone.c +7 -1
index e719450f81cb..e73848bdc8d6 100644
@@ -1,9 +1,15 @@
 // SPDX-License-Identifier: GPL-2.0-or-later
 #include <linux/mmzone.h>
 
+static pg_data_t dummy_pgdat = {
+       .node_zones = {
+               [0 ... MAX_NR_ZONES - 1] = { .zone_pgdat = &dummy_pgdat },
+       },
+};
+
 struct pglist_data *first_online_pgdat(void)
 {
-       return NULL;
+       return &dummy_pgdat;
 }
 
 struct pglist_data *next_online_pgdat(struct pglist_data *pgdat)
@@ -11,6 +17,22 @@ struct pglist_data *next_online_pgdat(struct

pglist_data *pgdat)

        return NULL;

}

+struct zone *next_zone(struct zone *zone)
+{
+ pg_data_t *pgdat = zone->zone_pgdat;
+
+ if (zone < pgdat->node_zones + MAX_NR_ZONES - 1)
+ zone++;
+ else {
+ pgdat = next_online_pgdat(pgdat);
+ if (pgdat)
+ zone = pgdat->node_zones;
+ else
+ zone = NULL;
+ }
+ return zone;
+}
+
void atomic_long_set(atomic_long_t *v, long i)
{
}

Quoted 11 lines
Quoted 10 lines
Quoted 8 lines

--
Sincerely yours,
Mike.

Quoted 2 lines

Best regards
Sang-Heon Jeon

Best regards,
Sang-Heon Jeon

maintainer
#5 lore raw
Quoted 16 lines · Sang-Heon Jeon
Quoted 15 lines · Sang-Heon Jeon
Quoted 13 lines · Mike Rapoport
Quoted 10 lines · Mike Rapoport
Quoted 1 line · Sang-Heon Jeon

memblock: use for_each_zone() in reset_all_zones_managed_pages()

Applied to for-next branch of memblock.git tree, thanks!

[1/1] memblock: use for_each_zone() in reset_all_zones_managed_pages()

      commit: 0876b2d8794913c867a1bb0dc3fd22ea1c5f0a95

tree: https://git.kernel.org/pub/scm/linux/kernel/git/rppt/memblock
branch: for-next

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

Hmm, I was too hasty.
This breaks mmemblock tests, so I dropped it for now.

Sorry for the noise. I missed it. I will keep it in mind next time. Just give me a second to check.

With the below fixes, tests will be fine again. Is it okay to send the v2 patchset with below fixes?

memblock tests do not cover late parts of mm initialization, I believe it would be fine to just define for_each_zone() to a nop.

Quoted 96 lines
tools/testing/memblock/linux/mmzone.h +8 -0
index 8d934ff5b080..631fe07923e7 100644
@@ -7,13 +7,20 @@
 
 struct pglist_data *first_online_pgdat(void);
 struct pglist_data *next_online_pgdat(struct pglist_data *pgdat);
+struct zone *next_zone(struct zone *zone);
 
 #define for_each_online_pgdat(pgdat)                   \
        for (pgdat = first_online_pgdat();              \
             pgdat;                                     \
             pgdat = next_online_pgdat(pgdat))
 
+#define for_each_zone(zone)                            \
+       for (zone = (first_online_pgdat())->node_zones; \
+            zone;                                      \
+            zone = next_zone(zone))
+
 enum zone_type {
+       ZONE_NORMAL,
        __MAX_NR_ZONES
 };
 
@@ -27,6 +34,7 @@ enum zone_type {
 #define pageblock_start_pfn(pfn)       ALIGN_DOWN((pfn), pageblock_nr_pages)
 
 struct zone {
+       struct pglist_data      *zone_pgdat;
        atomic_long_t           managed_pages;
 };
 
tools/testing/memblock/mmzone.c +23 -1
index e719450f81cb..e73848bdc8d6 100644
@@ -1,9 +1,15 @@
 // SPDX-License-Identifier: GPL-2.0-or-later
 #include <linux/mmzone.h>
 
+static pg_data_t dummy_pgdat = {
+       .node_zones = {
+               [0 ... MAX_NR_ZONES - 1] = { .zone_pgdat = &dummy_pgdat },
+       },
+};
+
 struct pglist_data *first_online_pgdat(void)
 {
-       return NULL;
+       return &dummy_pgdat;
 }
 
 struct pglist_data *next_online_pgdat(struct pglist_data *pgdat)
@@ -11,6 +17,22 @@ struct pglist_data *next_online_pgdat(struct
 pglist_data *pgdat)
        return NULL;
 }
 
+struct zone *next_zone(struct zone *zone)
+{
+       pg_data_t *pgdat = zone->zone_pgdat;
+
+       if (zone < pgdat->node_zones + MAX_NR_ZONES - 1)
+               zone++;
+       else {
+               pgdat = next_online_pgdat(pgdat);
+               if (pgdat)
+                       zone = pgdat->node_zones;
+               else
+                       zone = NULL;
+       }
+       return zone;
+}
+
 void atomic_long_set(atomic_long_t *v, long i)
 {

}

Quoted 11 lines
Quoted 10 lines
Quoted 8 lines

--
Sincerely yours,
Mike.

Quoted 2 lines

Best regards
Sang-Heon Jeon

Best regards,
Sang-Heon Jeon

Signature · 2 lines
Sincerely yours,
Mike.
#6 lore raw
Quoted 21 lines · Mike Rapoport
Quoted 19 lines · Sang-Heon Jeon
Quoted 18 lines · Sang-Heon Jeon
Quoted 15 lines · Mike Rapoport
Quoted 10 lines · Mike Rapoport
Quoted 1 line · Sang-Heon Jeon

memblock: use for_each_zone() in reset_all_zones_managed_pages()

Applied to for-next branch of memblock.git tree, thanks!

[1/1] memblock: use for_each_zone() in reset_all_zones_managed_pages()

      commit: 0876b2d8794913c867a1bb0dc3fd22ea1c5f0a95

tree: https://git.kernel.org/pub/scm/linux/kernel/git/rppt/memblock
branch: for-next

Hmm, I was too hasty.
This breaks mmemblock tests, so I dropped it for now.

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

Sorry for the noise. I missed it. I will keep it in mind next time. Just give me a second to check.

With the below fixes, tests will be fine again. Is it okay to send the v2 patchset with below fixes?

memblock tests do not cover late parts of mm initialization, I believe it would be fine to just define for_each_zone() to a nop.

Thanks for the review, Mike. I'll send a v2 soon.

Quoted 94 lines
Quoted 94 lines
tools/testing/memblock/linux/mmzone.h +8 -0
index 8d934ff5b080..631fe07923e7 100644
@@ -7,13 +7,20 @@
 
 struct pglist_data *first_online_pgdat(void);
 struct pglist_data *next_online_pgdat(struct pglist_data *pgdat);
+struct zone *next_zone(struct zone *zone);
 
 #define for_each_online_pgdat(pgdat)                   \
        for (pgdat = first_online_pgdat();              \
             pgdat;                                     \
             pgdat = next_online_pgdat(pgdat))
 
+#define for_each_zone(zone)                            \
+       for (zone = (first_online_pgdat())->node_zones; \
+            zone;                                      \
+            zone = next_zone(zone))
+
 enum zone_type {
+       ZONE_NORMAL,
        __MAX_NR_ZONES
 };
 
@@ -27,6 +34,7 @@ enum zone_type {
 #define pageblock_start_pfn(pfn)       ALIGN_DOWN((pfn), pageblock_nr_pages)
 
 struct zone {
+       struct pglist_data      *zone_pgdat;
        atomic_long_t           managed_pages;
 };
 
tools/testing/memblock/mmzone.c +23 -1
index e719450f81cb..e73848bdc8d6 100644
@@ -1,9 +1,15 @@
 // SPDX-License-Identifier: GPL-2.0-or-later
 #include <linux/mmzone.h>
 
+static pg_data_t dummy_pgdat = {
+       .node_zones = {
+               [0 ... MAX_NR_ZONES - 1] = { .zone_pgdat = &dummy_pgdat },
+       },
+};
+
 struct pglist_data *first_online_pgdat(void)
 {
-       return NULL;
+       return &dummy_pgdat;
 }
 
 struct pglist_data *next_online_pgdat(struct pglist_data *pgdat)
@@ -11,6 +17,22 @@ struct pglist_data *next_online_pgdat(struct
 pglist_data *pgdat)
        return NULL;
 }
 
+struct zone *next_zone(struct zone *zone)
+{
+       pg_data_t *pgdat = zone->zone_pgdat;
+
+       if (zone < pgdat->node_zones + MAX_NR_ZONES - 1)
+               zone++;
+       else {
+               pgdat = next_online_pgdat(pgdat);
+               if (pgdat)
+                       zone = pgdat->node_zones;
+               else
+                       zone = NULL;
+       }
+       return zone;
+}
+
 void atomic_long_set(atomic_long_t *v, long i)
 {

}

Quoted 13 lines
Quoted 10 lines
Quoted 8 lines

--
Sincerely yours,
Mike.

Best regards
Sang-Heon Jeon

Quoted 6 lines
Quoted 2 lines

Best regards,
Sang-Heon Jeon

--
Sincerely yours,
Mike.

Best regards,
Sang-Heon Jeon