[PATCH] block: annotate the approximate block device page count
From: Zhu Jun
Date: Wed Nov 11 2026 - 01:49:48 EST
nr_blockdev_pages() holds the superblock inode list lock while summing
mapping->nrpages. Page-cache updates use the mapping's XArray lock, so the
list lock does not exclude those updates and KCSAN reports the read.
The total is an approximate memory statistic. Annotate the intentional
lockless read with data_race(), leaving page-cache synchronization to its
existing locks.
Fixes: 1da177e4c3f41 ("Linux-2.6.12-rc2")
Signed-off-by: Zhu Jun <zhujun2@xxxxxxxxxxxxxxxxxxxx>
---
block/bdev.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/block/bdev.c b/block/bdev.c
index f20f91b3176e..cae291d4893c 100644
--- a/block/bdev.c
+++ b/block/bdev.c
@@ -564,8 +564,10 @@ long nr_blockdev_pages(void)
long ret = 0;
spin_lock(&blockdev_superblock->s_inode_list_lock);
- list_for_each_entry(inode, &blockdev_superblock->s_inodes, i_sb_list)
- ret += inode->i_mapping->nrpages;
+ list_for_each_entry(inode, &blockdev_superblock->s_inodes, i_sb_list) {
+ /* This is an approximate snapshot, without the XArray lock. */
+ ret += data_race(inode->i_mapping->nrpages);
+ }
spin_unlock(&blockdev_superblock->s_inode_list_lock);
return ret;
--
2.51.0