@@ -458,7 +458,7 @@ static void btrfs_submit_dev_bio(struct btrfs_device *dev, struct bio *bio)
* filesystem is fully initialized.
*/
if (dev->fs_devices->collect_fs_stats && bio_op(bio) == REQ_OP_READ && dev->fs_info)
- percpu_counter_add(&dev->fs_devices->stats_read_blocks,
+ percpu_counter_add(&dev->fs_info->stats_read_blocks,
bio->bi_iter.bi_size >> dev->fs_info->sectorsize_bits);
if (bio->bi_opf & REQ_BTRFS_CGROUP_PUNT)
@@ -1258,6 +1258,7 @@ void btrfs_free_fs_info(struct btrfs_fs_info *fs_info)
{
struct percpu_counter *em_counter = &fs_info->evictable_extent_maps;
+ percpu_counter_destroy(&fs_info->stats_read_blocks);
percpu_counter_destroy(&fs_info->dirty_metadata_bytes);
percpu_counter_destroy(&fs_info->delalloc_bytes);
percpu_counter_destroy(&fs_info->ordered_bytes);
@@ -2923,6 +2924,10 @@ static int init_mount_fs_info(struct btrfs_fs_info *fs_info, struct super_block
if (ret)
return ret;
+ ret = percpu_counter_init(&fs_info->stats_read_blocks, 0, GFP_KERNEL);
+ if (ret)
+ return ret;
+
fs_info->dirty_metadata_batch = PAGE_SIZE *
(1 + ilog2(nr_cpu_ids));
@@ -627,6 +627,9 @@ struct btrfs_fs_info {
struct kobject *qgroups_kobj;
struct kobject *discard_kobj;
+ /* Track the number of blocks (sectors) read by the filesystem. */
+ struct percpu_counter stats_read_blocks;
+
/* Used to keep from writing metadata until there is a nice batch */
struct percpu_counter dirty_metadata_bytes;
struct percpu_counter delalloc_bytes;
@@ -1255,7 +1255,6 @@ static void close_fs_devices(struct btrfs_fs_devices *fs_devices)
list_for_each_entry_safe(device, tmp, &fs_devices->devices, dev_list)
btrfs_close_one_device(device);
- percpu_counter_destroy(&fs_devices->stats_read_blocks);
WARN_ON(fs_devices->open_devices);
WARN_ON(fs_devices->rw_devices);
fs_devices->opened = 0;
@@ -1303,11 +1302,6 @@ static int open_fs_devices(struct btrfs_fs_devices *fs_devices,
s64 __maybe_unused value = 0;
int ret = 0;
- /* Initialize the in-memory record of filesystem read count. */
- ret = percpu_counter_init(&fs_devices->stats_read_blocks, 0, GFP_KERNEL);
- if (ret)
- return ret;
-
list_for_each_entry_safe(device, tmp_device, &fs_devices->devices,
dev_list) {
int ret2;
@@ -438,9 +438,6 @@ struct btrfs_fs_devices {
enum btrfs_chunk_allocation_policy chunk_alloc_policy;
- /* Track the number of blocks (sectors) read by the filesystem. */
- struct percpu_counter stats_read_blocks;
-
/* Policy used to read the mirrored stripes. */
enum btrfs_read_policy read_policy;
Move stats_read_blocks from btrfs_fs_devices to btrfs_fs_info and its init and destroy. This is based on the `for-next` branch in the repo github.com/btrfs/linux.git. Fixes: 49136a74162e btrfs: add tracking of read blocks for read policy Signed-off-by: Anand Jain <anand.jain@oracle.com> --- fs/btrfs/bio.c | 2 +- fs/btrfs/disk-io.c | 5 +++++ fs/btrfs/fs.h | 3 +++ fs/btrfs/volumes.c | 6 ------ fs/btrfs/volumes.h | 3 --- 5 files changed, 9 insertions(+), 10 deletions(-)