From: Ming Lei <ming.lei@redhat.com>
To: Jens Axboe <axboe@kernel.dk>, Christoph Hellwig <hch@lst.de>
Cc: linux-block@vger.kernel.org, Ming Lei <ming.lei@redhat.com>,
Yi Zhang <yi.zhang@redhat.com>
Subject: [PATCH 3/4] block: reuse wbt_set_min_lat for setting wbt->min_lat_nsec
Date: Tue, 25 May 2021 16:04:41 +0800 [thread overview]
Message-ID: <20210525080442.1896417-4-ming.lei@redhat.com> (raw)
In-Reply-To: <20210525080442.1896417-1-ming.lei@redhat.com>
We need to freeze queue when setting wbt->min_lat_nsec because
wbt enabled state can be changed, so reuse wbt_set_min_lat() for doing
that for users of wbt_init().
Meantime move wbt_enable_default() out of q->sysfs_lock, since we
don't need that lock for enabling wbt.
Reported-by: Yi Zhang <yi.zhang@redhat.com>
Signed-off-by: Ming Lei <ming.lei@redhat.com>
---
block/blk-sysfs.c | 16 +++-------------
block/blk-wbt.c | 29 ++++++++++++++++++++++-------
block/blk-wbt.h | 4 ++--
3 files changed, 27 insertions(+), 22 deletions(-)
diff --git a/block/blk-sysfs.c b/block/blk-sysfs.c
index 7fd4ffadcdfa..925043f926c5 100644
--- a/block/blk-sysfs.c
+++ b/block/blk-sysfs.c
@@ -498,18 +498,7 @@ static ssize_t queue_wb_lat_store(struct request_queue *q, const char *page,
if (wbt_get_min_lat(q) == val)
return count;
- /*
- * Ensure that the queue is idled, in case the latency update
- * ends up either enabling or disabling wbt completely. We can't
- * have IO inflight if that happens.
- */
- blk_mq_freeze_queue(q);
- blk_mq_quiesce_queue(q);
-
- wbt_set_min_lat(q, val);
-
- blk_mq_unquiesce_queue(q);
- blk_mq_unfreeze_queue(q);
+ wbt_set_min_lat(q, val, true);
return count;
}
@@ -918,7 +907,6 @@ int blk_register_queue(struct gendisk *disk)
}
blk_queue_flag_set(QUEUE_FLAG_REGISTERED, q);
- wbt_enable_default(q);
blk_throtl_register_queue(q);
/* Now everything is ready and send out KOBJ_ADD uevent */
@@ -927,6 +915,8 @@ int blk_register_queue(struct gendisk *disk)
kobject_uevent(&q->elevator->kobj, KOBJ_ADD);
mutex_unlock(&q->sysfs_lock);
+ wbt_enable_default(q);
+
ret = 0;
unlock:
mutex_unlock(&q->sysfs_dir_lock);
diff --git a/block/blk-wbt.c b/block/blk-wbt.c
index 5da48294e3e9..5d2db197cce6 100644
--- a/block/blk-wbt.c
+++ b/block/blk-wbt.c
@@ -24,6 +24,7 @@
#include <linux/slab.h>
#include <linux/backing-dev.h>
#include <linux/swap.h>
+#include <linux/blk-mq.h>
#include "blk-wbt.h"
#include "blk-rq-qos.h"
@@ -425,13 +426,27 @@ u64 wbt_get_min_lat(struct request_queue *q)
return RQWB(rqos)->min_lat_nsec;
}
-void wbt_set_min_lat(struct request_queue *q, u64 val)
+void wbt_set_min_lat(struct request_queue *q, u64 val, bool manual)
{
struct rq_qos *rqos = wbt_rq_qos(q);
+ /*
+ * Ensure that the queue is idled, in case the latency update
+ * ends up either enabling or disabling wbt completely. We can't
+ * have IO inflight if that happens.
+ */
+ blk_mq_freeze_queue(q);
+ blk_mq_quiesce_queue(q);
+
RQWB(rqos)->min_lat_nsec = val;
- RQWB(rqos)->enable_state = WBT_STATE_ON_MANUAL;
+ if (manual)
+ RQWB(rqos)->enable_state = WBT_STATE_ON_MANUAL;
+ else
+ RQWB(rqos)->enable_state = WBT_STATE_ON_DEFAULT;
wbt_update_limits(RQWB(rqos));
+
+ blk_mq_unquiesce_queue(q);
+ blk_mq_unfreeze_queue(q);
}
@@ -844,11 +859,11 @@ int wbt_alloc(struct request_queue *q)
void wbt_init(struct request_queue *q)
{
- struct rq_wb *rwb = RQWB(wbt_rq_qos(q));
-
- rwb->enable_state = WBT_STATE_ON_DEFAULT;
- rwb->min_lat_nsec = wbt_default_latency_nsec(q);
+ struct rq_qos *rqos = wbt_rq_qos(q);
+ struct rq_wb *rwb = RQWB(rqos);
- wbt_queue_depth_changed(&rwb->rqos);
+ rwb->rq_depth.queue_depth = blk_queue_depth(rqos->q);
wbt_set_write_cache(q, test_bit(QUEUE_FLAG_WC, &q->queue_flags));
+
+ wbt_set_min_lat(q, wbt_default_latency_nsec(q), false);
}
diff --git a/block/blk-wbt.h b/block/blk-wbt.h
index de07963f3544..d9b643a55407 100644
--- a/block/blk-wbt.h
+++ b/block/blk-wbt.h
@@ -93,7 +93,7 @@ void wbt_disable_default(struct request_queue *);
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);
+void wbt_set_min_lat(struct request_queue *q, u64 val, bool manual);
void wbt_set_write_cache(struct request_queue *, bool);
@@ -124,7 +124,7 @@ static inline u64 wbt_get_min_lat(struct request_queue *q)
{
return 0;
}
-static inline void wbt_set_min_lat(struct request_queue *q, u64 val)
+static inline void wbt_set_min_lat(struct request_queue *q, u64 val, bool manual)
{
}
static inline u64 wbt_default_latency_nsec(struct request_queue *q)
--
2.29.2
next prev parent reply other threads:[~2021-05-25 8:08 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-05-25 8:04 [PATCH 0/4] block: fix race between adding wbt and normal IO Ming Lei
2021-05-25 8:04 ` [PATCH 1/4] block: split wbt_init() into two parts Ming Lei
2021-06-04 0:32 ` Bart Van Assche
2021-05-25 8:04 ` [PATCH 2/4] block: move wbt allocation into blk_alloc_queue Ming Lei
2021-06-04 0:44 ` Bart Van Assche
2021-06-04 1:22 ` Ming Lei
2021-05-25 8:04 ` Ming Lei [this message]
2021-05-25 8:04 ` [PATCH 4/4] block: mark queue init done at the end of blk_register_queue Ming Lei
2021-06-04 0:03 ` [PATCH 0/4] block: fix race between adding wbt and normal IO Ming Lei
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210525080442.1896417-4-ming.lei@redhat.com \
--to=ming.lei@redhat.com \
--cc=axboe@kernel.dk \
--cc=hch@lst.de \
--cc=linux-block@vger.kernel.org \
--cc=yi.zhang@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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 NNTP newsgroup(s).