[RFC PATCH 4/5] md/raid1: use rot policy when no nonrot disk is readable
From: Chen Cheng
Date: Tue Aug 18 2026 - 03:11:30 EST
From: Chen Cheng <chencheng@xxxxxxxxx>
has_nonrot selects mixed policy or rot-only policy.
Current:
1. has_nonrot is true if conf->nonrot_disks > 0.
2. nonrot_disks counts every nonrot disk.
3. A Faulty disk, a rebuild disk, and a WriteMostly disk still
count.
Problem:
1. The array is NVMe + HDD. The NVMe fails. Only the HDD can
take reads.
2. nonrot_disks is still 1. The code thinks this is a mixed
array.
3. Sequential reads on the HDD do not stay on the HDD. Mixed
policy will not keep a rot disk.
4. Every read still advances the nonrot round-robin, though no
nonrot disk can take the read.
Improve:
1. Look at disks that can take this read.
2. If none of them is nonrot, use the rot-only policy.
Signed-off-by: Chen Cheng <chencheng@xxxxxxxxx>
---
drivers/md/raid1.c | 20 +++++++++++++++++++-
1 file changed, 19 insertions(+), 1 deletion(-)
diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
index 523b55d42779..f476d4dea4be 100644
--- a/drivers/md/raid1.c
+++ b/drivers/md/raid1.c
@@ -793,10 +793,28 @@ struct read_balance_ctl {
static int raid1_rr_pos(int disk, int start, int n)
{
return ((disk % n) - start + n) % n;
}
+static bool raid1_has_readable_nonrot(struct r1conf *conf,
+ struct r1bio *r1_bio)
+{
+ int disk;
+
+ for (disk = 0; disk < conf->raid_disks * 2; disk++) {
+ struct md_rdev *rdev;
+
+ if (r1_bio->bios[disk] == IO_BLOCKED)
+ continue;
+ rdev = conf->mirrors[disk].rdev;
+ if (rdev_readable(rdev, r1_bio) &&
+ test_bit(Nonrot, &rdev->flags))
+ return true;
+ }
+ return false;
+}
+
static bool is_better_disk(unsigned int pending, int disk, bool nonrot,
const struct read_balance_ctl *ctl,
int rr_start, int n)
{
if (ctl->min_pending_disk < 0)
@@ -814,11 +832,11 @@ static bool is_better_disk(unsigned int pending, int disk, bool nonrot,
static int choose_best_rdev(struct r1conf *conf, struct r1bio *r1_bio)
{
int disk;
int rr_start = 0;
- bool has_nonrot = READ_ONCE(conf->nonrot_disks);
+ bool has_nonrot = raid1_has_readable_nonrot(conf, r1_bio);
struct read_balance_ctl ctl = {
.closest_dist_disk = -1,
.closest_dist = MaxSector,
.min_pending_disk = -1,
.min_pending = UINT_MAX,
--
2.55.0