Skip to content

Commit 2c27d09

Browse files
YuKuai-huaweiliu-song-6
authored andcommitted
md/raid1: record nonrot rdevs while adding/removing rdevs to conf
For raid1, each read will iterate all the rdevs from conf and check if any rdev is non-rotational, then choose rdev with minimal IO inflight if so, or rdev with closest distance otherwise. Disk nonrot info can be changed through sysfs entry: /sys/block/[disk_name]/queue/rotational However, consider that this should only be used for testing, and user really shouldn't do this in real life. Record the number of non-rotational disks in conf, to avoid checking each rdev in IO fast path and simplify read_balance() a little bit. Co-developed-by: Paul Luse <[email protected]> Signed-off-by: Paul Luse <[email protected]> Signed-off-by: Yu Kuai <[email protected]> Signed-off-by: Song Liu <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 969d658 commit 2c27d09

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

drivers/md/md.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ enum flag_bits {
207207
* check if there is collision between raid1
208208
* serial bios.
209209
*/
210+
Nonrot, /* non-rotational device (SSD) */
210211
};
211212

212213
static inline int is_badblock(struct md_rdev *rdev, sector_t s, int sectors,

drivers/md/raid1.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,6 @@ static int read_balance(struct r1conf *conf, struct r1bio *r1_bio, int *max_sect
599599
int sectors;
600600
int best_good_sectors;
601601
int best_disk, best_dist_disk, best_pending_disk;
602-
int has_nonrot_disk;
603602
int disk;
604603
sector_t best_dist;
605604
unsigned int min_pending;
@@ -620,7 +619,6 @@ static int read_balance(struct r1conf *conf, struct r1bio *r1_bio, int *max_sect
620619
best_pending_disk = -1;
621620
min_pending = UINT_MAX;
622621
best_good_sectors = 0;
623-
has_nonrot_disk = 0;
624622
choose_next_idle = 0;
625623
clear_bit(R1BIO_FailFast, &r1_bio->state);
626624

@@ -637,7 +635,6 @@ static int read_balance(struct r1conf *conf, struct r1bio *r1_bio, int *max_sect
637635
sector_t first_bad;
638636
int bad_sectors;
639637
unsigned int pending;
640-
bool nonrot;
641638

642639
rdev = conf->mirrors[disk].rdev;
643640
if (r1_bio->bios[disk] == IO_BLOCKED
@@ -703,8 +700,6 @@ static int read_balance(struct r1conf *conf, struct r1bio *r1_bio, int *max_sect
703700
/* At least two disks to choose from so failfast is OK */
704701
set_bit(R1BIO_FailFast, &r1_bio->state);
705702

706-
nonrot = bdev_nonrot(rdev->bdev);
707-
has_nonrot_disk |= nonrot;
708703
pending = atomic_read(&rdev->nr_pending);
709704
dist = abs(this_sector - conf->mirrors[disk].head_position);
710705
if (choose_first) {
@@ -731,7 +726,7 @@ static int read_balance(struct r1conf *conf, struct r1bio *r1_bio, int *max_sect
731726
* small, but not a big deal since when the second disk
732727
* starts IO, the first disk is likely still busy.
733728
*/
734-
if (nonrot && opt_iosize > 0 &&
729+
if (test_bit(Nonrot, &rdev->flags) && opt_iosize > 0 &&
735730
mirror->seq_start != MaxSector &&
736731
mirror->next_seq_sect > opt_iosize &&
737732
mirror->next_seq_sect - opt_iosize >=
@@ -763,7 +758,7 @@ static int read_balance(struct r1conf *conf, struct r1bio *r1_bio, int *max_sect
763758
* mixed ratation/non-rotational disks depending on workload.
764759
*/
765760
if (best_disk == -1) {
766-
if (has_nonrot_disk || min_pending == 0)
761+
if (READ_ONCE(conf->nonrot_disks) || min_pending == 0)
767762
best_disk = best_pending_disk;
768763
else
769764
best_disk = best_dist_disk;
@@ -1768,6 +1763,11 @@ static bool raid1_add_conf(struct r1conf *conf, struct md_rdev *rdev, int disk,
17681763
if (info->rdev)
17691764
return false;
17701765

1766+
if (bdev_nonrot(rdev->bdev)) {
1767+
set_bit(Nonrot, &rdev->flags);
1768+
WRITE_ONCE(conf->nonrot_disks, conf->nonrot_disks + 1);
1769+
}
1770+
17711771
rdev->raid_disk = disk;
17721772
info->head_position = 0;
17731773
info->seq_start = MaxSector;
@@ -1791,6 +1791,9 @@ static bool raid1_remove_conf(struct r1conf *conf, int disk)
17911791
rdev->mddev->degraded < conf->raid_disks)
17921792
return false;
17931793

1794+
if (test_and_clear_bit(Nonrot, &rdev->flags))
1795+
WRITE_ONCE(conf->nonrot_disks, conf->nonrot_disks - 1);
1796+
17941797
WRITE_ONCE(info->rdev, NULL);
17951798
return true;
17961799
}

drivers/md/raid1.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ struct r1conf {
7171
* allow for replacements.
7272
*/
7373
int raid_disks;
74+
int nonrot_disks;
7475

7576
spinlock_t device_lock;
7677

0 commit comments

Comments
 (0)