Skip to contentSkip to conversation

md: remove REQ_NOWAIT support

PATCH Applied Abd-Alrhman Masalkhi 3 participants 5 messages Jun 28 – Jul 30 MD RAID

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 md: remove REQ_NOWAIT support

REQ_NOWAIT support in md is fundamentally incomplete. While reads can avoid some blocking paths, write requests can still encounter cases where one mirror succeeds while another returns -EAGAIN. At that point md cannot distinguish queue pressure from a real device failure, so it can neither record a bad block nor safely retry the write without REQ_NOWAIT, leaving mirrors with divergent data.

Rather than continue advertising REQ_NOWAIT support that cannot be implemented correctly, remove it from md and its raid personalities. This simplifies the waiting paths and avoids exposing incorrect non-blocking semantics.

Fixes bf2c411bb1cf ("md: raid456 add nowait support")
Fixes c9aa889b035f ("md: raid10 add nowait support")
Fixes 5aa705039c4f ("md: raid1 add nowait support")
Fixes f51d46d0e7cb ("md: add support for REQ_NOWAIT")
---
 drivers/md/md-bitmap.c   |  9 +---
 drivers/md/md-bitmap.h   |  2 +-
 drivers/md/md-llbitmap.c | 10 +----
 drivers/md/md.c          | 15 ++-----
 drivers/md/raid1-10.c    |  8 ++--
 drivers/md/raid1.c       | 91 +++++++++-------------------------------
 drivers/md/raid10.c      | 80 +++++++++--------------------------
 drivers/md/raid5.c       | 13 ------
 8 files changed, 51 insertions(+), 177 deletions(-)
drivers/md/md-bitmap.c +2 -7
index 0f02e2956398..7d778fe1c47c 100644
@@ -2064,23 +2064,18 @@ static void bitmap_end_behind_write(struct mddev *mddev)
 		 bitmap->mddev->bitmap_info.max_write_behind);
 }
 
-static bool bitmap_wait_behind_writes(struct mddev *mddev, bool nowait)
+static void bitmap_wait_behind_writes(struct mddev *mddev)
 {
 	struct bitmap *bitmap = mddev->bitmap;
 
 	/* wait for behind writes to complete */
 	if (bitmap && atomic_read(&bitmap->behind_writes) > 0) {
-		if (nowait)
-			return false;
-
 		pr_debug("md:%s: behind writes in progress - waiting to stop.\n",
 			 mdname(mddev));
 		/* need to kick something here to make sure I/O goes? */
 		wait_event(bitmap->behind_wait,
 			   atomic_read(&bitmap->behind_writes) == 0);
 	}
-
-	return true;
 }
 
 static void bitmap_destroy(struct mddev *mddev)
@@ -2090,7 +2085,7 @@ static void bitmap_destroy(struct mddev *mddev)
 	if (!bitmap) /* there was no bitmap */
 		return;
 
-	bitmap_wait_behind_writes(mddev, false);
+	bitmap_wait_behind_writes(mddev);
 	if (!test_bit(MD_SERIALIZE_POLICY, &mddev->flags))
 		mddev_destroy_serial_pool(mddev, NULL);
 
drivers/md/md-bitmap.h +1 -1
index f46674bdfeb9..214f623c7e79 100644
@@ -98,7 +98,7 @@ struct bitmap_operations {
 
 	void (*start_behind_write)(struct mddev *mddev);
 	void (*end_behind_write)(struct mddev *mddev);
-	bool (*wait_behind_writes)(struct mddev *mddev, bool nowait);
+	void (*wait_behind_writes)(struct mddev *mddev);
 
 	md_bitmap_fn *start_write;
 	md_bitmap_fn *end_write;
drivers/md/md-llbitmap.c +2 -8
index 5a4e2abaa757..2a2b38c663c3 100644
@@ -1574,19 +1574,13 @@ static void llbitmap_end_behind_write(struct mddev *mddev)
 		wake_up(&llbitmap->behind_wait);
 }
 
-static bool llbitmap_wait_behind_writes(struct mddev *mddev, bool nowait)
+static void llbitmap_wait_behind_writes(struct mddev *mddev)
 {
 	struct llbitmap *llbitmap = mddev->bitmap;
 
-	if (llbitmap && atomic_read(&llbitmap->behind_writes) > 0) {
-		if (nowait)
-			return false;
-
+	if (llbitmap && atomic_read(&llbitmap->behind_writes) > 0)
 		wait_event(llbitmap->behind_wait,
 			   atomic_read(&llbitmap->behind_writes) == 0);
-	}
-
-	return true;
 }
 
 static ssize_t bits_show(struct mddev *mddev, char *page)
drivers/md/md.c +4 -11
index d1465bcd86c8..66a41d482e59 100644
@@ -402,14 +402,9 @@ bool md_handle_request(struct mddev *mddev, struct bio *bio)
 		 */
 		percpu_ref_get(&mddev->active_io);
 	} else {
-		if (is_suspended(mddev, bio)) {
-			/* Bail out if REQ_NOWAIT is set for the bio */
-			if (bio->bi_opf & REQ_NOWAIT) {
-				bio_wouldblock_error(bio);
-				return true;
-			}
+		if (is_suspended(mddev, bio))
 			wait_event(mddev->sb_wait, !is_suspended(mddev, bio));
-		}
+
 		if (!percpu_ref_tryget_live(&mddev->active_io))
 			goto check_suspended;
 	}
@@ -6283,7 +6278,7 @@ void md_init_stacking_limits(struct queue_limits *lim)
 {
 	blk_set_stacking_limits(lim);
 	lim->features = BLK_FEAT_WRITE_CACHE | BLK_FEAT_FUA |
-			BLK_FEAT_IO_STAT | BLK_FEAT_NOWAIT;
+			BLK_FEAT_IO_STAT;
 }
 EXPORT_SYMBOL_GPL(md_init_stacking_limits);
 
@@ -6631,7 +6626,6 @@ int md_run(struct mddev *mddev)
 	int err;
 	struct md_rdev *rdev;
 	struct md_personality *pers;
-	bool nowait = true;
 
 	if (list_empty(&mddev->disks))
 		/* cannot run an array with no devices.. */
@@ -6702,7 +6696,6 @@ int md_run(struct mddev *mddev)
 			}
 		}
 		sysfs_notify_dirent_safe(rdev->sysfs_state);
-		nowait = nowait && bdev_nowait(rdev->bdev);
 	}
 
 	pers = get_pers(mddev->level, mddev->clevel);
@@ -7050,7 +7043,7 @@ EXPORT_SYMBOL_GPL(md_stop_writes);
 static void mddev_detach(struct mddev *mddev)
 {
 	if (md_bitmap_enabled(mddev, false))
-		mddev->bitmap_ops->wait_behind_writes(mddev, false);
+		mddev->bitmap_ops->wait_behind_writes(mddev);
 	if (mddev->pers && mddev->pers->quiesce && !is_md_suspended(mddev)) {
 		mddev->pers->quiesce(mddev, 1);
 		mddev->pers->quiesce(mddev, 0);
drivers/md/raid1-10.c +3 -5
index 56a56a4da4f8..3b0e230692ba 100644
@@ -290,9 +290,8 @@ static inline bool raid1_should_read_first(struct mddev *mddev,
 }
 
 /*
- * bio with REQ_RAHEAD or REQ_NOWAIT can fail at anytime, before such IO is
- * submitted to the underlying disks, hence don't record badblocks or retry
- * in this case.
+ * bio with REQ_RAHEAD can fail at anytime, before such IO is submitted to the
+ * underlying disks, hence don't record badblocks or retry in this case.
  *
  * BLK_STS_INVAL means the bio was not valid for the underlying device. This
  * is a user error, not a device failure, so retrying or recording bad blocks
@@ -300,6 +299,5 @@ static inline bool raid1_should_read_first(struct mddev *mddev,
  */
 static inline bool raid1_should_handle_error(struct bio *bio)
 {
-	return !(bio->bi_opf & (REQ_RAHEAD | REQ_NOWAIT)) &&
-		bio->bi_status != BLK_STS_INVAL;
+	return !(bio->bi_opf & REQ_RAHEAD) && bio->bi_status != BLK_STS_INVAL;
 }
drivers/md/raid1.c +19 -72

216 lines not on this page · raw message

drivers/md/raid10.c +20 -60

204 lines not on this page · raw message

drivers/md/raid5.c +0 -13
index 0c5c9fb0606e..5171e221696a 100644
@@ -5718,10 +5718,6 @@ static void make_discard_request(struct mddev *mddev, struct bio *bi)
 	struct bio *orig_bi = bi;
 	int stripe_sectors;
 
-	/* We need to handle this when io_uring supports discard/trim */
-	if (WARN_ON_ONCE(bi->bi_opf & REQ_NOWAIT))
-		return;
-
 	if (mddev->reshape_position != MaxSector)
 		/* Skip discard while reshape is happening */
 		return;
@@ -6191,15 +6187,6 @@ static bool raid5_make_request(struct mddev *mddev, struct bio * bi)
 	pr_debug("raid456: %s, logical %llu to %llu\n", __func__,
 		 bi->bi_iter.bi_sector, ctx->last_sector);
 
-	/* Bail out if conflicts with reshape and REQ_NOWAIT is set */
-	if ((bi->bi_opf & REQ_NOWAIT) &&
-	    get_reshape_loc(mddev, conf, logical_sector) == LOC_INSIDE_RESHAPE) {
-		bio_wouldblock_error(bi);
-		if (rw == WRITE)
-			md_write_end(mddev);
-		mempool_free(ctx, conf->ctx_pool);
-		return true;
-	}
 	md_account_bio(mddev, &bi);
 
 	/*
Signature · 1 line
2.43.0
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 18 lines · Abd-Alrhman Masalkhi

REQ_NOWAIT support in md is fundamentally incomplete. While reads can avoid some blocking paths, write requests can still encounter cases where one mirror succeeds while another returns -EAGAIN. At that point md cannot distinguish queue pressure from a real device failure, so it can neither record a bad block nor safely retry the write without REQ_NOWAIT, leaving mirrors with divergent data.

Rather than continue advertising REQ_NOWAIT support that cannot be implemented correctly, remove it from md and its raid personalities. This simplifies the waiting paths and avoids exposing incorrect non-blocking semantics.

Fixes bf2c411bb1cf ("md: raid456 add nowait support")
Fixes c9aa889b035f ("md: raid10 add nowait support")
Fixes 5aa705039c4f ("md: raid1 add nowait support")
Fixes f51d46d0e7cb ("md: add support for REQ_NOWAIT")
Quoted 10 lines
---
  drivers/md/md-bitmap.c   |  9 +---
  drivers/md/md-bitmap.h   |  2 +-
  drivers/md/md-llbitmap.c | 10 +----
  drivers/md/md.c          | 15 ++-----
  drivers/md/raid1-10.c    |  8 ++--
  drivers/md/raid1.c       | 91 +++++++++-------------------------------
  drivers/md/raid10.c      | 80 +++++++++--------------------------
  drivers/md/raid5.c       | 13 ------
  8 files changed, 51 insertions(+), 177 deletions(-)
Signature · 2 lines
Thanks,
Kuai
maintainer Applied
#2 lore raw
In reply to Abd-Alrhman Masalkhi

Hi,

Quoted 18 lines · Abd-Alrhman Masalkhi

REQ_NOWAIT support in md is fundamentally incomplete. While reads can avoid some blocking paths, write requests can still encounter cases where one mirror succeeds while another returns -EAGAIN. At that point md cannot distinguish queue pressure from a real device failure, so it can neither record a bad block nor safely retry the write without REQ_NOWAIT, leaving mirrors with divergent data.

Rather than continue advertising REQ_NOWAIT support that cannot be implemented correctly, remove it from md and its raid personalities. This simplifies the waiting paths and avoids exposing incorrect non-blocking semantics.

Fixes bf2c411bb1cf ("md: raid456 add nowait support")
Fixes c9aa889b035f ("md: raid10 add nowait support")
Fixes 5aa705039c4f ("md: raid1 add nowait support")
Fixes f51d46d0e7cb ("md: add support for REQ_NOWAIT")
Quoted 10 lines
---
  drivers/md/md-bitmap.c   |  9 +---
  drivers/md/md-bitmap.h   |  2 +-
  drivers/md/md-llbitmap.c | 10 +----
  drivers/md/md.c          | 15 ++-----
  drivers/md/raid1-10.c    |  8 ++--
  drivers/md/raid1.c       | 91 +++++++++-------------------------------
  drivers/md/raid10.c      | 80 +++++++++--------------------------
  drivers/md/raid5.c       | 13 ------
  8 files changed, 51 insertions(+), 177 deletions(-)

Applied to md-7.3 with a few changes, please check:

md: remove REQ_NOWAIT support from raid1/10/456 -
kernel/git/mdraid/linux.git - song's fork of linux.git <https://git.kernel.org/pub/scm/linux/kernel/git/mdraid/linux.git/commit/?h=md-7.3&id=3fe5b7c9fb72ccc29bfd0f955b124892af7e3674>

- rebase raid1/raid10 with latest code;
- keep nowait for raid0/linear;
- keep nowait for md_handle_request, as raid0/linear will need it;

Signature · 2 lines
Thanks,
Kuai
#3 lore raw
Quoted 32 lines · yu kuai

Hi,

? 2026/6/28 22:27, Abd-Alrhman Masalkhi ??:

Quoted 18 lines

REQ_NOWAIT support in md is fundamentally incomplete. While reads can avoid some blocking paths, write requests can still encounter cases where one mirror succeeds while another returns -EAGAIN. At that point md cannot distinguish queue pressure from a real device failure, so it can neither record a bad block nor safely retry the write without REQ_NOWAIT, leaving mirrors with divergent data.

Rather than continue advertising REQ_NOWAIT support that cannot be implemented correctly, remove it from md and its raid personalities. This simplifies the waiting paths and avoids exposing incorrect non-blocking semantics.

Fixes bf2c411bb1cf ("md: raid456 add nowait support")
Fixes c9aa889b035f ("md: raid10 add nowait support")
Fixes 5aa705039c4f ("md: raid1 add nowait support")
Fixes f51d46d0e7cb ("md: add support for REQ_NOWAIT")
Quoted 10 lines
---
  drivers/md/md-bitmap.c   |  9 +---
  drivers/md/md-bitmap.h   |  2 +-
  drivers/md/md-llbitmap.c | 10 +----
  drivers/md/md.c          | 15 ++-----
  drivers/md/raid1-10.c    |  8 ++--
  drivers/md/raid1.c       | 91 +++++++++-------------------------------
  drivers/md/raid10.c      | 80 +++++++++--------------------------
  drivers/md/raid5.c       | 13 ------
  8 files changed, 51 insertions(+), 177 deletions(-)
Quoted 8 lines

Applied to md-7.3 with a few changes, please check:

md: remove REQ_NOWAIT support from raid1/10/456 -
kernel/git/mdraid/linux.git - song's fork of linux.git <https://git.kernel.org/pub/scm/linux/kernel/git/mdraid/linux.git/commit/?h=md-7.3&id=3fe5b7c9fb72ccc29bfd0f955b124892af7e3674>

- rebase raid1/raid10 with latest code;
- keep nowait for raid0/linear;
- keep nowait for md_handle_request, as raid0/linear will need it;

What's the plan for making REQ_NOWAIT _actually_ work with md? Just yanking it wholesale is a massive performance problem, and it will regress workloads. Has any time been spent on making this more solid?

Signature · 1 line
Jens Axboe
maintainer
#4 lore raw

Hi,

Quoted 37 lines · Jens Axboe
Quoted 36 lines · yu kuai

Hi,

? 2026/6/28 22:27, Abd-Alrhman Masalkhi ??:

Quoted 18 lines

REQ_NOWAIT support in md is fundamentally incomplete. While reads can avoid some blocking paths, write requests can still encounter cases where one mirror succeeds while another returns -EAGAIN. At that point md cannot distinguish queue pressure from a real device failure, so it can neither record a bad block nor safely retry the write without REQ_NOWAIT, leaving mirrors with divergent data.

Rather than continue advertising REQ_NOWAIT support that cannot be implemented correctly, remove it from md and its raid personalities. This simplifies the waiting paths and avoids exposing incorrect non-blocking semantics.

Fixes bf2c411bb1cf ("md: raid456 add nowait support")
Fixes c9aa889b035f ("md: raid10 add nowait support")
Fixes 5aa705039c4f ("md: raid1 add nowait support")
Fixes f51d46d0e7cb ("md: add support for REQ_NOWAIT")
Quoted 10 lines
---
   drivers/md/md-bitmap.c   |  9 +---
   drivers/md/md-bitmap.h   |  2 +-
   drivers/md/md-llbitmap.c | 10 +----
   drivers/md/md.c          | 15 ++-----
   drivers/md/raid1-10.c    |  8 ++--
   drivers/md/raid1.c       | 91 +++++++++-------------------------------
   drivers/md/raid10.c      | 80 +++++++++--------------------------
   drivers/md/raid5.c       | 13 ------
   8 files changed, 51 insertions(+), 177 deletions(-)

Applied to md-7.3 with a few changes, please check:

md: remove REQ_NOWAIT support from raid1/10/456 -
kernel/git/mdraid/linux.git - song's fork of linux.git <https://git.kernel.org/pub/scm/linux/kernel/git/mdraid/linux.git/commit/?h=md-7.3&id=3fe5b7c9fb72ccc29bfd0f955b124892af7e3674>

Quoted 6 lines
Quoted 3 lines

- rebase raid1/raid10 with latest code;
- keep nowait for raid0/linear;
- keep nowait for md_handle_request, as raid0/linear will need it;

What's the plan for making REQ_NOWAIT _actually_ work with md? Just yanking it wholesale is a massive performance problem, and it will regress workloads. Has any time been spent on making this more solid?

For raid1/10/56, if anyone is still using nowait they should stop, because there is risk of data lost or wrong data being read.

And yes, I tried, but I can't figure out a solid solution for the case that, if nowait IO issue to one disk succeed while another disk failed. We can't either issue again without nowait from mdraid because it's against nowait principle, or record badblocks (which is currently what mdraid did) because data can be lost. Hence, the array will have to do additional data synchronization in this case, while nowait issue failure is not a slow path that performance overhead can be ignored.

Quoted 1 line
Signature · 2 lines
Thanks,
Kuai