]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
btrfs: report reclaim stats in sysfs
authorBoris Burkov <boris@bur.io>
Thu, 25 Jan 2024 22:10:30 +0000 (14:10 -0800)
committerDavid Sterba <dsterba@suse.com>
Thu, 11 Jul 2024 13:33:27 +0000 (15:33 +0200)
When evaluating various reclaim strategies/thresholds against each
other, it is useful to collect data about the amount of reclaim
happening. Expose a count, error count, and byte count via sysfs
per space_info.

Note that this is only for automatic reclaim, not manually invoked
balances or other codepaths that use "relocate_block_group"

Reviewed-by: Josef Bacik <josef@toxicpanda.com>
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: Boris Burkov <boris@bur.io>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/block-group.c
fs/btrfs/space-info.h
fs/btrfs/sysfs.c

index db666f9807eae4ab2ce29b436d63e033f4e09f72..b530302b469d5882a98c19fcb26a1e6bb4b0baa1 100644 (file)
@@ -1829,6 +1829,7 @@ void btrfs_reclaim_bgs_work(struct work_struct *work)
        list_sort(NULL, &fs_info->reclaim_bgs, reclaim_bgs_cmp);
        while (!list_empty(&fs_info->reclaim_bgs)) {
                u64 zone_unusable;
+               u64 reclaimed;
                int ret = 0;
 
                bg = list_first_entry(&fs_info->reclaim_bgs,
@@ -1921,12 +1922,21 @@ void btrfs_reclaim_bgs_work(struct work_struct *work)
                                div64_u64(bg->used * 100, bg->length),
                                div64_u64(zone_unusable * 100, bg->length));
                trace_btrfs_reclaim_block_group(bg);
+               reclaimed = bg->used;
                ret = btrfs_relocate_chunk(fs_info, bg->start);
                if (ret) {
                        btrfs_dec_block_group_ro(bg);
                        btrfs_err(fs_info, "error relocating chunk %llu",
                                  bg->start);
+                       reclaimed = 0;
+                       spin_lock(&space_info->lock);
+                       space_info->reclaim_errors++;
+                       spin_unlock(&space_info->lock);
                }
+               spin_lock(&space_info->lock);
+               space_info->reclaim_count++;
+               space_info->reclaim_bytes += reclaimed;
+               spin_unlock(&space_info->lock);
 
 next:
                if (ret) {
index a733458fd13b35e14c6c74ddd0a024583eb13af5..98ea35ae60fe0eeb47439d90a11618a24ee7d166 100644 (file)
@@ -165,6 +165,24 @@ struct btrfs_space_info {
 
        struct kobject kobj;
        struct kobject *block_group_kobjs[BTRFS_NR_RAID_TYPES];
+
+       /*
+        * Monotonically increasing counter of block group reclaim attempts
+        * Exposed in /sys/fs/<uuid>/allocation/<type>/reclaim_count
+        */
+       u64 reclaim_count;
+
+       /*
+        * Monotonically increasing counter of reclaimed bytes
+        * Exposed in /sys/fs/<uuid>/allocation/<type>/reclaim_bytes
+        */
+       u64 reclaim_bytes;
+
+       /*
+        * Monotonically increasing counter of reclaim errors
+        * Exposed in /sys/fs/<uuid>/allocation/<type>/reclaim_errors
+        */
+       u64 reclaim_errors;
 };
 
 struct reserve_ticket {
index af545b6b1190e3e9b28284da3b5b0873e4bbabb4..919c7ba4512175a5ba24a24954de487b2e8cca3c 100644 (file)
@@ -894,6 +894,9 @@ SPACE_INFO_ATTR(bytes_readonly);
 SPACE_INFO_ATTR(bytes_zone_unusable);
 SPACE_INFO_ATTR(disk_used);
 SPACE_INFO_ATTR(disk_total);
+SPACE_INFO_ATTR(reclaim_count);
+SPACE_INFO_ATTR(reclaim_bytes);
+SPACE_INFO_ATTR(reclaim_errors);
 BTRFS_ATTR_RW(space_info, chunk_size, btrfs_chunk_size_show, btrfs_chunk_size_store);
 BTRFS_ATTR(space_info, size_classes, btrfs_size_classes_show);
 
@@ -949,6 +952,9 @@ static struct attribute *space_info_attrs[] = {
        BTRFS_ATTR_PTR(space_info, bg_reclaim_threshold),
        BTRFS_ATTR_PTR(space_info, chunk_size),
        BTRFS_ATTR_PTR(space_info, size_classes),
+       BTRFS_ATTR_PTR(space_info, reclaim_count),
+       BTRFS_ATTR_PTR(space_info, reclaim_bytes),
+       BTRFS_ATTR_PTR(space_info, reclaim_errors),
 #ifdef CONFIG_BTRFS_DEBUG
        BTRFS_ATTR_PTR(space_info, force_chunk_alloc),
 #endif