From: "Pavel Begunkov (Silence)" <asml.silence@gmail.com>
To: Jens Axboe <axboe@kernel.dk>,
linux-block@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: Pavel Begunkov <asml.silence@gmail.com>
Subject: [PATCH 7/7] blk-mq: Adjust hybrid poll sleep time
Date: Tue, 30 Apr 2019 10:34:19 +0300 [thread overview]
Message-ID: <90ea71d810084eec70fb1632587b450b3037ce85.1556609582.git.asml.silence@gmail.com> (raw)
In-Reply-To: <cover.1556609582.git.asml.silence@gmail.com>
From: Pavel Begunkov <asml.silence@gmail.com>
Sleep for (mean / 2) in the adaptive polling is often too pessimistic,
use a variation of the 3-sigma rule (mean - 4 * lmd) and tune it in
runtime using percentage of missed (i.e. overslept) requests:
1. if more than ~3% of requests are missed, then fallback to (mean / 2)
2. if more than ~0.4% is missed, then scale down
Pitfalls:
1. any missed request increases the mean, synergistically increasing
mean and sleep time, so, scale down fast in the case
2. even if the sleep time is predicted well, sleep loop could greatly
oversleep by itself. Then try to detect it and skip the miss accounting.
Tested on an NVMe SSD:
{4K,8K} read-only workloads give similar latency distribution (up to
7 nines), and decreases CPU load twice (50% -> 25%). New method even
outperform the old one a bit (in terms of throughput and latencies),
presumably, because it alleviates the 2nd pitfall.
For write-only workload it falls back to (mean / 2).
Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
---
block/blk-mq.c | 44 +++++++++++++++++++++++++++++++++++++-------
1 file changed, 37 insertions(+), 7 deletions(-)
diff --git a/block/blk-mq.c b/block/blk-mq.c
index ec7cde754c2f..efa44a617bea 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -3338,10 +3338,21 @@ static void blk_mq_poll_stats_start(struct request_queue *q)
blk_stat_activate_msecs(q->poll_cb, 100);
}
+/*
+ * Thresholds are ilog2(nr_requests / nr_misses)
+ * To calculate tolerated miss ratio from it, use
+ * f(x) ~= 2 ^ -(x + 1)
+ *
+ * fallback ~ 3.1%
+ * throttle ~ 0.4%
+ */
+#define BLK_POLL_FALLBACK_THRESHOLD 4
+#define BLK_POLL_THROTTLE_THRESHOLD 7
+
static void blk_mq_update_poll_info(struct poll_info *pi,
struct blk_rq_stat *stat)
{
- u64 sleep_ns;
+ u64 half_mean, indent, sleep_ns;
u32 nr_misses, nr_samples;
nr_samples = stat->nr_samples;
@@ -3349,14 +3360,33 @@ static void blk_mq_update_poll_info(struct poll_info *pi,
if (nr_misses > nr_samples)
nr_misses = nr_samples;
- if (!nr_samples)
+ half_mean = (stat->mean + 1) / 2;
+ indent = stat->lmd * 4;
+
+ if (!stat->nr_samples) {
sleep_ns = 0;
- else
- sleep_ns = (stat->mean + 1) / 2;
+ } else if (!stat->lmd || stat->mean <= indent) {
+ sleep_ns = half_mean;
+ } else {
+ int ratio = INT_MAX;
- /*
- * Use miss ratio here to adjust sleep time
- */
+ sleep_ns = stat->mean - indent;
+
+ /*
+ * If a completion is overslept, the observable time will
+ * be greater than the actual, so increasing mean. It
+ * also increases sleep time estimation, synergistically
+ * backfiring on mean. Need to scale down / fallback early.
+ */
+ if (nr_misses)
+ ratio = ilog2(nr_samples / nr_misses);
+ if (ratio <= BLK_POLL_FALLBACK_THRESHOLD)
+ sleep_ns = half_mean;
+ else if (ratio <= BLK_POLL_THROTTLE_THRESHOLD)
+ sleep_ns -= sleep_ns / 4;
+
+ sleep_ns = max(sleep_ns, half_mean);
+ }
pi->stat = *stat;
pi->sleep_ns = sleep_ns;
--
2.21.0
next prev parent reply other threads:[~2019-04-30 7:35 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-04-30 7:34 [PATCH 0/7] Adjust hybrid polling " Pavel Begunkov (Silence)
2019-04-30 7:34 ` [PATCH 1/7] blk-iolatency: Fix zero mean in previous stats Pavel Begunkov (Silence)
2019-04-30 7:34 ` [PATCH 2/7] blk-stats: Introduce explicit stat staging buffers Pavel Begunkov (Silence)
2019-04-30 7:34 ` [PATCH 3/7] blk-mq: Fix disabled hybrid polling Pavel Begunkov (Silence)
2019-04-30 7:34 ` [PATCH 4/7] blk-stats: Add left mean deviation to blk_stats Pavel Begunkov (Silence)
2019-04-30 7:34 ` [PATCH 5/7] blk-mq: Precalculate hybrid polling time Pavel Begunkov (Silence)
2019-04-30 7:34 ` [PATCH 6/7] blk-mq: Track num of overslept by hybrid poll rqs Pavel Begunkov (Silence)
2019-04-30 7:34 ` Pavel Begunkov (Silence) [this message]
2019-05-24 9:06 ` [PATCH 0/7] Adjust hybrid polling sleep time Pavel Begunkov
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=90ea71d810084eec70fb1632587b450b3037ce85.1556609582.git.asml.silence@gmail.com \
--to=asml.silence@gmail.com \
--cc=axboe@kernel.dk \
--cc=linux-block@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/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
all inboxes | Powered by JetHome®