mm/vmstat: avoid taking zone lock in /proc/buddyinfo reads
Subsystems (2)
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
@@ -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
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 thezone->lock.Pass nolock=true from
frag_show(), so thatwalk_zones_in_node()can skip thezone->lockacquisition.
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
Signed-off-by Imran Khan <[email protected]>--- mm/vmstat.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)mm/vmstat.c +1
-1@@ -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:
e43ffb69e0438cddd72aaa30898b4dc446f664f8Signature · 1 line
2.34.1
Quoted 7 lines · Imran Khan
frag_show_print()just reads zone->free_area[order].nr_free, so it can safely do this without needing thezone->lock.Pass nolock=true from
frag_show(), so thatwalk_zones_in_node()can skip thezone->lockacquisition.Signed-off-by Imran Khan <[email protected]>
Quoted 19 lines
--- mm/vmstat.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)mm/vmstat.c +1
-1@@ -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
Quoted 7 lines · Imran Khan
frag_show_print()just reads zone->free_area[order].nr_free, so it can safely do this without needing thezone->lock.Pass nolock=true from
frag_show(), so thatwalk_zones_in_node()can skip thezone->lockacquisition.Signed-off-by Imran Khan <[email protected]>
LGTM, so:
Quoted 18 lines
--- mm/vmstat.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)mm/vmstat.c +1
-1@@ -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
Lorenzo Stoakes
reviewerHi 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 thezone->lock.Pass nolock=true from
frag_show(), so thatwalk_zones_in_node()can skip thezone->lockacquisition.Signed-off-by Imran Khan <[email protected]>--- mm/vmstat.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)mm/vmstat.c +1
-1@@ -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
Andrew Morton
maintainerQuoted 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.
Lorenzo Stoakes
reviewerQuoted 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
Quoted 8 lines · Imran Khan
frag_show_print()just reads zone->free_area[order].nr_free, so it can safely do this without needing thezone->lock.Pass nolock=true from
frag_show(), so thatwalk_zones_in_node()can skip thezone->lockacquisition.Signed-off-by Imran Khan <[email protected]>---
Signature · 3 lines
Cheers, David