Skip to contentSkip to conversation

plugging cleanup v3

PATCH Applied Pankaj Raghav 4 participants 12 messages Sep 29, 2022 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): CGME20220929074747eucas1p1821a5b79ad24cb559b7b6ec324239e9e@eucas1p1.samsung.com

#1 lore raw

v3 cover plugging cleanup v3

Hi Jens,

1st patch modifies blk_mq_plug() function to disable plugging for
write and write zeroes in zoned block devices.

2nd patch uses the blk_mq_plug function in the block layer consistently.

The patches are based on next-20220923.

Changes since v2:
- Enhance the commit log for the 2nd patch (Christoph)

Changes since v1:
- Explicltly check only for write and write zeroes as they require zone locking in blk_mq_plug
- create a new helper to check for ops that require zone locking for zoned devices and also reuse it in blk_req_needs_zone_write_lock

Pankaj Raghav (2):
block: adapt blk_mq_plug() to not plug for writes that require a zone
lock
block: use blk_mq_plug() wrapper consistently in the block layer

 block/blk-core.c       | 2 +-
 block/blk-mq.c         | 6 ++++--
 block/blk-mq.h         | 3 ++-
 block/blk-zoned.c      | 9 +++------
 include/linux/blkdev.h | 9 +++++++++
 5 files changed, 19 insertions(+), 10 deletions(-)
Signature · 1 line
2.25.1
#2 lore raw

PATCH v3 1/2 block: adapt blk_mq_plug() to not plug for writes that require a zone lock

The current implementation of blk_mq_plug() disables plugging for all operations that involves a transfer to the device as we just check if the last bit in op_is_write() function.

Modify blk_mq_plug() to disable plugging only for REQ_OP_WRITE and REQ_OP_WRITE_ZEROS as they might require a zone lock.

---
 block/blk-mq.h         | 3 ++-
 block/blk-zoned.c      | 9 +++------
 include/linux/blkdev.h | 9 +++++++++
 3 files changed, 14 insertions(+), 7 deletions(-)
block/blk-mq.h +2 -1
index 8ca453ac243d..0b2870839cdd 100644
@@ -312,7 +312,8 @@ static inline void blk_mq_clear_mq_map(struct blk_mq_queue_map *qmap)
 static inline struct blk_plug *blk_mq_plug( struct bio *bio)
 {
 	/* Zoned block device write operation case: do not plug the BIO */
-	if (bdev_is_zoned(bio->bi_bdev) && op_is_write(bio_op(bio)))
+	if (IS_ENABLED(CONFIG_BLK_DEV_ZONED) &&
+	    bdev_op_is_zoned_write(bio->bi_bdev, bio_op(bio)))
 		return NULL;
 
 	/*
block/blk-zoned.c +3 -6
index a264621d4905..db829401d8d0 100644
@@ -63,13 +63,10 @@ bool blk_req_needs_zone_write_lock(struct request *rq)
 	if (!rq->q->disk->seq_zones_wlock)
 		return false;
 
-	switch (req_op(rq)) {
-	case REQ_OP_WRITE_ZEROES:
-	case REQ_OP_WRITE:
+	if (bdev_op_is_zoned_write(rq->q->disk->part0, req_op(rq)))
 		return blk_rq_zone_is_seq(rq);
-	default:
-		return false;
-	}
+
+	return false;
 }
 EXPORT_SYMBOL_GPL(blk_req_needs_zone_write_lock);
 
include/linux/blkdev.h +9 -0
index 8038c5fbde40..74bc30c680d6 100644
@@ -1300,6 +1300,15 @@ static inline bool bdev_is_zoned(struct block_device *bdev)
 	return false;
 }
 
+static inline bool bdev_op_is_zoned_write(struct block_device *bdev,
+					  blk_opf_t op)
+{
+	if (!bdev_is_zoned(bdev))
+		return false;
+
+	return op == REQ_OP_WRITE || op == REQ_OP_WRITE_ZEROES;
+}
+
 static inline sector_t bdev_zone_sectors(struct block_device *bdev)
 {
 	struct request_queue *q = bdev_get_queue(bdev);
Signature · 1 line
2.25.1
Reviewed-by on v3 1/2
#3 lore raw

Re: [PATCH v3 1/2] block: adapt blk_mq_plug() to not plug for writes that require a zone lock

Quoted 11 lines · Pankaj Raghav

The current implementation of blk_mq_plug() disables plugging for all operations that involves a transfer to the device as we just check if the last bit in op_is_write() function.

Modify blk_mq_plug() to disable plugging only for REQ_OP_WRITE and REQ_OP_WRITE_ZEROS as they might require a zone lock.

Quoted 61 lines
---
 block/blk-mq.h         | 3 ++-
 block/blk-zoned.c      | 9 +++------
 include/linux/blkdev.h | 9 +++++++++
 3 files changed, 14 insertions(+), 7 deletions(-)
block/blk-mq.h +2 -1
index 8ca453ac243d..0b2870839cdd 100644
@@ -312,7 +312,8 @@ static inline void blk_mq_clear_mq_map(struct blk_mq_queue_map *qmap)
 static inline struct blk_plug *blk_mq_plug( struct bio *bio)
 {
 	/* Zoned block device write operation case: do not plug the BIO */
-	if (bdev_is_zoned(bio->bi_bdev) && op_is_write(bio_op(bio)))
+	if (IS_ENABLED(CONFIG_BLK_DEV_ZONED) &&
+	    bdev_op_is_zoned_write(bio->bi_bdev, bio_op(bio)))
 		return NULL;
 
 	/*
block/blk-zoned.c +3 -6
index a264621d4905..db829401d8d0 100644
@@ -63,13 +63,10 @@ bool blk_req_needs_zone_write_lock(struct request *rq)
 	if (!rq->q->disk->seq_zones_wlock)
 		return false;
 
-	switch (req_op(rq)) {
-	case REQ_OP_WRITE_ZEROES:
-	case REQ_OP_WRITE:
+	if (bdev_op_is_zoned_write(rq->q->disk->part0, req_op(rq)))
 		return blk_rq_zone_is_seq(rq);
-	default:
-		return false;
-	}
+
+	return false;
 }
 EXPORT_SYMBOL_GPL(blk_req_needs_zone_write_lock);
 
include/linux/blkdev.h +9 -0
index 8038c5fbde40..74bc30c680d6 100644
@@ -1300,6 +1300,15 @@ static inline bool bdev_is_zoned(struct block_device *bdev)
 	return false;
 }
 
+static inline bool bdev_op_is_zoned_write(struct block_device *bdev,
+					  blk_opf_t op)
+{
+	if (!bdev_is_zoned(bdev))
+		return false;
+
+	return op == REQ_OP_WRITE || op == REQ_OP_WRITE_ZEROES;
+}
+
 static inline sector_t bdev_zone_sectors(struct block_device *bdev)
 {
 	struct request_queue *q = bdev_get_queue(bdev);
Signature · 2 lines
Damien Le Moal
Western Digital Research
Reviewed-by on v3 1/2
#4 lore raw

Re: [PATCH v3 1/2] block: adapt blk_mq_plug() to not plug for writes that require a zone lock

In reply to Pankaj Raghav

On 29.09.22 09:49, Pankaj Raghav wrote:
Nit: (but I think Jens can fix this up when applying if he thinks so as well)

Quoted 2 lines

The current implementation of blk_mq_plug() disables plugging for all operations that involves a transfer to the device as we just check if

to a zoned device ~^

Otherwise,

#5 lore raw

PATCH v3 2/2 block: use blk_mq_plug() wrapper consistently in the block layer

In reply to Pankaj Raghav

Use blk_mq_plug() wrapper to get the plug instead of directly accessing it in the block layer.

Either of the changes should not have led to a bug in zoned devices:

- blk_execute_rq_nowait:
Only passthrough requests can use this function, and plugging can be performed on those requests in zoned devices. So no issues directly accessing the plug.

- blk_flush_plug in bio_poll:
As we don't plug the requests that require a zone lock in the first place, flushing should not have any impact. So no issues directly accessing the plug.

This is just a cleanup patch to use this wrapper to get the plug consistently across the block layer.

---
 block/blk-core.c | 2 +-
 block/blk-mq.c   | 6 ++++--
 2 files changed, 5 insertions(+), 3 deletions(-)
block/blk-core.c +1 -1
index 203be672da52..d0e97de216db 100644
@@ -850,7 +850,7 @@ int bio_poll(struct bio *bio, struct io_comp_batch *iob, unsigned int flags)
 	    !test_bit(QUEUE_FLAG_POLL, &q->queue_flags))
 		return 0;
 
-	blk_flush_plug(current->plug, false);
+	blk_flush_plug(blk_mq_plug(bio), false);
 
 	if (bio_queue_enter(bio))
 		return 0;
block/blk-mq.c +4 -2
index c11949d66163..5bf245c4bf0a 100644
@@ -1209,12 +1209,14 @@ static void blk_add_rq_to_plug(struct blk_plug *plug, struct request *rq)
  */
 void blk_execute_rq_nowait(struct request *rq, bool at_head)
 {
+	struct blk_plug *plug = blk_mq_plug(rq->bio);
+
 	WARN_ON(irqs_disabled());
 	WARN_ON(!blk_rq_is_passthrough(rq));
 
 	blk_account_io_start(rq);
-	if (current->plug)
-		blk_add_rq_to_plug(current->plug, rq);
+	if (plug)
+		blk_add_rq_to_plug(plug, rq);
 	else
 		blk_mq_sched_insert_request(rq, at_head, true, false);
 }
Signature · 1 line
2.25.1
Reviewed-by on v3 2/2
#6 lore raw

Re: [PATCH v3 2/2] block: use blk_mq_plug() wrapper consistently in the block layer

Quoted 15 lines · Pankaj Raghav

Use blk_mq_plug() wrapper to get the plug instead of directly accessing it in the block layer.

Either of the changes should not have led to a bug in zoned devices:

- blk_execute_rq_nowait:
Only passthrough requests can use this function, and plugging can be performed on those requests in zoned devices. So no issues directly accessing the plug.

- blk_flush_plug in bio_poll:
As we don't plug the requests that require a zone lock in the first place, flushing should not have any impact. So no issues directly accessing the plug.

Quoted 4 lines

This is just a cleanup patch to use this wrapper to get the plug consistently across the block layer.

Quoted 39 lines
---
 block/blk-core.c | 2 +-
 block/blk-mq.c   | 6 ++++--
 2 files changed, 5 insertions(+), 3 deletions(-)
block/blk-core.c +1 -1
index 203be672da52..d0e97de216db 100644
@@ -850,7 +850,7 @@ int bio_poll(struct bio *bio, struct io_comp_batch *iob, unsigned int flags)
 	    !test_bit(QUEUE_FLAG_POLL, &q->queue_flags))
 		return 0;
 
-	blk_flush_plug(current->plug, false);
+	blk_flush_plug(blk_mq_plug(bio), false);
 
 	if (bio_queue_enter(bio))
 		return 0;
block/blk-mq.c +4 -2
index c11949d66163..5bf245c4bf0a 100644
@@ -1209,12 +1209,14 @@ static void blk_add_rq_to_plug(struct blk_plug *plug, struct request *rq)
  */
 void blk_execute_rq_nowait(struct request *rq, bool at_head)
 {
+	struct blk_plug *plug = blk_mq_plug(rq->bio);
+
 	WARN_ON(irqs_disabled());
 	WARN_ON(!blk_rq_is_passthrough(rq));
 
 	blk_account_io_start(rq);
-	if (current->plug)
-		blk_add_rq_to_plug(current->plug, rq);
+	if (plug)
+		blk_add_rq_to_plug(plug, rq);
 	else
 		blk_mq_sched_insert_request(rq, at_head, true, false);
 }
Signature · 2 lines
Damien Le Moal
Western Digital Research
maintainer
#8 lore raw

Re: [PATCH v3 2/2] block: use blk_mq_plug() wrapper consistently in the block layer

In reply to Pankaj Raghav
Quoted 10 lines · Pankaj Raghav

Use blk_mq_plug() wrapper to get the plug instead of directly accessing it in the block layer.

Either of the changes should not have led to a bug in zoned devices:

- blk_execute_rq_nowait:
Only passthrough requests can use this function, and plugging can be performed on those requests in zoned devices. So no issues directly accessing the plug.

Quoted 7 lines

- blk_flush_plug in bio_poll:
As we don't plug the requests that require a zone lock in the first place, flushing should not have any impact. So no issues directly accessing the plug.

This is just a cleanup patch to use this wrapper to get the plug consistently across the block layer.

While I did suggest to make this consistent and in principle it's the right thing to do, it also irks me to add extra checks to paths where we know that it's just extra pointless code. Maybe we can just comment these two spots? Basically each of the sections above could just go into the appropriate file.

Signature · 1 line
Jens Axboe
#9 lore raw

Re: [PATCH v3 2/2] block: use blk_mq_plug() wrapper consistently in the block layer

Quoted 12 lines
Quoted 12 lines

Either of the changes should not have led to a bug in zoned devices:

- blk_execute_rq_nowait:
Only passthrough requests can use this function, and plugging can be performed on those requests in zoned devices. So no issues directly accessing the plug.

- blk_flush_plug in bio_poll:
As we don't plug the requests that require a zone lock in the first place, flushing should not have any impact. So no issues directly accessing the plug.

Quoted 9 lines
Quoted 2 lines

This is just a cleanup patch to use this wrapper to get the plug consistently across the block layer.

While I did suggest to make this consistent and in principle it's the right thing to do, it also irks me to add extra checks to paths where we know that it's just extra pointless code. Maybe we can just comment these two spots? Basically each of the sections above could just go into the appropriate file.

The checks should go away, and the plug could be inlined by the compiler if we don't have CONFIG_BLK_DEV_ZONED. Otherwise, I do agree with you that it is a pointless check.

I am fine with either, though I prefer what this patch is doing. So if you feel strongly against calling the blk_mq_plug function, I can turn this patch into just adding comments as you suggested.

maintainer
#10 lore raw

Re: [PATCH v3 2/2] block: use blk_mq_plug() wrapper consistently in the block layer

Quoted 21 lines · Pankaj Raghav
Quoted 12 lines
Quoted 12 lines

Either of the changes should not have led to a bug in zoned devices:

- blk_execute_rq_nowait:
Only passthrough requests can use this function, and plugging can be performed on those requests in zoned devices. So no issues directly accessing the plug.

- blk_flush_plug in bio_poll:
As we don't plug the requests that require a zone lock in the first place, flushing should not have any impact. So no issues directly accessing the plug.

Quoted 9 lines
Quoted 2 lines

This is just a cleanup patch to use this wrapper to get the plug consistently across the block layer.

While I did suggest to make this consistent and in principle it's the right thing to do, it also irks me to add extra checks to paths where we know that it's just extra pointless code. Maybe we can just comment these two spots? Basically each of the sections above could just go into the appropriate file.

Quoted 3 lines

The checks should go away, and the plug could be inlined by the compiler if we don't have CONFIG_BLK_DEV_ZONED. Otherwise, I do agree with you that it is a pointless check.

But that's my general complaint with the argument that "it doesn't matter if this feature isn't configured" - distros enable features. Anything that uses IS_ENABLED() is handy for testing, but assuming it all pretty much gets enabled in the distro kernel, it does absolutely nothing to help the added overhead. It's something that gets done to create the illusion that an added feature CAN have zero core overhead, while in reality that's utterly wrong.

Quoted 3 lines

I am fine with either, though I prefer what this patch is doing. So if you feel strongly against calling the blk_mq_plug function, I can turn this patch into just adding comments as you suggested.

I think we should. I can pick patch 1 here, and then you can send a patch 2 for that when you have time.

Signature · 1 line
Jens Axboe
#11 lore raw

Re: [PATCH v3 2/2] block: use blk_mq_plug() wrapper consistently in the block layer

Quoted 34 lines · Jens Axboe
Quoted 21 lines · Pankaj Raghav
Quoted 12 lines
Quoted 12 lines

Either of the changes should not have led to a bug in zoned devices:

- blk_execute_rq_nowait:
Only passthrough requests can use this function, and plugging can be performed on those requests in zoned devices. So no issues directly accessing the plug.

- blk_flush_plug in bio_poll:
As we don't plug the requests that require a zone lock in the first place, flushing should not have any impact. So no issues directly accessing the plug.

Quoted 9 lines
Quoted 2 lines

This is just a cleanup patch to use this wrapper to get the plug consistently across the block layer.

While I did suggest to make this consistent and in principle it's the right thing to do, it also irks me to add extra checks to paths where we know that it's just extra pointless code. Maybe we can just comment these two spots? Basically each of the sections above could just go into the appropriate file.

Quoted 3 lines

The checks should go away, and the plug could be inlined by the compiler if we don't have CONFIG_BLK_DEV_ZONED. Otherwise, I do agree with you that it is a pointless check.

But that's my general complaint with the argument that "it doesn't matter if this feature isn't configured" - distros enable features. Anything that uses IS_ENABLED() is handy for testing, but assuming it all pretty much gets enabled in the distro kernel, it does absolutely nothing to help the added overhead. It's something that gets done to create the illusion that an added feature CAN have zero core overhead, while in reality that's utterly wrong.
Got it!

Quoted 7 lines
Quoted 3 lines

I am fine with either, though I prefer what this patch is doing. So if you feel strongly against calling the blk_mq_plug function, I can turn this patch into just adding comments as you suggested.

I think we should. I can pick patch 1 here, and then you can send a patch 2 for that when you have time.

I will do it right away as a separate patch! Thanks.

maintainer Applied
#12 lore raw

Re: (subset) [PATCH v3 0/2] plugging cleanup v3

In reply to Pankaj Raghav
Quoted 8 lines · Pankaj Raghav

1st patch modifies blk_mq_plug() function to disable plugging for
write and write zeroes in zoned block devices.

2nd patch uses the blk_mq_plug function in the block layer consistently.

The patches are based on next-20220923.

[...]

Applied, thanks!

[1/2] block: adapt blk_mq_plug() to not plug for writes that require a zone lock

      commit: 8cafdb5ab94cda3ebb0975be16e2d564a05132ea

Best regards,

Signature · 1 line
Jens Axboe