]> git.hungrycats.org Git - linux/commitdiff
btrfs: balance RAID1/RAID10 mirror selection
authorlouis@waffle.tech <louis@waffle.tech>
Fri, 16 Oct 2020 05:59:19 +0000 (05:59 +0000)
committerZygo Blaxell <ce3g8jdj@umail.furryterror.org>
Fri, 18 Sep 2026 21:36:33 +0000 (17:36 -0400)
Balance RAID1/RAID10 mirror selection via plain round-robin scheduling. This should roughly double throughput for large reads.

Signed-off-by: Louis Jencka <louis@waffle.tech>
fs/btrfs/volumes.c

index 6a59b9a2cd479c7199e41afdb66fda6eab370b93..1188378742d0fb422501d5dba999b5f3d661d5fe 100644 (file)
@@ -369,6 +369,9 @@ struct list_head * __attribute_const__ btrfs_get_fs_uuids(void)
        return &fs_uuids;
 }
 
+/* Used for round-robin balancing RAID1/RAID10 reads. */
+atomic_t rr_counter = ATOMIC_INIT(0);
+
 /*
  * Allocate new btrfs_fs_devices structure identified by a fsid.
  *
@@ -6788,7 +6791,8 @@ static int find_live_mirror(struct btrfs_fs_info *fs_info,
                WRITE_ONCE(fs_info->fs_devices->read_policy, BTRFS_READ_POLICY_PID);
                fallthrough;
        case BTRFS_READ_POLICY_PID:
-               preferred_mirror = first + (current->pid % num_stripes);
+               preferred_mirror = first +
+                   (unsigned)atomic_inc_return(&rr_counter) % num_stripes;
                break;
 #ifdef CONFIG_BTRFS_EXPERIMENTAL
        case BTRFS_READ_POLICY_RR: