Skip to content

Commit f51d46d

Browse files
Vishal Vermaliu-song-6
Vishal Verma
authored andcommitted
md: add support for REQ_NOWAIT
commit 021a244 ("block: add QUEUE_FLAG_NOWAIT") added support for checking whether a given bdev supports handling of REQ_NOWAIT or not. Since then commit 6abc494 ("dm: add support for REQ_NOWAIT and enable it for linear target") added support for REQ_NOWAIT for dm. This uses a similar approach to incorporate REQ_NOWAIT for md based bios. This patch was tested using t/io_uring tool within FIO. A nvme drive was partitioned into 2 partitions and a simple raid 0 configuration /dev/md0 was created. md0 : active raid0 nvme4n1p1[1] nvme4n1p2[0] 937423872 blocks super 1.2 512k chunks Before patch: $ ./t/io_uring /dev/md0 -p 0 -a 0 -d 1 -r 100 Running top while the above runs: $ ps -eL | grep $(pidof io_uring) 38396 38396 pts/2 00:00:00 io_uring 38396 38397 pts/2 00:00:15 io_uring 38396 38398 pts/2 00:00:13 iou-wrk-38397 We can see iou-wrk-38397 io worker thread created which gets created when io_uring sees that the underlying device (/dev/md0 in this case) doesn't support nowait. After patch: $ ./t/io_uring /dev/md0 -p 0 -a 0 -d 1 -r 100 Running top while the above runs: $ ps -eL | grep $(pidof io_uring) 38341 38341 pts/2 00:10:22 io_uring 38341 38342 pts/2 00:10:37 io_uring After running this patch, we don't see any io worker thread being created which indicated that io_uring saw that the underlying device does support nowait. This is the exact behaviour noticed on a dm device which also supports nowait. For all the other raid personalities except raid0, we would need to train pieces which involves make_request fn in order for them to correctly handle REQ_NOWAIT. Reviewed-by: Jens Axboe <[email protected]> Signed-off-by: Vishal Verma <[email protected]> Signed-off-by: Song Liu <[email protected]>
1 parent a92ce0f commit f51d46d

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

drivers/md/md.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,12 @@ void md_handle_request(struct mddev *mddev, struct bio *bio)
418418
rcu_read_lock();
419419
if (is_suspended(mddev, bio)) {
420420
DEFINE_WAIT(__wait);
421+
/* Bail out if REQ_NOWAIT is set for the bio */
422+
if (bio->bi_opf & REQ_NOWAIT) {
423+
rcu_read_unlock();
424+
bio_wouldblock_error(bio);
425+
return;
426+
}
421427
for (;;) {
422428
prepare_to_wait(&mddev->sb_wait, &__wait,
423429
TASK_UNINTERRUPTIBLE);
@@ -5787,6 +5793,7 @@ int md_run(struct mddev *mddev)
57875793
int err;
57885794
struct md_rdev *rdev;
57895795
struct md_personality *pers;
5796+
bool nowait = true;
57905797

57915798
if (list_empty(&mddev->disks))
57925799
/* cannot run an array with no devices.. */
@@ -5857,8 +5864,13 @@ int md_run(struct mddev *mddev)
58575864
}
58585865
}
58595866
sysfs_notify_dirent_safe(rdev->sysfs_state);
5867+
nowait = nowait && blk_queue_nowait(bdev_get_queue(rdev->bdev));
58605868
}
58615869

5870+
/* Set the NOWAIT flags if all underlying devices support it */
5871+
if (nowait)
5872+
blk_queue_flag_set(QUEUE_FLAG_NOWAIT, mddev->queue);
5873+
58625874
if (!bioset_initialized(&mddev->bio_set)) {
58635875
err = bioset_init(&mddev->bio_set, BIO_POOL_SIZE, 0, BIOSET_NEED_BVECS);
58645876
if (err)
@@ -7002,6 +7014,15 @@ static int hot_add_disk(struct mddev *mddev, dev_t dev)
70027014
set_bit(MD_SB_CHANGE_DEVS, &mddev->sb_flags);
70037015
if (!mddev->thread)
70047016
md_update_sb(mddev, 1);
7017+
/*
7018+
* If the new disk does not support REQ_NOWAIT,
7019+
* disable on the whole MD.
7020+
*/
7021+
if (!blk_queue_nowait(bdev_get_queue(rdev->bdev))) {
7022+
pr_info("%s: Disabling nowait because %s does not support nowait\n",
7023+
mdname(mddev), bdevname(rdev->bdev, b));
7024+
blk_queue_flag_clear(QUEUE_FLAG_NOWAIT, mddev->queue);
7025+
}
70057026
/*
70067027
* Kick recovery, maybe this spare has to be added to the
70077028
* array immediately.

0 commit comments

Comments
 (0)