Skip to contentSkip to conversation

mm/vmstat: avoid taking zone lock in /proc/buddyinfo reads

PATCH Applied Imran Khan 6 participants 8 messages Jun 4 – Jun 29

Subsystems (2)
lore
Share & tools
lore

Imran Khan

author
#0 lore raw

PATCH 1/1 mm/vmstat: avoid taking zone lock in /proc/buddyinfo reads

frag_show_print() just reads zone->free_area[order].nr_free, so it can safely do this without needing the zone->lock.

Pass nolock=true from frag_show(), so that walk_zones_in_node() can skip the zone->lock acquisition.

---
 mm/vmstat.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mm/vmstat.c +1 -1
index f534972f517de..7b93fbf9af092 100644
@@ -1568,7 +1568,7 @@ static void frag_show_print(struct seq_file *m, pg_data_t *pgdat,
 static int frag_show(struct seq_file *m, void *arg)
 {
 	pg_data_t *pgdat = (pg_data_t *)arg;
-	walk_zones_in_node(m, pgdat, true, false, frag_show_print);
+	walk_zones_in_node(m, pgdat, true, true, frag_show_print);
 	return 0;
 }
 

base-commit: e43ffb69e0438cddd72aaa30898b4dc446f664f8

Signature · 1 line
2.34.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 5 lines · On Thu, 4 Jun 2026 21:42:45 +0800 Imran Khan <[email protected]> wrote:

frag_show_print() just reads zone->free_area[order].nr_free, so it can safely do this without needing the zone->lock.

Pass nolock=true from frag_show(), so that walk_zones_in_node() can skip the zone->lock acquisition.

Hello Imran, thank you for the patch!

Seems reasonable to me, and I think this sentiment was already explicitly encoded in a comment block in frag_show_print:

		/*
		 * Access to nr_free is lockless as nr_free is used only for
		 * printing purposes. Use data_race to avoid KCSAN warning.
		 */
		seq_printf(m, "%6lu ", data_race(zone->free_area[order].nr_free));

Plus, we have a data_race() here so it seems like lockless reading was always the intent anyways. So:

Digging into this a bit more, I did find something worth noting.

Commit af1c31acc85325 "mm/vmstat: annotate data race for zone->free_area[order].nr_free" was the commit that added the data_race() here, in response to a KCSAN report. But looking into it, I don't think KCSAN was reporting a data race for this callsite, it was actually reporting it for a different one in extfrag_for_order->fill_contig_page_info. Maybe the author there added the data_race() for frag_show_print just to be safe as well, even though at the time it was protected by a zone->lock anyways.

Just something I thought was interesting to note. Thanks again! Joshua

Quoted 22 lines
---
 mm/vmstat.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mm/vmstat.c +1 -1
index f534972f517de..7b93fbf9af092 100644
@@ -1568,7 +1568,7 @@ static void frag_show_print(struct seq_file *m, pg_data_t *pgdat,
 static int frag_show(struct seq_file *m, void *arg)
 {
 	pg_data_t *pgdat = (pg_data_t *)arg;
-	walk_zones_in_node(m, pgdat, true, false, frag_show_print);
+	walk_zones_in_node(m, pgdat, true, true, frag_show_print);
 	return 0;
 }
 

base-commit: e43ffb69e0438cddd72aaa30898b4dc446f664f8

Signature · 1 line
2.34.1
reviewer Acked-by on v1 1/1
#2 lore raw
In reply to Imran Khan
Quoted 7 lines · Imran Khan

frag_show_print() just reads zone->free_area[order].nr_free, so it can safely do this without needing the zone->lock.

Pass nolock=true from frag_show(), so that walk_zones_in_node() can skip the zone->lock acquisition.

Quoted 19 lines
---
 mm/vmstat.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mm/vmstat.c +1 -1
index f534972f517de..7b93fbf9af092 100644
@@ -1568,7 +1568,7 @@ static void frag_show_print(struct seq_file *m, pg_data_t *pgdat,
 static int frag_show(struct seq_file *m, void *arg)
 {
 	pg_data_t *pgdat = (pg_data_t *)arg;
-	walk_zones_in_node(m, pgdat, true, false, frag_show_print);
+	walk_zones_in_node(m, pgdat, true, true, frag_show_print);
 	return 0;
 }
 

base-commit: e43ffb69e0438cddd72aaa30898b4dc446f664f8

reviewer Reviewed-by on v1 1/1
#3 lore raw
In reply to Imran Khan
Quoted 7 lines · Imran Khan

frag_show_print() just reads zone->free_area[order].nr_free, so it can safely do this without needing the zone->lock.

Pass nolock=true from frag_show(), so that walk_zones_in_node() can skip the zone->lock acquisition.

LGTM, so:

Quoted 18 lines
---
 mm/vmstat.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mm/vmstat.c +1 -1
index f534972f517de..7b93fbf9af092 100644
@@ -1568,7 +1568,7 @@ static void frag_show_print(struct seq_file *m, pg_data_t *pgdat,
 static int frag_show(struct seq_file *m, void *arg)
 {
 	pg_data_t *pgdat = (pg_data_t *)arg;
-	walk_zones_in_node(m, pgdat, true, false, frag_show_print);
+	walk_zones_in_node(m, pgdat, true, true, frag_show_print);
 	return 0;
 }
 
Quoted 4 lines

base-commit: e43ffb69e0438cddd72aaa30898b4dc446f664f8 --
2.34.1

Cheers, Lorenzo

#4 lore raw
In reply to Imran Khan

Hi Andrew,

I think this one got missed last cycle? I don't see it in any mm- tree, and has a bunch of tags.

I guess Imran will need to resend it at -rc1?

Cheers, Lorenzo

Quoted 29 lines · Imran Khan

frag_show_print() just reads zone->free_area[order].nr_free, so it can safely do this without needing the zone->lock.

Pass nolock=true from frag_show(), so that walk_zones_in_node() can skip the zone->lock acquisition.

---
 mm/vmstat.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mm/vmstat.c +1 -1
index f534972f517de..7b93fbf9af092 100644
@@ -1568,7 +1568,7 @@ static void frag_show_print(struct seq_file *m, pg_data_t *pgdat,
 static int frag_show(struct seq_file *m, void *arg)
 {
 	pg_data_t *pgdat = (pg_data_t *)arg;
-	walk_zones_in_node(m, pgdat, true, false, frag_show_print);
+	walk_zones_in_node(m, pgdat, true, true, frag_show_print);
 	return 0;
 }
 

base-commit: e43ffb69e0438cddd72aaa30898b4dc446f664f8 --
2.34.1

maintainer
#5 lore raw
Quoted 2 lines · On Wed, 24 Jun 2026 08:16:50 +0100 Lorenzo Stoakes <[email protected]> wrote:

I think this one got missed last cycle? I don't see it in any mm- tree, and has a bunch of tags.

It arrived during -rc6 and isn't a bugfix so I put it in the "next -rc1" pile.

Quoted 1 line

I guess Imran will need to resend it at -rc1?

Got it now. Thanks, all.

#6 lore raw
Quoted 11 lines · Andrew Morton
Quoted 2 lines · On Wed, 24 Jun 2026 08:16:50 +0100 Lorenzo Stoakes <[email protected]> wrote:

I think this one got missed last cycle? I don't see it in any mm- tree, and has a bunch of tags.

It arrived during -rc6 and isn't a bugfix so I put it in the "next -rc1" pile.

Quoted 1 line

I guess Imran will need to resend it at -rc1?

Got it now. Thanks, all.

Ack thanks! :)

Cheers, Lorenzo