]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
btrfs: avoid unnecessary dev stats updates
authorQu Wenruo <wqu@suse.com>
Tue, 7 Apr 2026 09:34:01 +0000 (19:04 +0930)
committerJohannes Thumshirn <johannes.thumshirn@wdc.com>
Tue, 9 Jun 2026 16:22:45 +0000 (18:22 +0200)
[MINOR PROBLEM]
When mounting a filesystem with a valid DEV_STATS item, we will always
update the DEV_STATS again in the next transaction commit, even if there
is no change the values.

[CAUSE]
During the mount, btrfs_device_init_dev_stats() will read out the
on-disk DEV_STATS item for each device.
Then it calls btrfs_dev_stat_set() to update the in-memory structure.

However btrfs_dev_stat_set() does not only set the dev stats value, but
also increase device->dev_stats_ccnt.

That member determines if we should update the device item at the next
transaction commit. Since we have called btrfs_dev_stat_set() for each
dev status member, dev_stats_ccnt will be non-zero and we will update
the dev stats item even it doesn't change at all.

[FIX]
Instead of using btrfs_dev_stat_set() for valid on-disk DEV_STATUS
values, directly call atomic_set() to set the in-memory values.

For other call sites, we still want to use btrfs_dev_stat_set() so that
we will force updating/creating the dev stats item.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/volumes.c

index 42615e6e799257b3ce46b90a2a544554ab6c1734..4cd9033320f761100940852941798fdf1decfa0f 100644 (file)
@@ -8209,8 +8209,8 @@ static int btrfs_device_init_dev_stats(struct btrfs_device *device,
 
        for (i = 0; i < BTRFS_DEV_STAT_VALUES_MAX; i++) {
                if (item_size >= (1 + i) * sizeof(__le64))
-                       btrfs_dev_stat_set(device, i,
-                                          btrfs_dev_stats_value(eb, ptr, i));
+                       atomic_set(device->dev_stat_values + i,
+                                  btrfs_dev_stats_value(eb, ptr, i));
                else
                        btrfs_dev_stat_set(device, i, 0);
        }