All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/3] blk-wbt: simple improvment to enable wbt correctly
@ 2022-09-19  7:09 Yu Kuai
  2022-09-19  7:09 ` [PATCH v2 1/3] wbt: don't show valid wbt_lat_usec in sysfs while wbt is disabled Yu Kuai
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Yu Kuai @ 2022-09-19  7:09 UTC (permalink / raw)
  To: paolo.valente, axboe
  Cc: linux-block, linux-kernel, yukuai3, yukuai1, yi.zhang

From: Yu Kuai <yukuai3@huawei.com>

changes in v2:
 - define new api if wbt config is not enabled in patch 1.

Yu Kuai (3):
  wbt: don't show valid wbt_lat_usec in sysfs while wbt is disabled
  block: add a helper to check elevator name
  blk-wbt: don't enable throttling if default elevator is bfq

 block/bfq-iosched.c |  2 +-
 block/blk-sysfs.c   | 11 +++++++++--
 block/blk-wbt.c     | 13 ++++++++++++-
 block/blk-wbt.h     | 10 ++++++++--
 block/elevator.h    |  5 +++++
 5 files changed, 35 insertions(+), 6 deletions(-)

-- 
2.31.1


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

* [PATCH v2 1/3] wbt: don't show valid wbt_lat_usec in sysfs while wbt is disabled
  2022-09-19  7:09 [PATCH v2 0/3] blk-wbt: simple improvment to enable wbt correctly Yu Kuai
@ 2022-09-19  7:09 ` Yu Kuai
  2022-09-19  7:09 ` [PATCH v2 2/3] block: add a helper to check elevator name Yu Kuai
  2022-09-19  7:09 ` [PATCH v2 3/3] blk-wbt: don't enable throttling if default elevator is bfq Yu Kuai
  2 siblings, 0 replies; 6+ messages in thread
From: Yu Kuai @ 2022-09-19  7:09 UTC (permalink / raw)
  To: paolo.valente, axboe
  Cc: linux-block, linux-kernel, yukuai3, yukuai1, yi.zhang

From: Yu Kuai <yukuai3@huawei.com>

Currently, if wbt is initialized and then disabled by
wbt_disable_default(), sysfs will still show valid wbt_lat_usec, which
will confuse users that wbt is still enabled.

This patch shows wbt_lat_usec as zero and forbid to set it while wbt
is disabled.

Signed-off-by: Yu Kuai <yukuai3@huawei.com>
Reported-and-tested-by: Holger Hoffstätte <holger@applied-asynchrony.com>
---
 block/blk-sysfs.c | 9 ++++++++-
 block/blk-wbt.c   | 7 +++++++
 block/blk-wbt.h   | 5 +++++
 3 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/block/blk-sysfs.c b/block/blk-sysfs.c
index e1f009aba6fd..1955bb6a284d 100644
--- a/block/blk-sysfs.c
+++ b/block/blk-sysfs.c
@@ -467,10 +467,14 @@ static ssize_t queue_io_timeout_store(struct request_queue *q, const char *page,
 
 static ssize_t queue_wb_lat_show(struct request_queue *q, char *page)
 {
+	u64 lat;
+
 	if (!wbt_rq_qos(q))
 		return -EINVAL;
 
-	return sprintf(page, "%llu\n", div_u64(wbt_get_min_lat(q), 1000));
+	lat = wbt_disabled(q) ? 0 : div_u64(wbt_get_min_lat(q), 1000);
+
+	return sprintf(page, "%llu\n", lat);
 }
 
 static ssize_t queue_wb_lat_store(struct request_queue *q, const char *page,
@@ -493,6 +497,9 @@ static ssize_t queue_wb_lat_store(struct request_queue *q, const char *page,
 			return ret;
 	}
 
+	if (wbt_disabled(q))
+		return -EINVAL;
+
 	if (val == -1)
 		val = wbt_default_latency_nsec(q);
 	else if (val >= 0)
diff --git a/block/blk-wbt.c b/block/blk-wbt.c
index a9982000b667..68851c2c02d2 100644
--- a/block/blk-wbt.c
+++ b/block/blk-wbt.c
@@ -422,6 +422,13 @@ static void wbt_update_limits(struct rq_wb *rwb)
 	rwb_wake_all(rwb);
 }
 
+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;
+}
+
 u64 wbt_get_min_lat(struct request_queue *q)
 {
 	struct rq_qos *rqos = wbt_rq_qos(q);
diff --git a/block/blk-wbt.h b/block/blk-wbt.h
index 7e44eccc676d..e42465ddcbb6 100644
--- a/block/blk-wbt.h
+++ b/block/blk-wbt.h
@@ -94,6 +94,7 @@ void wbt_enable_default(struct request_queue *);
 
 u64 wbt_get_min_lat(struct request_queue *q);
 void wbt_set_min_lat(struct request_queue *q, u64 val);
+bool wbt_disabled(struct request_queue *);
 
 void wbt_set_write_cache(struct request_queue *, bool);
 
@@ -125,6 +126,10 @@ static inline u64 wbt_default_latency_nsec(struct request_queue *q)
 {
 	return 0;
 }
+static inline bool wbt_disabled(struct request_queue *q)
+{
+	return true;
+}
 
 #endif /* CONFIG_BLK_WBT */
 
-- 
2.31.1


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

* [PATCH v2 2/3] block: add a helper to check elevator name
  2022-09-19  7:09 [PATCH v2 0/3] blk-wbt: simple improvment to enable wbt correctly Yu Kuai
  2022-09-19  7:09 ` [PATCH v2 1/3] wbt: don't show valid wbt_lat_usec in sysfs while wbt is disabled Yu Kuai
@ 2022-09-19  7:09 ` Yu Kuai
  2022-09-19  7:09 ` [PATCH v2 3/3] blk-wbt: don't enable throttling if default elevator is bfq Yu Kuai
  2 siblings, 0 replies; 6+ messages in thread
From: Yu Kuai @ 2022-09-19  7:09 UTC (permalink / raw)
  To: paolo.valente, axboe
  Cc: linux-block, linux-kernel, yukuai3, yukuai1, yi.zhang

From: Yu Kuai <yukuai3@huawei.com>

The helper will be used in later patch to make sure wbt is not enabled
if default io scheduler is bfq.

Signed-off-by: Yu Kuai <yukuai3@huawei.com>
---
 block/elevator.h | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/block/elevator.h b/block/elevator.h
index 3f0593b3bf9d..2ddc738cae97 100644
--- a/block/elevator.h
+++ b/block/elevator.h
@@ -104,6 +104,11 @@ struct elevator_queue
 	DECLARE_HASHTABLE(hash, ELV_HASH_BITS);
 };
 
+static inline bool check_elevator_name(struct elevator_queue *elevator,
+				       const char *name)
+{
+	return elevator && !strcmp(elevator->type->elevator_name, name);
+}
 /*
  * block elevator interface
  */
-- 
2.31.1


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

* [PATCH v2 3/3] blk-wbt: don't enable throttling if default elevator is bfq
  2022-09-19  7:09 [PATCH v2 0/3] blk-wbt: simple improvment to enable wbt correctly Yu Kuai
  2022-09-19  7:09 ` [PATCH v2 1/3] wbt: don't show valid wbt_lat_usec in sysfs while wbt is disabled Yu Kuai
  2022-09-19  7:09 ` [PATCH v2 2/3] block: add a helper to check elevator name Yu Kuai
@ 2022-09-19  7:09 ` Yu Kuai
  2022-09-20  7:25   ` Christoph Hellwig
  2 siblings, 1 reply; 6+ messages in thread
From: Yu Kuai @ 2022-09-19  7:09 UTC (permalink / raw)
  To: paolo.valente, axboe
  Cc: linux-block, linux-kernel, yukuai3, yukuai1, yi.zhang

From: Yu Kuai <yukuai3@huawei.com>

Commit b5dc5d4d1f4f ("block,bfq: Disable writeback throttling") tries to
disable wbt for bfq, it's done by calling wbt_disable_default() in
bfq_init_queue(). However, wbt is still enabled if default elevator is
bfq:

device_add_disk
 elevator_init_mq
  bfq_init_queue
   wbt_disable_default -> done nothing

 blk_register_queue
  wbt_enable_default -> wbt is enabled

Fix the problem by checking elevator name if wbt_enable_default() is
called from blk_register_queue().

Signed-off-by: Yu Kuai <yukuai3@huawei.com>
---
 block/bfq-iosched.c | 2 +-
 block/blk-sysfs.c   | 2 +-
 block/blk-wbt.c     | 6 +++++-
 block/blk-wbt.h     | 5 +++--
 4 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/block/bfq-iosched.c b/block/bfq-iosched.c
index 7ea427817f7f..f769c90744fd 100644
--- a/block/bfq-iosched.c
+++ b/block/bfq-iosched.c
@@ -7045,7 +7045,7 @@ static void bfq_exit_queue(struct elevator_queue *e)
 #endif
 
 	blk_stat_disable_accounting(bfqd->queue);
-	wbt_enable_default(bfqd->queue);
+	wbt_enable_default(bfqd->queue, false);
 
 	kfree(bfqd);
 }
diff --git a/block/blk-sysfs.c b/block/blk-sysfs.c
index 1955bb6a284d..3e8adb95ff02 100644
--- a/block/blk-sysfs.c
+++ b/block/blk-sysfs.c
@@ -850,7 +850,7 @@ int blk_register_queue(struct gendisk *disk)
 		goto put_dev;
 
 	blk_queue_flag_set(QUEUE_FLAG_REGISTERED, q);
-	wbt_enable_default(q);
+	wbt_enable_default(q, true);
 	blk_throtl_register_queue(q);
 
 	/* Now everything is ready and send out KOBJ_ADD uevent */
diff --git a/block/blk-wbt.c b/block/blk-wbt.c
index 68851c2c02d2..c6256e7c9e8e 100644
--- a/block/blk-wbt.c
+++ b/block/blk-wbt.c
@@ -27,6 +27,7 @@
 
 #include "blk-wbt.h"
 #include "blk-rq-qos.h"
+#include "elevator.h"
 
 #define CREATE_TRACE_POINTS
 #include <trace/events/wbt.h>
@@ -643,10 +644,13 @@ void wbt_set_write_cache(struct request_queue *q, bool write_cache_on)
 /*
  * Enable wbt if defaults are configured that way
  */
-void wbt_enable_default(struct request_queue *q)
+void wbt_enable_default(struct request_queue *q, bool check_elevator)
 {
 	struct rq_qos *rqos = wbt_rq_qos(q);
 
+	if (check_elevator && check_elevator_name(q->elevator, "bfq"))
+		return;
+
 	/* Throttling already enabled? */
 	if (rqos) {
 		if (RQWB(rqos)->enable_state == WBT_STATE_OFF_DEFAULT)
diff --git a/block/blk-wbt.h b/block/blk-wbt.h
index e42465ddcbb6..eb028febaff0 100644
--- a/block/blk-wbt.h
+++ b/block/blk-wbt.h
@@ -90,7 +90,7 @@ static inline unsigned int wbt_inflight(struct rq_wb *rwb)
 
 int wbt_init(struct request_queue *);
 void wbt_disable_default(struct request_queue *);
-void wbt_enable_default(struct request_queue *);
+void wbt_enable_default(struct request_queue *, bool);
 
 u64 wbt_get_min_lat(struct request_queue *q);
 void wbt_set_min_lat(struct request_queue *q, u64 val);
@@ -109,7 +109,8 @@ static inline int wbt_init(struct request_queue *q)
 static inline void wbt_disable_default(struct request_queue *q)
 {
 }
-static inline void wbt_enable_default(struct request_queue *q)
+static inline void wbt_enable_default(struct request_queue *q,
+				      bool check_elevator)
 {
 }
 static inline void wbt_set_write_cache(struct request_queue *q, bool wc)
-- 
2.31.1


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

* Re: [PATCH v2 3/3] blk-wbt: don't enable throttling if default elevator is bfq
  2022-09-19  7:09 ` [PATCH v2 3/3] blk-wbt: don't enable throttling if default elevator is bfq Yu Kuai
@ 2022-09-20  7:25   ` Christoph Hellwig
  2022-09-20  7:48     ` Yu Kuai
  0 siblings, 1 reply; 6+ messages in thread
From: Christoph Hellwig @ 2022-09-20  7:25 UTC (permalink / raw)
  To: Yu Kuai
  Cc: paolo.valente, axboe, linux-block, linux-kernel, yukuai3, yi.zhang

Matching names is always is a bad idea.

Just ad a flags field to elevator_mq_ops, add a DISABLE_WBT flag
to it, and check for that and everything should become much, much
simpler.


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

* Re: [PATCH v2 3/3] blk-wbt: don't enable throttling if default elevator is bfq
  2022-09-20  7:25   ` Christoph Hellwig
@ 2022-09-20  7:48     ` Yu Kuai
  0 siblings, 0 replies; 6+ messages in thread
From: Yu Kuai @ 2022-09-20  7:48 UTC (permalink / raw)
  To: Christoph Hellwig, Yu Kuai
  Cc: paolo.valente, axboe, linux-block, linux-kernel, yi.zhang, yukuai (C)

Hi, Christoph!

在 2022/09/20 15:25, Christoph Hellwig 写道:
> Matching names is always is a bad idea.
> 
> Just ad a flags field to elevator_mq_ops, add a DISABLE_WBT flag
> to it, and check for that and everything should become much, much
> simpler.

Thanks for the adivce, that is a good idea!

Kuai
> 
> .
> 


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

end of thread, other threads:[~2022-09-20  7:50 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-19  7:09 [PATCH v2 0/3] blk-wbt: simple improvment to enable wbt correctly Yu Kuai
2022-09-19  7:09 ` [PATCH v2 1/3] wbt: don't show valid wbt_lat_usec in sysfs while wbt is disabled Yu Kuai
2022-09-19  7:09 ` [PATCH v2 2/3] block: add a helper to check elevator name Yu Kuai
2022-09-19  7:09 ` [PATCH v2 3/3] blk-wbt: don't enable throttling if default elevator is bfq Yu Kuai
2022-09-20  7:25   ` Christoph Hellwig
2022-09-20  7:48     ` Yu Kuai

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.