Skip to contentSkip to conversation

Refactor blk_zone_wplug_handle_write()

PATCH Applied Bart Van Assche 5 participants 8 messages Nov 11, 2025 – Nov 12, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v2 cover Refactor blk_zone_wplug_handle_write()

Hi Jens,

This series includes three small patches for the zoned block device code: a typo is fixed, a lockdep annotation is added and the code for handling zoned writes is made slightly easier to follow. Please consider these patches for the next merge window.

Thanks,

Bart.

Changes compared to v1:
- Combined patches 3 and 4 into a single patch.
- Renamed a goto label.
- Removed the local variable "schedule_bio_work".

Bart Van Assche (3):
blk-zoned: Fix a typo in a source code comment
blk-zoned: Document disk_zone_wplug_schedule_bio_work() locking
blk-zoned: Move code from disk_zone_wplug_add_bio() into its caller

 block/blk-zoned.c | 46 ++++++++++++++++++++--------------------------
 1 file changed, 20 insertions(+), 26 deletions(-)
#1 lore raw

PATCH v2 1/3 blk-zoned: Fix a typo in a source code comment

Remove a superfluous parenthesis that was introduced by commit fa8555630b32 ("blk-zoned: Improve the queue reference count strategy documentation").

---
 block/blk-zoned.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
block/blk-zoned.c +1 -1
index 3791755bc6ad..57ab2b365c2d 100644
@@ -730,7 +730,7 @@ static inline void blk_zone_wplug_bio_io_error(struct blk_zone_wplug *zwplug,
 	bio_clear_flag(bio, BIO_ZONE_WRITE_PLUGGING);
 	bio_io_error(bio);
 	disk_put_zone_wplug(zwplug);
-	/* Drop the reference taken by disk_zone_wplug_add_bio(() */
+	/* Drop the reference taken by disk_zone_wplug_add_bio(). */
 	blk_queue_exit(q);
 }
 
#2 lore raw

PATCH v2 2/3 blk-zoned: Document disk_zone_wplug_schedule_bio_work() locking

In reply to Bart Van Assche

Document that all callers hold this lock because the code in disk_zone_wplug_schedule_bio_work() depends on this.

---
 block/blk-zoned.c | 2 ++
 1 file changed, 2 insertions(+)
block/blk-zoned.c +2 -0
index 57ab2b365c2d..5487d5eb2650 100644
@@ -1188,6 +1188,8 @@ void blk_zone_mgmt_bio_endio(struct bio *bio)
 static void disk_zone_wplug_schedule_bio_work(struct gendisk *disk,
 					      struct blk_zone_wplug *zwplug)
 {
+	lockdep_assert_held(&zwplug->lock);
+
 	/*
 	 * Take a reference on the zone write plug and schedule the submission
 	 * of the next plugged BIO. blk_zone_wplug_bio_work() will release the
#3 lore raw

PATCH v2 3/3 blk-zoned: Move code from disk_zone_wplug_add_bio() into its caller

In reply to Bart Van Assche

Move the following code into the only caller of disk_zone_wplug_add_bio():
- The code for clearing the REQ_NOWAIT flag.
- The code that sets the BLK_ZONE_WPLUG_PLUGGED flag.
- The disk_zone_wplug_schedule_bio_work() call.

This patch moves all code that is related to REQ_NOWAIT or to bio scheduling into a single function. Additionally, the 'schedule_bio_work' variable is removed. No functionality has been changed.

Cc Damien Le Moal <[email protected]>
Cc Christoph Hellwig <[email protected]>
---
 block/blk-zoned.c | 42 +++++++++++++++++-------------------------
 1 file changed, 17 insertions(+), 25 deletions(-)
block/blk-zoned.c +17 -25
index 5487d5eb2650..85de45c3f6be 100644
@@ -1204,8 +1204,6 @@ static inline void disk_zone_wplug_add_bio(struct gendisk *disk,
 				struct blk_zone_wplug *zwplug,
 				struct bio *bio, unsigned int nr_segs)
 {
-	bool schedule_bio_work = false;
-
 	/*
 	 * Grab an extra reference on the BIO request queue usage counter.
 	 * This reference will be reused to submit a request for the BIO for
@@ -1221,16 +1219,6 @@ static inline void disk_zone_wplug_add_bio(struct gendisk *disk,
 	 */
 	bio_clear_polled(bio);
 
-	/*
-	 * REQ_NOWAIT BIOs are always handled using the zone write plug BIO
-	 * work, which can block. So clear the REQ_NOWAIT flag and schedule the
-	 * work if this is the first BIO we are plugging.
-	 */
-	if (bio->bi_opf & REQ_NOWAIT) {
-		schedule_bio_work = !(zwplug->flags & BLK_ZONE_WPLUG_PLUGGED);
-		bio->bi_opf &= ~REQ_NOWAIT;
-	}
-
 	/*
 	 * Reuse the poll cookie field to store the number of segments when
 	 * split to the hardware limits.
@@ -1246,11 +1234,6 @@ static inline void disk_zone_wplug_add_bio(struct gendisk *disk,
 	bio_list_add(&zwplug->bio_list, bio);
 	trace_disk_zone_wplug_add_bio(zwplug->disk->queue, zwplug->zone_no,
 				      bio->bi_iter.bi_sector, bio_sectors(bio));
-
-	zwplug->flags |= BLK_ZONE_WPLUG_PLUGGED;
-
-	if (schedule_bio_work)
-		disk_zone_wplug_schedule_bio_work(disk, zwplug);
 }
 
 /*
@@ -1461,14 +1444,17 @@ static bool blk_zone_wplug_handle_write(struct bio *bio, unsigned int nr_segs)
 	bio_set_flag(bio, BIO_ZONE_WRITE_PLUGGING);
 
 	/*
-	 * If the zone is already plugged, add the BIO to the plug BIO list.
-	 * Do the same for REQ_NOWAIT BIOs to ensure that we will not see a
-	 * BLK_STS_AGAIN failure if we let the BIO execute.
-	 * Otherwise, plug and let the BIO execute.
+	 * Add REQ_NOWAIT BIOs to the plug list to ensure that we will not see a
+	 * BLK_STS_AGAIN failure if we let the caller submit the BIO.
 	 */
-	if ((zwplug->flags & BLK_ZONE_WPLUG_PLUGGED) ||
-	    (bio->bi_opf & REQ_NOWAIT))
-		goto plug;
+	if (bio->bi_opf & REQ_NOWAIT) {
+		bio->bi_opf &= ~REQ_NOWAIT;
+		goto queue_bio;
+	}
+
+	/* If the zone is already plugged, add the BIO to the BIO plug list. */
+	if (zwplug->flags & BLK_ZONE_WPLUG_PLUGGED)
+		goto queue_bio;
 
 	if (!blk_zone_wplug_prepare_bio(zwplug, bio)) {
 		spin_unlock_irqrestore(&zwplug->lock, flags);
@@ -1476,15 +1462,21 @@ static bool blk_zone_wplug_handle_write(struct bio *bio, unsigned int nr_segs)
 		return true;
 	}
 
+	/* Otherwise, plug and let the caller submit the BIO. */
 	zwplug->flags |= BLK_ZONE_WPLUG_PLUGGED;
 
 	spin_unlock_irqrestore(&zwplug->lock, flags);
 
 	return false;
 
-plug:
+queue_bio:
 	disk_zone_wplug_add_bio(disk, zwplug, bio, nr_segs);
 
+	if (!(zwplug->flags & BLK_ZONE_WPLUG_PLUGGED)) {
+		zwplug->flags |= BLK_ZONE_WPLUG_PLUGGED;
+		disk_zone_wplug_schedule_bio_work(disk, zwplug);
+	}
+
 	spin_unlock_irqrestore(&zwplug->lock, flags);
 
 	return true;
maintainer Reviewed-by on v2 3/3
#5 lore raw

Re: [PATCH v2 3/3] blk-zoned: Move code from disk_zone_wplug_add_bio() into its caller

In reply to Bart Van Assche
Quoted 5 lines · Bart Van Assche

Move the following code into the only caller of disk_zone_wplug_add_bio():
- The code for clearing the REQ_NOWAIT flag.
- The code that sets the BLK_ZONE_WPLUG_PLUGGED flag.
- The disk_zone_wplug_schedule_bio_work() call.

Quoted 7 lines

This patch moves all code that is related to REQ_NOWAIT or to bio scheduling into a single function. Additionally, the 'schedule_bio_work' variable is removed. No functionality has been changed.

Cc Damien Le Moal <[email protected]>
Cc Christoph Hellwig <[email protected]>
Signature · 2 lines
Damien Le Moal
Western Digital Research
Reviewed-by on the v2 series
#6 lore raw
In reply to Bart Van Assche

Bart,

Quoted 4 lines

This series includes three small patches for the zoned block device
code: a typo is fixed, a lockdep annotation is added and the code for handling zoned writes is made slightly easier to follow. Please consider these patches for the next merge window.

Looks fine.

Signature · 1 line
Martin K. Petersen
maintainer Applied
#7 lore raw
In reply to Bart Van Assche
Quoted 8 lines · Bart Van Assche

This series includes three small patches for the zoned block device code: a typo is fixed, a lockdep annotation is added and the code for handling zoned writes is made slightly easier to follow. Please consider these patches for the next merge window.

Thanks,

[...]

Applied, thanks!

[1/3] blk-zoned: Fix a typo in a source code comment

      commit: fd0ae4754c7b2add72338b14ddc8c8ff5ffda426
[2/3] blk-zoned: Document disk_zone_wplug_schedule_bio_work() locking
      commit: faa3be1a61bfaace4c2bd57434de7b13347f9f31
[3/3] blk-zoned: Move code from disk_zone_wplug_add_bio() into its caller
      commit: f233339188cd9b1a985fd8410d5811e920fdd4ef

Best regards,

Signature · 1 line
Jens Axboe