Skip to content

Commit be4d328

Browse files
Shaohua Lineilbrown
authored andcommitted
md/raid1: make sequential read detection per disk based
Currently the sequential read detection is global wide. It's natural to make it per disk based, which can improve the detection for concurrent multiple sequential reads. And next patch will make SSD read balance not use distance based algorithm, where this change help detect truly sequential read for SSD. Signed-off-by: Shaohua Li <shli@fusionio.com> Signed-off-by: NeilBrown <neilb@suse.de>
1 parent cc4d1ef commit be4d328

2 files changed

Lines changed: 12 additions & 34 deletions

File tree

‎drivers/md/raid1.c‎

Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -497,9 +497,8 @@ static int read_balance(struct r1conf *conf, struct r1bio *r1_bio, int *max_sect
497497
const sector_t this_sector = r1_bio->sector;
498498
int sectors;
499499
int best_good_sectors;
500-
int start_disk;
501500
int best_disk;
502-
int i;
501+
int disk;
503502
sector_t best_dist;
504503
struct md_rdev *rdev;
505504
int choose_first;
@@ -517,23 +516,16 @@ static int read_balance(struct r1conf *conf, struct r1bio *r1_bio, int *max_sect
517516
best_good_sectors = 0;
518517

519518
if (conf->mddev->recovery_cp < MaxSector &&
520-
(this_sector + sectors >= conf->next_resync)) {
519+
(this_sector + sectors >= conf->next_resync))
521520
choose_first = 1;
522-
start_disk = 0;
523-
} else {
521+
else
524522
choose_first = 0;
525-
start_disk = conf->last_used;
526-
}
527523

528-
for (i = 0 ; i < conf->raid_disks * 2 ; i++) {
524+
for (disk = 0 ; disk < conf->raid_disks * 2 ; disk++) {
529525
sector_t dist;
530526
sector_t first_bad;
531527
int bad_sectors;
532528

533-
int disk = start_disk + i;
534-
if (disk >= conf->raid_disks * 2)
535-
disk -= conf->raid_disks * 2;
536-
537529
rdev = rcu_dereference(conf->mirrors[disk].rdev);
538530
if (r1_bio->bios[disk] == IO_BLOCKED
539531
|| rdev == NULL
@@ -594,7 +586,7 @@ static int read_balance(struct r1conf *conf, struct r1bio *r1_bio, int *max_sect
594586
dist = abs(this_sector - conf->mirrors[disk].head_position);
595587
if (choose_first
596588
/* Don't change to another disk for sequential reads */
597-
|| conf->next_seq_sect == this_sector
589+
|| conf->mirrors[disk].next_seq_sect == this_sector
598590
|| dist == 0
599591
/* If device is idle, use it */
600592
|| atomic_read(&rdev->nr_pending) == 0) {
@@ -620,8 +612,7 @@ static int read_balance(struct r1conf *conf, struct r1bio *r1_bio, int *max_sect
620612
goto retry;
621613
}
622614
sectors = best_good_sectors;
623-
conf->next_seq_sect = this_sector + sectors;
624-
conf->last_used = best_disk;
615+
conf->mirrors[best_disk].next_seq_sect = this_sector + sectors;
625616
}
626617
rcu_read_unlock();
627618
*max_sectors = sectors;
@@ -2599,7 +2590,6 @@ static struct r1conf *setup_conf(struct mddev *mddev)
25992590
conf->recovery_disabled = mddev->recovery_disabled - 1;
26002591

26012592
err = -EIO;
2602-
conf->last_used = -1;
26032593
for (i = 0; i < conf->raid_disks * 2; i++) {
26042594

26052595
disk = conf->mirrors + i;
@@ -2625,19 +2615,9 @@ static struct r1conf *setup_conf(struct mddev *mddev)
26252615
if (disk->rdev &&
26262616
(disk->rdev->saved_raid_disk < 0))
26272617
conf->fullsync = 1;
2628-
} else if (conf->last_used < 0)
2629-
/*
2630-
* The first working device is used as a
2631-
* starting point to read balancing.
2632-
*/
2633-
conf->last_used = i;
2618+
}
26342619
}
26352620

2636-
if (conf->last_used < 0) {
2637-
printk(KERN_ERR "md/raid1:%s: no operational mirrors\n",
2638-
mdname(mddev));
2639-
goto abort;
2640-
}
26412621
err = -ENOMEM;
26422622
conf->thread = md_register_thread(raid1d, mddev, "raid1");
26432623
if (!conf->thread) {
@@ -2894,7 +2874,6 @@ static int raid1_reshape(struct mddev *mddev)
28942874
conf->raid_disks = mddev->raid_disks = raid_disks;
28952875
mddev->delta_disks = 0;
28962876

2897-
conf->last_used = 0; /* just make sure it is in-range */
28982877
lower_barrier(conf);
28992878

29002879
set_bit(MD_RECOVERY_NEEDED, &mddev->recovery);

‎drivers/md/raid1.h‎

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
struct raid1_info {
55
struct md_rdev *rdev;
66
sector_t head_position;
7+
8+
/* When choose the best device for a read (read_balance())
9+
* we try to keep sequential reads one the same device
10+
*/
11+
sector_t next_seq_sect;
712
};
813

914
/*
@@ -29,12 +34,6 @@ struct r1conf {
2934
*/
3035
int raid_disks;
3136

32-
/* When choose the best device for a read (read_balance())
33-
* we try to keep sequential reads one the same device
34-
* using 'last_used' and 'next_seq_sect'
35-
*/
36-
int last_used;
37-
sector_t next_seq_sect;
3837
/* During resync, read_balancing is only allowed on the part
3938
* of the array that has been resynced. 'next_resync' tells us
4039
* where that is.

0 commit comments

Comments
 (0)