]> 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>
Thu, 31 Mar 2022 21:12:19 +0000 (17:12 -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>
(cherry picked from commit 0af07493e90d9063dabbb9321069ff05d88c45be)
(cherry picked from commit add8cfb279582377df7ea987ef693e38144558e8)
(cherry picked from commit e297545942b115296b3fb2fb5dcb5063c1912af7)
(cherry picked from commit 106dfbf574af39271e8bb7d0e06a69cb9c03e5e8)

fs/btrfs/volumes.c

index 9d8aa3347c741d99242c1fa76a5a4c920f311d81..437089707fa9c4ff387a0da16b4d017ee50280ac 100644 (file)
@@ -308,6 +308,9 @@ struct list_head *btrfs_get_fs_uuids(void)
        return &fs_uuids;
 }
 
+/* Used for round-robin balancing RAID1/RAID10 reads. */
+atomic_t rr_counter = ATOMIC_INIT(0);
+
 /*
  * alloc_fs_devices - allocate struct btrfs_fs_devices
  * @fsid:              if not NULL, copy the UUID to fs_devices::fsid
@@ -5585,7 +5588,7 @@ static int find_live_mirror(struct btrfs_fs_info *fs_info,
        else
                num_stripes = map->num_stripes;
 
-       preferred_mirror = first + current->pid % num_stripes;
+       preferred_mirror = first + (unsigned)atomic_inc_return(&rr_counter) % num_stripes;
 
        if (dev_replace_is_ongoing &&
            fs_info->dev_replace.cont_reading_from_srcdev_mode ==