Linux-Block Archive mirror
 help / color / mirror / Atom feed
* [PATCH -next 0/3] blk-wbt: cleanup patches
@ 2023-03-04  8:40 Yu Kuai
  2023-03-04  8:40 ` [PATCH -next 1/3] blk-wbt: cleanup rwb_enabled() and wbt_disabled() Yu Kuai
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Yu Kuai @ 2023-03-04  8:40 UTC (permalink / raw
  To: hch, axboe
  Cc: linux-block, linux-kernel, yukuai3, yukuai1, yi.zhang, yangerkun

From: Yu Kuai <yukuai3@huawei.com>

Yu Kuai (3):
  blk-wbt: cleanup rwb_enabled() and wbt_disabled()
  blk-wbt: freeze queue in wbt_enable/disable_default
  blk-wbt: remove deadcode

 block/blk-wbt.c | 43 ++++++++++++++++++++-----------------------
 1 file changed, 20 insertions(+), 23 deletions(-)

-- 
2.31.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH -next 1/3] blk-wbt: cleanup rwb_enabled() and wbt_disabled()
  2023-03-04  8:40 [PATCH -next 0/3] blk-wbt: cleanup patches Yu Kuai
@ 2023-03-04  8:40 ` Yu Kuai
  2023-03-04  8:40 ` [PATCH -next 2/3] blk-wbt: freeze queue in wbt_enable/disable_default Yu Kuai
  2023-03-04  8:40 ` [PATCH -next 3/3] blk-wbt: remove deadcode Yu Kuai
  2 siblings, 0 replies; 4+ messages in thread
From: Yu Kuai @ 2023-03-04  8:40 UTC (permalink / raw
  To: hch, axboe
  Cc: linux-block, linux-kernel, yukuai3, yukuai1, yi.zhang, yangerkun

From: Yu Kuai <yukuai3@huawei.com>

The checkings in the two functions are redundant.

Signed-off-by: Yu Kuai <yukuai3@huawei.com>
---
 block/blk-wbt.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/block/blk-wbt.c b/block/blk-wbt.c
index e49a48684532..b5edf44499ab 100644
--- a/block/blk-wbt.c
+++ b/block/blk-wbt.c
@@ -146,7 +146,7 @@ enum {
 static inline bool rwb_enabled(struct rq_wb *rwb)
 {
 	return rwb && rwb->enable_state != WBT_STATE_OFF_DEFAULT &&
-		      rwb->wb_normal != 0;
+		      rwb->enable_state != WBT_STATE_OFF_MANUAL;
 }
 
 static void wb_timestamp(struct rq_wb *rwb, unsigned long *var)
@@ -503,8 +503,7 @@ bool wbt_disabled(struct request_queue *q)
 {
 	struct rq_qos *rqos = wbt_rq_qos(q);
 
-	return !rqos || RQWB(rqos)->enable_state == WBT_STATE_OFF_DEFAULT ||
-	       RQWB(rqos)->enable_state == WBT_STATE_OFF_MANUAL;
+	return !rqos || !rwb_enabled(RQWB(rqos));
 }
 
 u64 wbt_get_min_lat(struct request_queue *q)
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH -next 2/3] blk-wbt: freeze queue in wbt_enable/disable_default
  2023-03-04  8:40 [PATCH -next 0/3] blk-wbt: cleanup patches Yu Kuai
  2023-03-04  8:40 ` [PATCH -next 1/3] blk-wbt: cleanup rwb_enabled() and wbt_disabled() Yu Kuai
@ 2023-03-04  8:40 ` Yu Kuai
  2023-03-04  8:40 ` [PATCH -next 3/3] blk-wbt: remove deadcode Yu Kuai
  2 siblings, 0 replies; 4+ messages in thread
From: Yu Kuai @ 2023-03-04  8:40 UTC (permalink / raw
  To: hch, axboe
  Cc: linux-block, linux-kernel, yukuai3, yukuai1, yi.zhang, yangerkun

From: Yu Kuai <yukuai3@huawei.com>

All the caller of wbt_enable/disable_default() ensures that queue is
freezed and quiesced, and it's not a good idea to enable or disable wbt
while io is inflight because this will make implementation complex and
easy to leak wbt inflight counter, which will cause io hang.

This patch just freeze queue in wbt explicitly, there are no functional
changes.

Signed-off-by: Yu Kuai <yukuai3@huawei.com>
---
 block/blk-wbt.c | 22 ++++++++++++++++++----
 1 file changed, 18 insertions(+), 4 deletions(-)

diff --git a/block/blk-wbt.c b/block/blk-wbt.c
index b5edf44499ab..2d5a2f4ee8bc 100644
--- a/block/blk-wbt.c
+++ b/block/blk-wbt.c
@@ -729,24 +729,32 @@ void wbt_enable_default(struct gendisk *disk)
 {
 	struct request_queue *q = disk->queue;
 	struct rq_qos *rqos;
-	bool disable_flag = q->elevator &&
-		    test_bit(ELEVATOR_FLAG_DISABLE_WBT, &q->elevator->flags);
+	bool disable_flag;
 
+	blk_mq_freeze_queue(q);
+	blk_mq_quiesce_queue(q);
+
+	disable_flag = q->elevator && test_bit(ELEVATOR_FLAG_DISABLE_WBT,
+					       &q->elevator->flags);
 	/* Throttling already enabled? */
 	rqos = wbt_rq_qos(q);
 	if (rqos) {
 		if (!disable_flag &&
 		    RQWB(rqos)->enable_state == WBT_STATE_OFF_DEFAULT)
 			RQWB(rqos)->enable_state = WBT_STATE_ON_DEFAULT;
-		return;
+		goto out;
 	}
 
 	/* Queue not registered? Maybe shutting down... */
 	if (!blk_queue_registered(q))
-		return;
+		goto out;
 
 	if (queue_is_mq(q) && !disable_flag)
 		wbt_init(disk);
+
+out:
+	blk_mq_unquiesce_queue(q);
+	blk_mq_unfreeze_queue(q);
 }
 EXPORT_SYMBOL_GPL(wbt_enable_default);
 
@@ -801,8 +809,14 @@ void wbt_disable_default(struct gendisk *disk)
 		return;
 	rwb = RQWB(rqos);
 	if (rwb->enable_state == WBT_STATE_ON_DEFAULT) {
+		blk_mq_freeze_queue(disk->queue);
+		blk_mq_quiesce_queue(disk->queue);
+
 		blk_stat_deactivate(rwb->cb);
 		rwb->enable_state = WBT_STATE_OFF_DEFAULT;
+
+		blk_mq_unquiesce_queue(disk->queue);
+		blk_mq_unfreeze_queue(disk->queue);
 	}
 }
 EXPORT_SYMBOL_GPL(wbt_disable_default);
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH -next 3/3] blk-wbt: remove deadcode
  2023-03-04  8:40 [PATCH -next 0/3] blk-wbt: cleanup patches Yu Kuai
  2023-03-04  8:40 ` [PATCH -next 1/3] blk-wbt: cleanup rwb_enabled() and wbt_disabled() Yu Kuai
  2023-03-04  8:40 ` [PATCH -next 2/3] blk-wbt: freeze queue in wbt_enable/disable_default Yu Kuai
@ 2023-03-04  8:40 ` Yu Kuai
  2 siblings, 0 replies; 4+ messages in thread
From: Yu Kuai @ 2023-03-04  8:40 UTC (permalink / raw
  To: hch, axboe
  Cc: linux-block, linux-kernel, yukuai3, yukuai1, yi.zhang, yangerkun

From: Yu Kuai <yukuai3@huawei.com>

wbt can never be enabled or disabled while io is still inflight.

Signed-off-by: Yu Kuai <yukuai3@huawei.com>
---
 block/blk-wbt.c | 16 ----------------
 1 file changed, 16 deletions(-)

diff --git a/block/blk-wbt.c b/block/blk-wbt.c
index 2d5a2f4ee8bc..247f27a15062 100644
--- a/block/blk-wbt.c
+++ b/block/blk-wbt.c
@@ -200,15 +200,6 @@ static void wbt_rqw_done(struct rq_wb *rwb, struct rq_wait *rqw,
 
 	inflight = atomic_dec_return(&rqw->inflight);
 
-	/*
-	 * wbt got disabled with IO in flight. Wake up any potential
-	 * waiters, we don't have to do more than that.
-	 */
-	if (unlikely(!rwb_enabled(rwb))) {
-		rwb_wake_all(rwb);
-		return;
-	}
-
 	/*
 	 * For discards, our limit is always the background. For writes, if
 	 * the device does write back caching, drop further down before we
@@ -544,13 +535,6 @@ static inline unsigned int get_limit(struct rq_wb *rwb, blk_opf_t opf)
 {
 	unsigned int limit;
 
-	/*
-	 * If we got disabled, just return UINT_MAX. This ensures that
-	 * we'll properly inc a new IO, and dec+wakeup at the end.
-	 */
-	if (!rwb_enabled(rwb))
-		return UINT_MAX;
-
 	if ((opf & REQ_OP_MASK) == REQ_OP_DISCARD)
 		return rwb->wb_background;
 
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-03-04  8:17 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-03-04  8:40 [PATCH -next 0/3] blk-wbt: cleanup patches Yu Kuai
2023-03-04  8:40 ` [PATCH -next 1/3] blk-wbt: cleanup rwb_enabled() and wbt_disabled() Yu Kuai
2023-03-04  8:40 ` [PATCH -next 2/3] blk-wbt: freeze queue in wbt_enable/disable_default Yu Kuai
2023-03-04  8:40 ` [PATCH -next 3/3] blk-wbt: remove deadcode Yu Kuai

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).