All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] btrfs: migrate tracking read blocks from fs_devices to
@ 2025-01-08 21:01 Anand Jain
  2025-01-08 21:01 ` [PATCH 1/2] fixup: btrfs: add tracking of read blocks for read policy Anand Jain
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Anand Jain @ 2025-01-08 21:01 UTC (permalink / raw)
  To: linux-btrfs, dsterba

David reported btrfs/161 failing during sprouted filesystem unmount.
Bisected to commit 49136a74162e ("btrfs: add tracking of read blocks
for read policy"). Now, tracking is moved from `fs_devices` to `fs_info`.

Tested to be working fine.

-----
FSTYP         -- btrfs
PLATFORM      -- Linux/aarch64 local 6.13.0-rc6+ #45 SMP PREEMPT_DYNAMIC Thu Jan  9 04:04:07 +08 2025
MKFS_OPTIONS  -- /dev/sdb
MOUNT_OPTIONS -- -o context=system_u:object_r:root_t:s0 /dev/sdb /mnt/scratch

btrfs/161 0s ...  0s
Ran: btrfs/161
Passed all 1 tests
------

Patches should be folded into their respective commits. Thx.

Anand Jain (2):
  fixup: btrfs: add tracking of read blocks for read policy
  fixup: btrfs: introduce RAID1 round-robin read balancing

 fs/btrfs/bio.c     |  2 +-
 fs/btrfs/disk-io.c |  5 +++++
 fs/btrfs/fs.h      |  3 +++
 fs/btrfs/volumes.c | 17 ++++++-----------
 fs/btrfs/volumes.h |  3 ---
 5 files changed, 15 insertions(+), 15 deletions(-)

-- 
2.47.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/2] fixup: btrfs: add tracking of read blocks for read policy
  2025-01-08 21:01 [PATCH 0/2] btrfs: migrate tracking read blocks from fs_devices to Anand Jain
@ 2025-01-08 21:01 ` Anand Jain
  2025-01-08 21:01 ` [PATCH 2/2] fixup: btrfs: introduce RAID1 round-robin read balancing Anand Jain
  2025-01-09 10:17 ` [PATCH 0/2] btrfs: migrate tracking read blocks from fs_devices to David Sterba
  2 siblings, 0 replies; 4+ messages in thread
From: Anand Jain @ 2025-01-08 21:01 UTC (permalink / raw)
  To: linux-btrfs, dsterba

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(-)

diff --git a/fs/btrfs/bio.c b/fs/btrfs/bio.c
index afff205ef671..bc2555c44a12 100644
--- a/fs/btrfs/bio.c
+++ b/fs/btrfs/bio.c
@@ -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)
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index 4928bf2cd07f..ef3121b55c50 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -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));
 
diff --git a/fs/btrfs/fs.h b/fs/btrfs/fs.h
index be8c32d1a7bb..b572d6b9730b 100644
--- a/fs/btrfs/fs.h
+++ b/fs/btrfs/fs.h
@@ -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;
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index c02d551b73a7..e0c64246f8f6 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -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;
diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h
index f197e152f318..120f65e21eeb 100644
--- a/fs/btrfs/volumes.h
+++ b/fs/btrfs/volumes.h
@@ -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;
 
-- 
2.47.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/2] fixup: btrfs: introduce RAID1 round-robin read balancing
  2025-01-08 21:01 [PATCH 0/2] btrfs: migrate tracking read blocks from fs_devices to Anand Jain
  2025-01-08 21:01 ` [PATCH 1/2] fixup: btrfs: add tracking of read blocks for read policy Anand Jain
@ 2025-01-08 21:01 ` Anand Jain
  2025-01-09 10:17 ` [PATCH 0/2] btrfs: migrate tracking read blocks from fs_devices to David Sterba
  2 siblings, 0 replies; 4+ messages in thread
From: Anand Jain @ 2025-01-08 21:01 UTC (permalink / raw)
  To: linux-btrfs, dsterba

The member stats_read_blocks has been moved to fs_info, so update its
usage accordingly in btrfs_read_rr().

This is based on the `for-next` branch in the repo github.com/btrfs/linux.git.

Fixes: ee37a901a9d2 btrfs: introduce RAID1 round-robin read balancing
Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
 fs/btrfs/volumes.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index e0c64246f8f6..a594f66daedf 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -6018,21 +6018,22 @@ static int btrfs_read_rr(const struct btrfs_chunk_map *map, int first, int num_s
 {
 	struct stripe_mirror stripes[BTRFS_RAID1_MAX_MIRRORS] = { 0 };
 	struct btrfs_device *device  = map->stripes[first].dev;
-	struct btrfs_fs_devices *fs_devices = device->fs_devices;
+	struct btrfs_fs_info *fs_info = device->fs_devices->fs_info;
 	unsigned int read_cycle;
 	unsigned int total_reads;
 	unsigned int min_reads_per_dev;
 
-	total_reads = percpu_counter_sum(&fs_devices->stats_read_blocks);
-	min_reads_per_dev = READ_ONCE(fs_devices->rr_min_contig_read) >>
-			    fs_devices->fs_info->sectorsize_bits;
+	total_reads = percpu_counter_sum(&fs_info->stats_read_blocks);
+	min_reads_per_dev = READ_ONCE(fs_info->fs_devices->rr_min_contig_read) >>
+						       fs_info->sectorsize_bits;
 
 	for (int index = 0, i = first; i < first + num_stripes; i++) {
 		stripes[index].devid = map->stripes[i].dev->devid;
 		stripes[index].num = i;
 		index++;
 	}
-	sort(stripes, num_stripes, sizeof(struct stripe_mirror), btrfs_cmp_devid, NULL);
+	sort(stripes, num_stripes, sizeof(struct stripe_mirror),
+	     btrfs_cmp_devid, NULL);
 
 	read_cycle = total_reads / min_reads_per_dev;
 	return stripes[read_cycle % num_stripes].num;
-- 
2.47.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 0/2] btrfs: migrate tracking read blocks from fs_devices to
  2025-01-08 21:01 [PATCH 0/2] btrfs: migrate tracking read blocks from fs_devices to Anand Jain
  2025-01-08 21:01 ` [PATCH 1/2] fixup: btrfs: add tracking of read blocks for read policy Anand Jain
  2025-01-08 21:01 ` [PATCH 2/2] fixup: btrfs: introduce RAID1 round-robin read balancing Anand Jain
@ 2025-01-09 10:17 ` David Sterba
  2 siblings, 0 replies; 4+ messages in thread
From: David Sterba @ 2025-01-09 10:17 UTC (permalink / raw)
  To: Anand Jain; +Cc: linux-btrfs, dsterba

On Thu, Jan 09, 2025 at 05:01:34AM +0800, Anand Jain wrote:
> David reported btrfs/161 failing during sprouted filesystem unmount.
> Bisected to commit 49136a74162e ("btrfs: add tracking of read blocks
> for read policy"). Now, tracking is moved from `fs_devices` to `fs_info`.
> 
> Tested to be working fine.

Thanks, updated in for-next.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-01-09 10:18 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-01-08 21:01 [PATCH 0/2] btrfs: migrate tracking read blocks from fs_devices to Anand Jain
2025-01-08 21:01 ` [PATCH 1/2] fixup: btrfs: add tracking of read blocks for read policy Anand Jain
2025-01-08 21:01 ` [PATCH 2/2] fixup: btrfs: introduce RAID1 round-robin read balancing Anand Jain
2025-01-09 10:17 ` [PATCH 0/2] btrfs: migrate tracking read blocks from fs_devices to David Sterba

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.