2019-04-30 21:42:39 +03:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2017-04-14 11:00:02 +03:00
|
|
|
/*
|
|
|
|
* The Kyber I/O scheduler. Controls latency by throttling queue depths using
|
|
|
|
* scalable techniques.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2017 Facebook
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/blkdev.h>
|
|
|
|
#include <linux/blk-mq.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/sbitmap.h>
|
|
|
|
|
2021-02-22 08:29:59 +03:00
|
|
|
#include <trace/events/block.h>
|
|
|
|
|
2021-09-20 15:33:23 +03:00
|
|
|
#include "elevator.h"
|
2017-04-14 11:00:02 +03:00
|
|
|
#include "blk.h"
|
|
|
|
#include "blk-mq.h"
|
2017-05-04 10:31:33 +03:00
|
|
|
#include "blk-mq-debugfs.h"
|
2017-04-14 11:00:02 +03:00
|
|
|
#include "blk-mq-sched.h"
|
|
|
|
#include "blk-mq-tag.h"
|
|
|
|
|
2018-09-28 01:55:55 +03:00
|
|
|
#define CREATE_TRACE_POINTS
|
|
|
|
#include <trace/events/kyber.h>
|
|
|
|
|
kyber: implement improved heuristics
Kyber's current heuristics have a few flaws:
- It's based on the mean latency, but p99 latency tends to be more
meaningful to anyone who cares about latency. The mean can also be
skewed by rare outliers that the scheduler can't do anything about.
- The statistics calculations are purely time-based with a short window.
This works for steady, high load, but is more sensitive to outliers
with bursty workloads.
- It only considers the latency once an I/O has been submitted to the
device, but the user cares about the time spent in the kernel, as
well.
These are shortcomings of the generic blk-stat code which doesn't quite
fit the ideal use case for Kyber. So, this replaces the statistics with
a histogram used to calculate percentiles of total latency and I/O
latency, which we then use to adjust depths in a slightly more
intelligent manner:
- Sync and async writes are now the same domain.
- Discards are a separate domain.
- Domain queue depths are scaled by the ratio of the p99 total latency
to the target latency (e.g., if the p99 latency is double the target
latency, we will double the queue depth; if the p99 latency is half of
the target latency, we can halve the queue depth).
- We use the I/O latency to determine whether we should scale queue
depths down: we will only scale down if any domain's I/O latency
exceeds the target latency, which is an indicator of congestion in the
device.
These new heuristics are just as scalable as the heuristics they
replace.
Signed-off-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2018-09-28 01:55:54 +03:00
|
|
|
/*
|
|
|
|
* Scheduling domains: the device is divided into multiple domains based on the
|
|
|
|
* request type.
|
|
|
|
*/
|
2017-04-14 11:00:02 +03:00
|
|
|
enum {
|
|
|
|
KYBER_READ,
|
kyber: implement improved heuristics
Kyber's current heuristics have a few flaws:
- It's based on the mean latency, but p99 latency tends to be more
meaningful to anyone who cares about latency. The mean can also be
skewed by rare outliers that the scheduler can't do anything about.
- The statistics calculations are purely time-based with a short window.
This works for steady, high load, but is more sensitive to outliers
with bursty workloads.
- It only considers the latency once an I/O has been submitted to the
device, but the user cares about the time spent in the kernel, as
well.
These are shortcomings of the generic blk-stat code which doesn't quite
fit the ideal use case for Kyber. So, this replaces the statistics with
a histogram used to calculate percentiles of total latency and I/O
latency, which we then use to adjust depths in a slightly more
intelligent manner:
- Sync and async writes are now the same domain.
- Discards are a separate domain.
- Domain queue depths are scaled by the ratio of the p99 total latency
to the target latency (e.g., if the p99 latency is double the target
latency, we will double the queue depth; if the p99 latency is half of
the target latency, we can halve the queue depth).
- We use the I/O latency to determine whether we should scale queue
depths down: we will only scale down if any domain's I/O latency
exceeds the target latency, which is an indicator of congestion in the
device.
These new heuristics are just as scalable as the heuristics they
replace.
Signed-off-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2018-09-28 01:55:54 +03:00
|
|
|
KYBER_WRITE,
|
|
|
|
KYBER_DISCARD,
|
|
|
|
KYBER_OTHER,
|
2017-04-14 11:00:02 +03:00
|
|
|
KYBER_NUM_DOMAINS,
|
|
|
|
};
|
|
|
|
|
2018-09-28 01:55:55 +03:00
|
|
|
static const char *kyber_domain_names[] = {
|
|
|
|
[KYBER_READ] = "READ",
|
|
|
|
[KYBER_WRITE] = "WRITE",
|
|
|
|
[KYBER_DISCARD] = "DISCARD",
|
|
|
|
[KYBER_OTHER] = "OTHER",
|
|
|
|
};
|
|
|
|
|
2017-04-14 11:00:02 +03:00
|
|
|
enum {
|
|
|
|
/*
|
|
|
|
* In order to prevent starvation of synchronous requests by a flood of
|
|
|
|
* asynchronous requests, we reserve 25% of requests for synchronous
|
|
|
|
* operations.
|
|
|
|
*/
|
|
|
|
KYBER_ASYNC_PERCENT = 75,
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
kyber: implement improved heuristics
Kyber's current heuristics have a few flaws:
- It's based on the mean latency, but p99 latency tends to be more
meaningful to anyone who cares about latency. The mean can also be
skewed by rare outliers that the scheduler can't do anything about.
- The statistics calculations are purely time-based with a short window.
This works for steady, high load, but is more sensitive to outliers
with bursty workloads.
- It only considers the latency once an I/O has been submitted to the
device, but the user cares about the time spent in the kernel, as
well.
These are shortcomings of the generic blk-stat code which doesn't quite
fit the ideal use case for Kyber. So, this replaces the statistics with
a histogram used to calculate percentiles of total latency and I/O
latency, which we then use to adjust depths in a slightly more
intelligent manner:
- Sync and async writes are now the same domain.
- Discards are a separate domain.
- Domain queue depths are scaled by the ratio of the p99 total latency
to the target latency (e.g., if the p99 latency is double the target
latency, we will double the queue depth; if the p99 latency is half of
the target latency, we can halve the queue depth).
- We use the I/O latency to determine whether we should scale queue
depths down: we will only scale down if any domain's I/O latency
exceeds the target latency, which is an indicator of congestion in the
device.
These new heuristics are just as scalable as the heuristics they
replace.
Signed-off-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2018-09-28 01:55:54 +03:00
|
|
|
* Maximum device-wide depth for each scheduling domain.
|
2017-04-14 11:00:02 +03:00
|
|
|
*
|
kyber: implement improved heuristics
Kyber's current heuristics have a few flaws:
- It's based on the mean latency, but p99 latency tends to be more
meaningful to anyone who cares about latency. The mean can also be
skewed by rare outliers that the scheduler can't do anything about.
- The statistics calculations are purely time-based with a short window.
This works for steady, high load, but is more sensitive to outliers
with bursty workloads.
- It only considers the latency once an I/O has been submitted to the
device, but the user cares about the time spent in the kernel, as
well.
These are shortcomings of the generic blk-stat code which doesn't quite
fit the ideal use case for Kyber. So, this replaces the statistics with
a histogram used to calculate percentiles of total latency and I/O
latency, which we then use to adjust depths in a slightly more
intelligent manner:
- Sync and async writes are now the same domain.
- Discards are a separate domain.
- Domain queue depths are scaled by the ratio of the p99 total latency
to the target latency (e.g., if the p99 latency is double the target
latency, we will double the queue depth; if the p99 latency is half of
the target latency, we can halve the queue depth).
- We use the I/O latency to determine whether we should scale queue
depths down: we will only scale down if any domain's I/O latency
exceeds the target latency, which is an indicator of congestion in the
device.
These new heuristics are just as scalable as the heuristics they
replace.
Signed-off-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2018-09-28 01:55:54 +03:00
|
|
|
* Even for fast devices with lots of tags like NVMe, you can saturate the
|
|
|
|
* device with only a fraction of the maximum possible queue depth. So, we cap
|
|
|
|
* these to a reasonable value.
|
2017-04-14 11:00:02 +03:00
|
|
|
*/
|
|
|
|
static const unsigned int kyber_depth[] = {
|
|
|
|
[KYBER_READ] = 256,
|
kyber: implement improved heuristics
Kyber's current heuristics have a few flaws:
- It's based on the mean latency, but p99 latency tends to be more
meaningful to anyone who cares about latency. The mean can also be
skewed by rare outliers that the scheduler can't do anything about.
- The statistics calculations are purely time-based with a short window.
This works for steady, high load, but is more sensitive to outliers
with bursty workloads.
- It only considers the latency once an I/O has been submitted to the
device, but the user cares about the time spent in the kernel, as
well.
These are shortcomings of the generic blk-stat code which doesn't quite
fit the ideal use case for Kyber. So, this replaces the statistics with
a histogram used to calculate percentiles of total latency and I/O
latency, which we then use to adjust depths in a slightly more
intelligent manner:
- Sync and async writes are now the same domain.
- Discards are a separate domain.
- Domain queue depths are scaled by the ratio of the p99 total latency
to the target latency (e.g., if the p99 latency is double the target
latency, we will double the queue depth; if the p99 latency is half of
the target latency, we can halve the queue depth).
- We use the I/O latency to determine whether we should scale queue
depths down: we will only scale down if any domain's I/O latency
exceeds the target latency, which is an indicator of congestion in the
device.
These new heuristics are just as scalable as the heuristics they
replace.
Signed-off-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2018-09-28 01:55:54 +03:00
|
|
|
[KYBER_WRITE] = 128,
|
|
|
|
[KYBER_DISCARD] = 64,
|
|
|
|
[KYBER_OTHER] = 16,
|
2017-04-14 11:00:02 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
kyber: implement improved heuristics
Kyber's current heuristics have a few flaws:
- It's based on the mean latency, but p99 latency tends to be more
meaningful to anyone who cares about latency. The mean can also be
skewed by rare outliers that the scheduler can't do anything about.
- The statistics calculations are purely time-based with a short window.
This works for steady, high load, but is more sensitive to outliers
with bursty workloads.
- It only considers the latency once an I/O has been submitted to the
device, but the user cares about the time spent in the kernel, as
well.
These are shortcomings of the generic blk-stat code which doesn't quite
fit the ideal use case for Kyber. So, this replaces the statistics with
a histogram used to calculate percentiles of total latency and I/O
latency, which we then use to adjust depths in a slightly more
intelligent manner:
- Sync and async writes are now the same domain.
- Discards are a separate domain.
- Domain queue depths are scaled by the ratio of the p99 total latency
to the target latency (e.g., if the p99 latency is double the target
latency, we will double the queue depth; if the p99 latency is half of
the target latency, we can halve the queue depth).
- We use the I/O latency to determine whether we should scale queue
depths down: we will only scale down if any domain's I/O latency
exceeds the target latency, which is an indicator of congestion in the
device.
These new heuristics are just as scalable as the heuristics they
replace.
Signed-off-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2018-09-28 01:55:54 +03:00
|
|
|
* Default latency targets for each scheduling domain.
|
|
|
|
*/
|
|
|
|
static const u64 kyber_latency_targets[] = {
|
2018-09-28 19:22:50 +03:00
|
|
|
[KYBER_READ] = 2ULL * NSEC_PER_MSEC,
|
|
|
|
[KYBER_WRITE] = 10ULL * NSEC_PER_MSEC,
|
|
|
|
[KYBER_DISCARD] = 5ULL * NSEC_PER_SEC,
|
kyber: implement improved heuristics
Kyber's current heuristics have a few flaws:
- It's based on the mean latency, but p99 latency tends to be more
meaningful to anyone who cares about latency. The mean can also be
skewed by rare outliers that the scheduler can't do anything about.
- The statistics calculations are purely time-based with a short window.
This works for steady, high load, but is more sensitive to outliers
with bursty workloads.
- It only considers the latency once an I/O has been submitted to the
device, but the user cares about the time spent in the kernel, as
well.
These are shortcomings of the generic blk-stat code which doesn't quite
fit the ideal use case for Kyber. So, this replaces the statistics with
a histogram used to calculate percentiles of total latency and I/O
latency, which we then use to adjust depths in a slightly more
intelligent manner:
- Sync and async writes are now the same domain.
- Discards are a separate domain.
- Domain queue depths are scaled by the ratio of the p99 total latency
to the target latency (e.g., if the p99 latency is double the target
latency, we will double the queue depth; if the p99 latency is half of
the target latency, we can halve the queue depth).
- We use the I/O latency to determine whether we should scale queue
depths down: we will only scale down if any domain's I/O latency
exceeds the target latency, which is an indicator of congestion in the
device.
These new heuristics are just as scalable as the heuristics they
replace.
Signed-off-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2018-09-28 01:55:54 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Batch size (number of requests we'll dispatch in a row) for each scheduling
|
|
|
|
* domain.
|
2017-04-14 11:00:02 +03:00
|
|
|
*/
|
|
|
|
static const unsigned int kyber_batch_size[] = {
|
|
|
|
[KYBER_READ] = 16,
|
kyber: implement improved heuristics
Kyber's current heuristics have a few flaws:
- It's based on the mean latency, but p99 latency tends to be more
meaningful to anyone who cares about latency. The mean can also be
skewed by rare outliers that the scheduler can't do anything about.
- The statistics calculations are purely time-based with a short window.
This works for steady, high load, but is more sensitive to outliers
with bursty workloads.
- It only considers the latency once an I/O has been submitted to the
device, but the user cares about the time spent in the kernel, as
well.
These are shortcomings of the generic blk-stat code which doesn't quite
fit the ideal use case for Kyber. So, this replaces the statistics with
a histogram used to calculate percentiles of total latency and I/O
latency, which we then use to adjust depths in a slightly more
intelligent manner:
- Sync and async writes are now the same domain.
- Discards are a separate domain.
- Domain queue depths are scaled by the ratio of the p99 total latency
to the target latency (e.g., if the p99 latency is double the target
latency, we will double the queue depth; if the p99 latency is half of
the target latency, we can halve the queue depth).
- We use the I/O latency to determine whether we should scale queue
depths down: we will only scale down if any domain's I/O latency
exceeds the target latency, which is an indicator of congestion in the
device.
These new heuristics are just as scalable as the heuristics they
replace.
Signed-off-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2018-09-28 01:55:54 +03:00
|
|
|
[KYBER_WRITE] = 8,
|
|
|
|
[KYBER_DISCARD] = 1,
|
|
|
|
[KYBER_OTHER] = 1,
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Requests latencies are recorded in a histogram with buckets defined relative
|
|
|
|
* to the target latency:
|
|
|
|
*
|
|
|
|
* <= 1/4 * target latency
|
|
|
|
* <= 1/2 * target latency
|
|
|
|
* <= 3/4 * target latency
|
|
|
|
* <= target latency
|
|
|
|
* <= 1 1/4 * target latency
|
|
|
|
* <= 1 1/2 * target latency
|
|
|
|
* <= 1 3/4 * target latency
|
|
|
|
* > 1 3/4 * target latency
|
|
|
|
*/
|
|
|
|
enum {
|
|
|
|
/*
|
|
|
|
* The width of the latency histogram buckets is
|
|
|
|
* 1 / (1 << KYBER_LATENCY_SHIFT) * target latency.
|
|
|
|
*/
|
|
|
|
KYBER_LATENCY_SHIFT = 2,
|
|
|
|
/*
|
|
|
|
* The first (1 << KYBER_LATENCY_SHIFT) buckets are <= target latency,
|
|
|
|
* thus, "good".
|
|
|
|
*/
|
|
|
|
KYBER_GOOD_BUCKETS = 1 << KYBER_LATENCY_SHIFT,
|
|
|
|
/* There are also (1 << KYBER_LATENCY_SHIFT) "bad" buckets. */
|
|
|
|
KYBER_LATENCY_BUCKETS = 2 << KYBER_LATENCY_SHIFT,
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We measure both the total latency and the I/O latency (i.e., latency after
|
|
|
|
* submitting to the device).
|
|
|
|
*/
|
|
|
|
enum {
|
|
|
|
KYBER_TOTAL_LATENCY,
|
|
|
|
KYBER_IO_LATENCY,
|
|
|
|
};
|
|
|
|
|
2018-09-28 01:55:55 +03:00
|
|
|
static const char *kyber_latency_type_names[] = {
|
|
|
|
[KYBER_TOTAL_LATENCY] = "total",
|
|
|
|
[KYBER_IO_LATENCY] = "I/O",
|
|
|
|
};
|
|
|
|
|
kyber: implement improved heuristics
Kyber's current heuristics have a few flaws:
- It's based on the mean latency, but p99 latency tends to be more
meaningful to anyone who cares about latency. The mean can also be
skewed by rare outliers that the scheduler can't do anything about.
- The statistics calculations are purely time-based with a short window.
This works for steady, high load, but is more sensitive to outliers
with bursty workloads.
- It only considers the latency once an I/O has been submitted to the
device, but the user cares about the time spent in the kernel, as
well.
These are shortcomings of the generic blk-stat code which doesn't quite
fit the ideal use case for Kyber. So, this replaces the statistics with
a histogram used to calculate percentiles of total latency and I/O
latency, which we then use to adjust depths in a slightly more
intelligent manner:
- Sync and async writes are now the same domain.
- Discards are a separate domain.
- Domain queue depths are scaled by the ratio of the p99 total latency
to the target latency (e.g., if the p99 latency is double the target
latency, we will double the queue depth; if the p99 latency is half of
the target latency, we can halve the queue depth).
- We use the I/O latency to determine whether we should scale queue
depths down: we will only scale down if any domain's I/O latency
exceeds the target latency, which is an indicator of congestion in the
device.
These new heuristics are just as scalable as the heuristics they
replace.
Signed-off-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2018-09-28 01:55:54 +03:00
|
|
|
/*
|
|
|
|
* Per-cpu latency histograms: total latency and I/O latency for each scheduling
|
|
|
|
* domain except for KYBER_OTHER.
|
|
|
|
*/
|
|
|
|
struct kyber_cpu_latency {
|
|
|
|
atomic_t buckets[KYBER_OTHER][2][KYBER_LATENCY_BUCKETS];
|
2017-04-14 11:00:02 +03:00
|
|
|
};
|
|
|
|
|
block: kyber: make kyber more friendly with merging
Currently, kyber is very unfriendly with merging. kyber depends
on ctx rq_list to do merging, however, most of time, it will not
leave any requests in ctx rq_list. This is because even if tokens
of one domain is used up, kyber will try to dispatch requests
from other domain and flush the rq_list there.
To improve this, we setup kyber_ctx_queue (kcq) which is similar
with ctx, but it has rq_lists for different domain and build same
mapping between kcq and khd as the ctx & hctx. Then we could merge,
insert and dispatch for different domains separately. At the same
time, only flush the rq_list of kcq when get domain token successfully.
Then if one domain token is used up, the requests could be left in
the rq_list of that domain and maybe merged with following io.
Following is my test result on machine with 8 cores and NVMe card
INTEL SSDPEKKR128G7
fio size=256m ioengine=libaio iodepth=64 direct=1 numjobs=8
seq/random
+------+---------------------------------------------------------------+
|patch?| bw(MB/s) | iops | slat(usec) | clat(usec) | merge |
+----------------------------------------------------------------------+
| w/o | 606/612 | 151k/153k | 6.89/7.03 | 3349.21/3305.40 | 0/0 |
+----------------------------------------------------------------------+
| w/ | 1083/616 | 277k/154k | 4.93/6.95 | 1830.62/3279.95 | 223k/3k |
+----------------------------------------------------------------------+
When set numjobs to 16, the bw and iops could reach 1662MB/s and 425k
on my platform.
Signed-off-by: Jianchao Wang <jianchao.w.wang@oracle.com>
Tested-by: Holger Hoffstätte <holger@applied-asynchrony.com>
Reviewed-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2018-05-30 19:47:40 +03:00
|
|
|
/*
|
|
|
|
* There is a same mapping between ctx & hctx and kcq & khd,
|
|
|
|
* we use request->mq_ctx->index_hw to index the kcq in khd.
|
|
|
|
*/
|
|
|
|
struct kyber_ctx_queue {
|
|
|
|
/*
|
|
|
|
* Used to ensure operations on rq_list and kcq_map to be an atmoic one.
|
|
|
|
* Also protect the rqs on rq_list when merge.
|
|
|
|
*/
|
|
|
|
spinlock_t lock;
|
|
|
|
struct list_head rq_list[KYBER_NUM_DOMAINS];
|
|
|
|
} ____cacheline_aligned_in_smp;
|
|
|
|
|
2017-04-14 11:00:02 +03:00
|
|
|
struct kyber_queue_data {
|
2018-09-28 01:55:55 +03:00
|
|
|
struct request_queue *q;
|
2021-10-12 12:33:01 +03:00
|
|
|
dev_t dev;
|
2018-09-28 01:55:55 +03:00
|
|
|
|
2017-04-14 11:00:02 +03:00
|
|
|
/*
|
kyber: implement improved heuristics
Kyber's current heuristics have a few flaws:
- It's based on the mean latency, but p99 latency tends to be more
meaningful to anyone who cares about latency. The mean can also be
skewed by rare outliers that the scheduler can't do anything about.
- The statistics calculations are purely time-based with a short window.
This works for steady, high load, but is more sensitive to outliers
with bursty workloads.
- It only considers the latency once an I/O has been submitted to the
device, but the user cares about the time spent in the kernel, as
well.
These are shortcomings of the generic blk-stat code which doesn't quite
fit the ideal use case for Kyber. So, this replaces the statistics with
a histogram used to calculate percentiles of total latency and I/O
latency, which we then use to adjust depths in a slightly more
intelligent manner:
- Sync and async writes are now the same domain.
- Discards are a separate domain.
- Domain queue depths are scaled by the ratio of the p99 total latency
to the target latency (e.g., if the p99 latency is double the target
latency, we will double the queue depth; if the p99 latency is half of
the target latency, we can halve the queue depth).
- We use the I/O latency to determine whether we should scale queue
depths down: we will only scale down if any domain's I/O latency
exceeds the target latency, which is an indicator of congestion in the
device.
These new heuristics are just as scalable as the heuristics they
replace.
Signed-off-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2018-09-28 01:55:54 +03:00
|
|
|
* Each scheduling domain has a limited number of in-flight requests
|
|
|
|
* device-wide, limited by these tokens.
|
2017-04-14 11:00:02 +03:00
|
|
|
*/
|
|
|
|
struct sbitmap_queue domain_tokens[KYBER_NUM_DOMAINS];
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Async request percentage, converted to per-word depth for
|
|
|
|
* sbitmap_get_shallow().
|
|
|
|
*/
|
|
|
|
unsigned int async_depth;
|
|
|
|
|
kyber: implement improved heuristics
Kyber's current heuristics have a few flaws:
- It's based on the mean latency, but p99 latency tends to be more
meaningful to anyone who cares about latency. The mean can also be
skewed by rare outliers that the scheduler can't do anything about.
- The statistics calculations are purely time-based with a short window.
This works for steady, high load, but is more sensitive to outliers
with bursty workloads.
- It only considers the latency once an I/O has been submitted to the
device, but the user cares about the time spent in the kernel, as
well.
These are shortcomings of the generic blk-stat code which doesn't quite
fit the ideal use case for Kyber. So, this replaces the statistics with
a histogram used to calculate percentiles of total latency and I/O
latency, which we then use to adjust depths in a slightly more
intelligent manner:
- Sync and async writes are now the same domain.
- Discards are a separate domain.
- Domain queue depths are scaled by the ratio of the p99 total latency
to the target latency (e.g., if the p99 latency is double the target
latency, we will double the queue depth; if the p99 latency is half of
the target latency, we can halve the queue depth).
- We use the I/O latency to determine whether we should scale queue
depths down: we will only scale down if any domain's I/O latency
exceeds the target latency, which is an indicator of congestion in the
device.
These new heuristics are just as scalable as the heuristics they
replace.
Signed-off-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2018-09-28 01:55:54 +03:00
|
|
|
struct kyber_cpu_latency __percpu *cpu_latency;
|
|
|
|
|
|
|
|
/* Timer for stats aggregation and adjusting domain tokens. */
|
|
|
|
struct timer_list timer;
|
|
|
|
|
|
|
|
unsigned int latency_buckets[KYBER_OTHER][2][KYBER_LATENCY_BUCKETS];
|
|
|
|
|
|
|
|
unsigned long latency_timeout[KYBER_OTHER];
|
|
|
|
|
|
|
|
int domain_p99[KYBER_OTHER];
|
|
|
|
|
2017-04-14 11:00:02 +03:00
|
|
|
/* Target latencies in nanoseconds. */
|
kyber: implement improved heuristics
Kyber's current heuristics have a few flaws:
- It's based on the mean latency, but p99 latency tends to be more
meaningful to anyone who cares about latency. The mean can also be
skewed by rare outliers that the scheduler can't do anything about.
- The statistics calculations are purely time-based with a short window.
This works for steady, high load, but is more sensitive to outliers
with bursty workloads.
- It only considers the latency once an I/O has been submitted to the
device, but the user cares about the time spent in the kernel, as
well.
These are shortcomings of the generic blk-stat code which doesn't quite
fit the ideal use case for Kyber. So, this replaces the statistics with
a histogram used to calculate percentiles of total latency and I/O
latency, which we then use to adjust depths in a slightly more
intelligent manner:
- Sync and async writes are now the same domain.
- Discards are a separate domain.
- Domain queue depths are scaled by the ratio of the p99 total latency
to the target latency (e.g., if the p99 latency is double the target
latency, we will double the queue depth; if the p99 latency is half of
the target latency, we can halve the queue depth).
- We use the I/O latency to determine whether we should scale queue
depths down: we will only scale down if any domain's I/O latency
exceeds the target latency, which is an indicator of congestion in the
device.
These new heuristics are just as scalable as the heuristics they
replace.
Signed-off-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2018-09-28 01:55:54 +03:00
|
|
|
u64 latency_targets[KYBER_OTHER];
|
2017-04-14 11:00:02 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
struct kyber_hctx_data {
|
|
|
|
spinlock_t lock;
|
|
|
|
struct list_head rqs[KYBER_NUM_DOMAINS];
|
|
|
|
unsigned int cur_domain;
|
|
|
|
unsigned int batching;
|
block: kyber: make kyber more friendly with merging
Currently, kyber is very unfriendly with merging. kyber depends
on ctx rq_list to do merging, however, most of time, it will not
leave any requests in ctx rq_list. This is because even if tokens
of one domain is used up, kyber will try to dispatch requests
from other domain and flush the rq_list there.
To improve this, we setup kyber_ctx_queue (kcq) which is similar
with ctx, but it has rq_lists for different domain and build same
mapping between kcq and khd as the ctx & hctx. Then we could merge,
insert and dispatch for different domains separately. At the same
time, only flush the rq_list of kcq when get domain token successfully.
Then if one domain token is used up, the requests could be left in
the rq_list of that domain and maybe merged with following io.
Following is my test result on machine with 8 cores and NVMe card
INTEL SSDPEKKR128G7
fio size=256m ioengine=libaio iodepth=64 direct=1 numjobs=8
seq/random
+------+---------------------------------------------------------------+
|patch?| bw(MB/s) | iops | slat(usec) | clat(usec) | merge |
+----------------------------------------------------------------------+
| w/o | 606/612 | 151k/153k | 6.89/7.03 | 3349.21/3305.40 | 0/0 |
+----------------------------------------------------------------------+
| w/ | 1083/616 | 277k/154k | 4.93/6.95 | 1830.62/3279.95 | 223k/3k |
+----------------------------------------------------------------------+
When set numjobs to 16, the bw and iops could reach 1662MB/s and 425k
on my platform.
Signed-off-by: Jianchao Wang <jianchao.w.wang@oracle.com>
Tested-by: Holger Hoffstätte <holger@applied-asynchrony.com>
Reviewed-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2018-05-30 19:47:40 +03:00
|
|
|
struct kyber_ctx_queue *kcqs;
|
|
|
|
struct sbitmap kcq_map[KYBER_NUM_DOMAINS];
|
2018-12-20 18:50:58 +03:00
|
|
|
struct sbq_wait domain_wait[KYBER_NUM_DOMAINS];
|
2017-12-06 09:57:43 +03:00
|
|
|
struct sbq_wait_state *domain_ws[KYBER_NUM_DOMAINS];
|
2017-04-14 11:00:02 +03:00
|
|
|
atomic_t wait_index[KYBER_NUM_DOMAINS];
|
|
|
|
};
|
|
|
|
|
2017-12-06 09:57:43 +03:00
|
|
|
static int kyber_domain_wake(wait_queue_entry_t *wait, unsigned mode, int flags,
|
|
|
|
void *key);
|
|
|
|
|
2022-07-14 21:06:35 +03:00
|
|
|
static unsigned int kyber_sched_domain(blk_opf_t opf)
|
2017-04-14 11:00:02 +03:00
|
|
|
{
|
2022-07-14 21:06:35 +03:00
|
|
|
switch (opf & REQ_OP_MASK) {
|
kyber: implement improved heuristics
Kyber's current heuristics have a few flaws:
- It's based on the mean latency, but p99 latency tends to be more
meaningful to anyone who cares about latency. The mean can also be
skewed by rare outliers that the scheduler can't do anything about.
- The statistics calculations are purely time-based with a short window.
This works for steady, high load, but is more sensitive to outliers
with bursty workloads.
- It only considers the latency once an I/O has been submitted to the
device, but the user cares about the time spent in the kernel, as
well.
These are shortcomings of the generic blk-stat code which doesn't quite
fit the ideal use case for Kyber. So, this replaces the statistics with
a histogram used to calculate percentiles of total latency and I/O
latency, which we then use to adjust depths in a slightly more
intelligent manner:
- Sync and async writes are now the same domain.
- Discards are a separate domain.
- Domain queue depths are scaled by the ratio of the p99 total latency
to the target latency (e.g., if the p99 latency is double the target
latency, we will double the queue depth; if the p99 latency is half of
the target latency, we can halve the queue depth).
- We use the I/O latency to determine whether we should scale queue
depths down: we will only scale down if any domain's I/O latency
exceeds the target latency, which is an indicator of congestion in the
device.
These new heuristics are just as scalable as the heuristics they
replace.
Signed-off-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2018-09-28 01:55:54 +03:00
|
|
|
case REQ_OP_READ:
|
2017-04-14 11:00:02 +03:00
|
|
|
return KYBER_READ;
|
kyber: implement improved heuristics
Kyber's current heuristics have a few flaws:
- It's based on the mean latency, but p99 latency tends to be more
meaningful to anyone who cares about latency. The mean can also be
skewed by rare outliers that the scheduler can't do anything about.
- The statistics calculations are purely time-based with a short window.
This works for steady, high load, but is more sensitive to outliers
with bursty workloads.
- It only considers the latency once an I/O has been submitted to the
device, but the user cares about the time spent in the kernel, as
well.
These are shortcomings of the generic blk-stat code which doesn't quite
fit the ideal use case for Kyber. So, this replaces the statistics with
a histogram used to calculate percentiles of total latency and I/O
latency, which we then use to adjust depths in a slightly more
intelligent manner:
- Sync and async writes are now the same domain.
- Discards are a separate domain.
- Domain queue depths are scaled by the ratio of the p99 total latency
to the target latency (e.g., if the p99 latency is double the target
latency, we will double the queue depth; if the p99 latency is half of
the target latency, we can halve the queue depth).
- We use the I/O latency to determine whether we should scale queue
depths down: we will only scale down if any domain's I/O latency
exceeds the target latency, which is an indicator of congestion in the
device.
These new heuristics are just as scalable as the heuristics they
replace.
Signed-off-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2018-09-28 01:55:54 +03:00
|
|
|
case REQ_OP_WRITE:
|
|
|
|
return KYBER_WRITE;
|
|
|
|
case REQ_OP_DISCARD:
|
|
|
|
return KYBER_DISCARD;
|
|
|
|
default:
|
2017-04-14 11:00:02 +03:00
|
|
|
return KYBER_OTHER;
|
kyber: implement improved heuristics
Kyber's current heuristics have a few flaws:
- It's based on the mean latency, but p99 latency tends to be more
meaningful to anyone who cares about latency. The mean can also be
skewed by rare outliers that the scheduler can't do anything about.
- The statistics calculations are purely time-based with a short window.
This works for steady, high load, but is more sensitive to outliers
with bursty workloads.
- It only considers the latency once an I/O has been submitted to the
device, but the user cares about the time spent in the kernel, as
well.
These are shortcomings of the generic blk-stat code which doesn't quite
fit the ideal use case for Kyber. So, this replaces the statistics with
a histogram used to calculate percentiles of total latency and I/O
latency, which we then use to adjust depths in a slightly more
intelligent manner:
- Sync and async writes are now the same domain.
- Discards are a separate domain.
- Domain queue depths are scaled by the ratio of the p99 total latency
to the target latency (e.g., if the p99 latency is double the target
latency, we will double the queue depth; if the p99 latency is half of
the target latency, we can halve the queue depth).
- We use the I/O latency to determine whether we should scale queue
depths down: we will only scale down if any domain's I/O latency
exceeds the target latency, which is an indicator of congestion in the
device.
These new heuristics are just as scalable as the heuristics they
replace.
Signed-off-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2018-09-28 01:55:54 +03:00
|
|
|
}
|
2017-04-14 11:00:02 +03:00
|
|
|
}
|
|
|
|
|
kyber: implement improved heuristics
Kyber's current heuristics have a few flaws:
- It's based on the mean latency, but p99 latency tends to be more
meaningful to anyone who cares about latency. The mean can also be
skewed by rare outliers that the scheduler can't do anything about.
- The statistics calculations are purely time-based with a short window.
This works for steady, high load, but is more sensitive to outliers
with bursty workloads.
- It only considers the latency once an I/O has been submitted to the
device, but the user cares about the time spent in the kernel, as
well.
These are shortcomings of the generic blk-stat code which doesn't quite
fit the ideal use case for Kyber. So, this replaces the statistics with
a histogram used to calculate percentiles of total latency and I/O
latency, which we then use to adjust depths in a slightly more
intelligent manner:
- Sync and async writes are now the same domain.
- Discards are a separate domain.
- Domain queue depths are scaled by the ratio of the p99 total latency
to the target latency (e.g., if the p99 latency is double the target
latency, we will double the queue depth; if the p99 latency is half of
the target latency, we can halve the queue depth).
- We use the I/O latency to determine whether we should scale queue
depths down: we will only scale down if any domain's I/O latency
exceeds the target latency, which is an indicator of congestion in the
device.
These new heuristics are just as scalable as the heuristics they
replace.
Signed-off-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2018-09-28 01:55:54 +03:00
|
|
|
static void flush_latency_buckets(struct kyber_queue_data *kqd,
|
|
|
|
struct kyber_cpu_latency *cpu_latency,
|
|
|
|
unsigned int sched_domain, unsigned int type)
|
2017-04-14 11:00:02 +03:00
|
|
|
{
|
kyber: implement improved heuristics
Kyber's current heuristics have a few flaws:
- It's based on the mean latency, but p99 latency tends to be more
meaningful to anyone who cares about latency. The mean can also be
skewed by rare outliers that the scheduler can't do anything about.
- The statistics calculations are purely time-based with a short window.
This works for steady, high load, but is more sensitive to outliers
with bursty workloads.
- It only considers the latency once an I/O has been submitted to the
device, but the user cares about the time spent in the kernel, as
well.
These are shortcomings of the generic blk-stat code which doesn't quite
fit the ideal use case for Kyber. So, this replaces the statistics with
a histogram used to calculate percentiles of total latency and I/O
latency, which we then use to adjust depths in a slightly more
intelligent manner:
- Sync and async writes are now the same domain.
- Discards are a separate domain.
- Domain queue depths are scaled by the ratio of the p99 total latency
to the target latency (e.g., if the p99 latency is double the target
latency, we will double the queue depth; if the p99 latency is half of
the target latency, we can halve the queue depth).
- We use the I/O latency to determine whether we should scale queue
depths down: we will only scale down if any domain's I/O latency
exceeds the target latency, which is an indicator of congestion in the
device.
These new heuristics are just as scalable as the heuristics they
replace.
Signed-off-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2018-09-28 01:55:54 +03:00
|
|
|
unsigned int *buckets = kqd->latency_buckets[sched_domain][type];
|
|
|
|
atomic_t *cpu_buckets = cpu_latency->buckets[sched_domain][type];
|
|
|
|
unsigned int bucket;
|
2017-04-14 11:00:02 +03:00
|
|
|
|
kyber: implement improved heuristics
Kyber's current heuristics have a few flaws:
- It's based on the mean latency, but p99 latency tends to be more
meaningful to anyone who cares about latency. The mean can also be
skewed by rare outliers that the scheduler can't do anything about.
- The statistics calculations are purely time-based with a short window.
This works for steady, high load, but is more sensitive to outliers
with bursty workloads.
- It only considers the latency once an I/O has been submitted to the
device, but the user cares about the time spent in the kernel, as
well.
These are shortcomings of the generic blk-stat code which doesn't quite
fit the ideal use case for Kyber. So, this replaces the statistics with
a histogram used to calculate percentiles of total latency and I/O
latency, which we then use to adjust depths in a slightly more
intelligent manner:
- Sync and async writes are now the same domain.
- Discards are a separate domain.
- Domain queue depths are scaled by the ratio of the p99 total latency
to the target latency (e.g., if the p99 latency is double the target
latency, we will double the queue depth; if the p99 latency is half of
the target latency, we can halve the queue depth).
- We use the I/O latency to determine whether we should scale queue
depths down: we will only scale down if any domain's I/O latency
exceeds the target latency, which is an indicator of congestion in the
device.
These new heuristics are just as scalable as the heuristics they
replace.
Signed-off-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2018-09-28 01:55:54 +03:00
|
|
|
for (bucket = 0; bucket < KYBER_LATENCY_BUCKETS; bucket++)
|
|
|
|
buckets[bucket] += atomic_xchg(&cpu_buckets[bucket], 0);
|
2017-04-14 11:00:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
kyber: implement improved heuristics
Kyber's current heuristics have a few flaws:
- It's based on the mean latency, but p99 latency tends to be more
meaningful to anyone who cares about latency. The mean can also be
skewed by rare outliers that the scheduler can't do anything about.
- The statistics calculations are purely time-based with a short window.
This works for steady, high load, but is more sensitive to outliers
with bursty workloads.
- It only considers the latency once an I/O has been submitted to the
device, but the user cares about the time spent in the kernel, as
well.
These are shortcomings of the generic blk-stat code which doesn't quite
fit the ideal use case for Kyber. So, this replaces the statistics with
a histogram used to calculate percentiles of total latency and I/O
latency, which we then use to adjust depths in a slightly more
intelligent manner:
- Sync and async writes are now the same domain.
- Discards are a separate domain.
- Domain queue depths are scaled by the ratio of the p99 total latency
to the target latency (e.g., if the p99 latency is double the target
latency, we will double the queue depth; if the p99 latency is half of
the target latency, we can halve the queue depth).
- We use the I/O latency to determine whether we should scale queue
depths down: we will only scale down if any domain's I/O latency
exceeds the target latency, which is an indicator of congestion in the
device.
These new heuristics are just as scalable as the heuristics they
replace.
Signed-off-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2018-09-28 01:55:54 +03:00
|
|
|
* Calculate the histogram bucket with the given percentile rank, or -1 if there
|
|
|
|
* aren't enough samples yet.
|
2017-04-14 11:00:02 +03:00
|
|
|
*/
|
kyber: implement improved heuristics
Kyber's current heuristics have a few flaws:
- It's based on the mean latency, but p99 latency tends to be more
meaningful to anyone who cares about latency. The mean can also be
skewed by rare outliers that the scheduler can't do anything about.
- The statistics calculations are purely time-based with a short window.
This works for steady, high load, but is more sensitive to outliers
with bursty workloads.
- It only considers the latency once an I/O has been submitted to the
device, but the user cares about the time spent in the kernel, as
well.
These are shortcomings of the generic blk-stat code which doesn't quite
fit the ideal use case for Kyber. So, this replaces the statistics with
a histogram used to calculate percentiles of total latency and I/O
latency, which we then use to adjust depths in a slightly more
intelligent manner:
- Sync and async writes are now the same domain.
- Discards are a separate domain.
- Domain queue depths are scaled by the ratio of the p99 total latency
to the target latency (e.g., if the p99 latency is double the target
latency, we will double the queue depth; if the p99 latency is half of
the target latency, we can halve the queue depth).
- We use the I/O latency to determine whether we should scale queue
depths down: we will only scale down if any domain's I/O latency
exceeds the target latency, which is an indicator of congestion in the
device.
These new heuristics are just as scalable as the heuristics they
replace.
Signed-off-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2018-09-28 01:55:54 +03:00
|
|
|
static int calculate_percentile(struct kyber_queue_data *kqd,
|
|
|
|
unsigned int sched_domain, unsigned int type,
|
|
|
|
unsigned int percentile)
|
2017-04-14 11:00:02 +03:00
|
|
|
{
|
kyber: implement improved heuristics
Kyber's current heuristics have a few flaws:
- It's based on the mean latency, but p99 latency tends to be more
meaningful to anyone who cares about latency. The mean can also be
skewed by rare outliers that the scheduler can't do anything about.
- The statistics calculations are purely time-based with a short window.
This works for steady, high load, but is more sensitive to outliers
with bursty workloads.
- It only considers the latency once an I/O has been submitted to the
device, but the user cares about the time spent in the kernel, as
well.
These are shortcomings of the generic blk-stat code which doesn't quite
fit the ideal use case for Kyber. So, this replaces the statistics with
a histogram used to calculate percentiles of total latency and I/O
latency, which we then use to adjust depths in a slightly more
intelligent manner:
- Sync and async writes are now the same domain.
- Discards are a separate domain.
- Domain queue depths are scaled by the ratio of the p99 total latency
to the target latency (e.g., if the p99 latency is double the target
latency, we will double the queue depth; if the p99 latency is half of
the target latency, we can halve the queue depth).
- We use the I/O latency to determine whether we should scale queue
depths down: we will only scale down if any domain's I/O latency
exceeds the target latency, which is an indicator of congestion in the
device.
These new heuristics are just as scalable as the heuristics they
replace.
Signed-off-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2018-09-28 01:55:54 +03:00
|
|
|
unsigned int *buckets = kqd->latency_buckets[sched_domain][type];
|
|
|
|
unsigned int bucket, samples = 0, percentile_samples;
|
|
|
|
|
|
|
|
for (bucket = 0; bucket < KYBER_LATENCY_BUCKETS; bucket++)
|
|
|
|
samples += buckets[bucket];
|
|
|
|
|
|
|
|
if (!samples)
|
|
|
|
return -1;
|
2017-04-14 11:00:02 +03:00
|
|
|
|
|
|
|
/*
|
kyber: implement improved heuristics
Kyber's current heuristics have a few flaws:
- It's based on the mean latency, but p99 latency tends to be more
meaningful to anyone who cares about latency. The mean can also be
skewed by rare outliers that the scheduler can't do anything about.
- The statistics calculations are purely time-based with a short window.
This works for steady, high load, but is more sensitive to outliers
with bursty workloads.
- It only considers the latency once an I/O has been submitted to the
device, but the user cares about the time spent in the kernel, as
well.
These are shortcomings of the generic blk-stat code which doesn't quite
fit the ideal use case for Kyber. So, this replaces the statistics with
a histogram used to calculate percentiles of total latency and I/O
latency, which we then use to adjust depths in a slightly more
intelligent manner:
- Sync and async writes are now the same domain.
- Discards are a separate domain.
- Domain queue depths are scaled by the ratio of the p99 total latency
to the target latency (e.g., if the p99 latency is double the target
latency, we will double the queue depth; if the p99 latency is half of
the target latency, we can halve the queue depth).
- We use the I/O latency to determine whether we should scale queue
depths down: we will only scale down if any domain's I/O latency
exceeds the target latency, which is an indicator of congestion in the
device.
These new heuristics are just as scalable as the heuristics they
replace.
Signed-off-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2018-09-28 01:55:54 +03:00
|
|
|
* We do the calculation once we have 500 samples or one second passes
|
|
|
|
* since the first sample was recorded, whichever comes first.
|
2017-04-14 11:00:02 +03:00
|
|
|
*/
|
kyber: implement improved heuristics
Kyber's current heuristics have a few flaws:
- It's based on the mean latency, but p99 latency tends to be more
meaningful to anyone who cares about latency. The mean can also be
skewed by rare outliers that the scheduler can't do anything about.
- The statistics calculations are purely time-based with a short window.
This works for steady, high load, but is more sensitive to outliers
with bursty workloads.
- It only considers the latency once an I/O has been submitted to the
device, but the user cares about the time spent in the kernel, as
well.
These are shortcomings of the generic blk-stat code which doesn't quite
fit the ideal use case for Kyber. So, this replaces the statistics with
a histogram used to calculate percentiles of total latency and I/O
latency, which we then use to adjust depths in a slightly more
intelligent manner:
- Sync and async writes are now the same domain.
- Discards are a separate domain.
- Domain queue depths are scaled by the ratio of the p99 total latency
to the target latency (e.g., if the p99 latency is double the target
latency, we will double the queue depth; if the p99 latency is half of
the target latency, we can halve the queue depth).
- We use the I/O latency to determine whether we should scale queue
depths down: we will only scale down if any domain's I/O latency
exceeds the target latency, which is an indicator of congestion in the
device.
These new heuristics are just as scalable as the heuristics they
replace.
Signed-off-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2018-09-28 01:55:54 +03:00
|
|
|
if (!kqd->latency_timeout[sched_domain])
|
|
|
|
kqd->latency_timeout[sched_domain] = max(jiffies + HZ, 1UL);
|
|
|
|
if (samples < 500 &&
|
|
|
|
time_is_after_jiffies(kqd->latency_timeout[sched_domain])) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
kqd->latency_timeout[sched_domain] = 0;
|
2017-04-14 11:00:02 +03:00
|
|
|
|
kyber: implement improved heuristics
Kyber's current heuristics have a few flaws:
- It's based on the mean latency, but p99 latency tends to be more
meaningful to anyone who cares about latency. The mean can also be
skewed by rare outliers that the scheduler can't do anything about.
- The statistics calculations are purely time-based with a short window.
This works for steady, high load, but is more sensitive to outliers
with bursty workloads.
- It only considers the latency once an I/O has been submitted to the
device, but the user cares about the time spent in the kernel, as
well.
These are shortcomings of the generic blk-stat code which doesn't quite
fit the ideal use case for Kyber. So, this replaces the statistics with
a histogram used to calculate percentiles of total latency and I/O
latency, which we then use to adjust depths in a slightly more
intelligent manner:
- Sync and async writes are now the same domain.
- Discards are a separate domain.
- Domain queue depths are scaled by the ratio of the p99 total latency
to the target latency (e.g., if the p99 latency is double the target
latency, we will double the queue depth; if the p99 latency is half of
the target latency, we can halve the queue depth).
- We use the I/O latency to determine whether we should scale queue
depths down: we will only scale down if any domain's I/O latency
exceeds the target latency, which is an indicator of congestion in the
device.
These new heuristics are just as scalable as the heuristics they
replace.
Signed-off-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2018-09-28 01:55:54 +03:00
|
|
|
percentile_samples = DIV_ROUND_UP(samples * percentile, 100);
|
|
|
|
for (bucket = 0; bucket < KYBER_LATENCY_BUCKETS - 1; bucket++) {
|
|
|
|
if (buckets[bucket] >= percentile_samples)
|
2017-04-14 11:00:02 +03:00
|
|
|
break;
|
kyber: implement improved heuristics
Kyber's current heuristics have a few flaws:
- It's based on the mean latency, but p99 latency tends to be more
meaningful to anyone who cares about latency. The mean can also be
skewed by rare outliers that the scheduler can't do anything about.
- The statistics calculations are purely time-based with a short window.
This works for steady, high load, but is more sensitive to outliers
with bursty workloads.
- It only considers the latency once an I/O has been submitted to the
device, but the user cares about the time spent in the kernel, as
well.
These are shortcomings of the generic blk-stat code which doesn't quite
fit the ideal use case for Kyber. So, this replaces the statistics with
a histogram used to calculate percentiles of total latency and I/O
latency, which we then use to adjust depths in a slightly more
intelligent manner:
- Sync and async writes are now the same domain.
- Discards are a separate domain.
- Domain queue depths are scaled by the ratio of the p99 total latency
to the target latency (e.g., if the p99 latency is double the target
latency, we will double the queue depth; if the p99 latency is half of
the target latency, we can halve the queue depth).
- We use the I/O latency to determine whether we should scale queue
depths down: we will only scale down if any domain's I/O latency
exceeds the target latency, which is an indicator of congestion in the
device.
These new heuristics are just as scalable as the heuristics they
replace.
Signed-off-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2018-09-28 01:55:54 +03:00
|
|
|
percentile_samples -= buckets[bucket];
|
2017-04-14 11:00:02 +03:00
|
|
|
}
|
kyber: implement improved heuristics
Kyber's current heuristics have a few flaws:
- It's based on the mean latency, but p99 latency tends to be more
meaningful to anyone who cares about latency. The mean can also be
skewed by rare outliers that the scheduler can't do anything about.
- The statistics calculations are purely time-based with a short window.
This works for steady, high load, but is more sensitive to outliers
with bursty workloads.
- It only considers the latency once an I/O has been submitted to the
device, but the user cares about the time spent in the kernel, as
well.
These are shortcomings of the generic blk-stat code which doesn't quite
fit the ideal use case for Kyber. So, this replaces the statistics with
a histogram used to calculate percentiles of total latency and I/O
latency, which we then use to adjust depths in a slightly more
intelligent manner:
- Sync and async writes are now the same domain.
- Discards are a separate domain.
- Domain queue depths are scaled by the ratio of the p99 total latency
to the target latency (e.g., if the p99 latency is double the target
latency, we will double the queue depth; if the p99 latency is half of
the target latency, we can halve the queue depth).
- We use the I/O latency to determine whether we should scale queue
depths down: we will only scale down if any domain's I/O latency
exceeds the target latency, which is an indicator of congestion in the
device.
These new heuristics are just as scalable as the heuristics they
replace.
Signed-off-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2018-09-28 01:55:54 +03:00
|
|
|
memset(buckets, 0, sizeof(kqd->latency_buckets[sched_domain][type]));
|
2017-04-14 11:00:02 +03:00
|
|
|
|
2021-10-12 12:33:01 +03:00
|
|
|
trace_kyber_latency(kqd->dev, kyber_domain_names[sched_domain],
|
2018-09-28 01:55:55 +03:00
|
|
|
kyber_latency_type_names[type], percentile,
|
|
|
|
bucket + 1, 1 << KYBER_LATENCY_SHIFT, samples);
|
|
|
|
|
kyber: implement improved heuristics
Kyber's current heuristics have a few flaws:
- It's based on the mean latency, but p99 latency tends to be more
meaningful to anyone who cares about latency. The mean can also be
skewed by rare outliers that the scheduler can't do anything about.
- The statistics calculations are purely time-based with a short window.
This works for steady, high load, but is more sensitive to outliers
with bursty workloads.
- It only considers the latency once an I/O has been submitted to the
device, but the user cares about the time spent in the kernel, as
well.
These are shortcomings of the generic blk-stat code which doesn't quite
fit the ideal use case for Kyber. So, this replaces the statistics with
a histogram used to calculate percentiles of total latency and I/O
latency, which we then use to adjust depths in a slightly more
intelligent manner:
- Sync and async writes are now the same domain.
- Discards are a separate domain.
- Domain queue depths are scaled by the ratio of the p99 total latency
to the target latency (e.g., if the p99 latency is double the target
latency, we will double the queue depth; if the p99 latency is half of
the target latency, we can halve the queue depth).
- We use the I/O latency to determine whether we should scale queue
depths down: we will only scale down if any domain's I/O latency
exceeds the target latency, which is an indicator of congestion in the
device.
These new heuristics are just as scalable as the heuristics they
replace.
Signed-off-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2018-09-28 01:55:54 +03:00
|
|
|
return bucket;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void kyber_resize_domain(struct kyber_queue_data *kqd,
|
|
|
|
unsigned int sched_domain, unsigned int depth)
|
|
|
|
{
|
2017-04-14 11:00:02 +03:00
|
|
|
depth = clamp(depth, 1U, kyber_depth[sched_domain]);
|
2018-09-28 01:55:55 +03:00
|
|
|
if (depth != kqd->domain_tokens[sched_domain].sb.depth) {
|
2017-04-14 11:00:02 +03:00
|
|
|
sbitmap_queue_resize(&kqd->domain_tokens[sched_domain], depth);
|
2021-10-12 12:33:01 +03:00
|
|
|
trace_kyber_adjust(kqd->dev, kyber_domain_names[sched_domain],
|
2018-09-28 01:55:55 +03:00
|
|
|
depth);
|
|
|
|
}
|
2017-04-14 11:00:02 +03:00
|
|
|
}
|
|
|
|
|
kyber: implement improved heuristics
Kyber's current heuristics have a few flaws:
- It's based on the mean latency, but p99 latency tends to be more
meaningful to anyone who cares about latency. The mean can also be
skewed by rare outliers that the scheduler can't do anything about.
- The statistics calculations are purely time-based with a short window.
This works for steady, high load, but is more sensitive to outliers
with bursty workloads.
- It only considers the latency once an I/O has been submitted to the
device, but the user cares about the time spent in the kernel, as
well.
These are shortcomings of the generic blk-stat code which doesn't quite
fit the ideal use case for Kyber. So, this replaces the statistics with
a histogram used to calculate percentiles of total latency and I/O
latency, which we then use to adjust depths in a slightly more
intelligent manner:
- Sync and async writes are now the same domain.
- Discards are a separate domain.
- Domain queue depths are scaled by the ratio of the p99 total latency
to the target latency (e.g., if the p99 latency is double the target
latency, we will double the queue depth; if the p99 latency is half of
the target latency, we can halve the queue depth).
- We use the I/O latency to determine whether we should scale queue
depths down: we will only scale down if any domain's I/O latency
exceeds the target latency, which is an indicator of congestion in the
device.
These new heuristics are just as scalable as the heuristics they
replace.
Signed-off-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2018-09-28 01:55:54 +03:00
|
|
|
static void kyber_timer_fn(struct timer_list *t)
|
|
|
|
{
|
|
|
|
struct kyber_queue_data *kqd = from_timer(kqd, t, timer);
|
|
|
|
unsigned int sched_domain;
|
|
|
|
int cpu;
|
|
|
|
bool bad = false;
|
|
|
|
|
|
|
|
/* Sum all of the per-cpu latency histograms. */
|
|
|
|
for_each_online_cpu(cpu) {
|
|
|
|
struct kyber_cpu_latency *cpu_latency;
|
|
|
|
|
|
|
|
cpu_latency = per_cpu_ptr(kqd->cpu_latency, cpu);
|
|
|
|
for (sched_domain = 0; sched_domain < KYBER_OTHER; sched_domain++) {
|
|
|
|
flush_latency_buckets(kqd, cpu_latency, sched_domain,
|
|
|
|
KYBER_TOTAL_LATENCY);
|
|
|
|
flush_latency_buckets(kqd, cpu_latency, sched_domain,
|
|
|
|
KYBER_IO_LATENCY);
|
2017-04-14 11:00:02 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
kyber: implement improved heuristics
Kyber's current heuristics have a few flaws:
- It's based on the mean latency, but p99 latency tends to be more
meaningful to anyone who cares about latency. The mean can also be
skewed by rare outliers that the scheduler can't do anything about.
- The statistics calculations are purely time-based with a short window.
This works for steady, high load, but is more sensitive to outliers
with bursty workloads.
- It only considers the latency once an I/O has been submitted to the
device, but the user cares about the time spent in the kernel, as
well.
These are shortcomings of the generic blk-stat code which doesn't quite
fit the ideal use case for Kyber. So, this replaces the statistics with
a histogram used to calculate percentiles of total latency and I/O
latency, which we then use to adjust depths in a slightly more
intelligent manner:
- Sync and async writes are now the same domain.
- Discards are a separate domain.
- Domain queue depths are scaled by the ratio of the p99 total latency
to the target latency (e.g., if the p99 latency is double the target
latency, we will double the queue depth; if the p99 latency is half of
the target latency, we can halve the queue depth).
- We use the I/O latency to determine whether we should scale queue
depths down: we will only scale down if any domain's I/O latency
exceeds the target latency, which is an indicator of congestion in the
device.
These new heuristics are just as scalable as the heuristics they
replace.
Signed-off-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2018-09-28 01:55:54 +03:00
|
|
|
/*
|
|
|
|
* Check if any domains have a high I/O latency, which might indicate
|
|
|
|
* congestion in the device. Note that we use the p90; we don't want to
|
|
|
|
* be too sensitive to outliers here.
|
|
|
|
*/
|
|
|
|
for (sched_domain = 0; sched_domain < KYBER_OTHER; sched_domain++) {
|
|
|
|
int p90;
|
2017-04-14 11:00:02 +03:00
|
|
|
|
kyber: implement improved heuristics
Kyber's current heuristics have a few flaws:
- It's based on the mean latency, but p99 latency tends to be more
meaningful to anyone who cares about latency. The mean can also be
skewed by rare outliers that the scheduler can't do anything about.
- The statistics calculations are purely time-based with a short window.
This works for steady, high load, but is more sensitive to outliers
with bursty workloads.
- It only considers the latency once an I/O has been submitted to the
device, but the user cares about the time spent in the kernel, as
well.
These are shortcomings of the generic blk-stat code which doesn't quite
fit the ideal use case for Kyber. So, this replaces the statistics with
a histogram used to calculate percentiles of total latency and I/O
latency, which we then use to adjust depths in a slightly more
intelligent manner:
- Sync and async writes are now the same domain.
- Discards are a separate domain.
- Domain queue depths are scaled by the ratio of the p99 total latency
to the target latency (e.g., if the p99 latency is double the target
latency, we will double the queue depth; if the p99 latency is half of
the target latency, we can halve the queue depth).
- We use the I/O latency to determine whether we should scale queue
depths down: we will only scale down if any domain's I/O latency
exceeds the target latency, which is an indicator of congestion in the
device.
These new heuristics are just as scalable as the heuristics they
replace.
Signed-off-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2018-09-28 01:55:54 +03:00
|
|
|
p90 = calculate_percentile(kqd, sched_domain, KYBER_IO_LATENCY,
|
|
|
|
90);
|
|
|
|
if (p90 >= KYBER_GOOD_BUCKETS)
|
|
|
|
bad = true;
|
|
|
|
}
|
2017-04-14 11:00:02 +03:00
|
|
|
|
|
|
|
/*
|
kyber: implement improved heuristics
Kyber's current heuristics have a few flaws:
- It's based on the mean latency, but p99 latency tends to be more
meaningful to anyone who cares about latency. The mean can also be
skewed by rare outliers that the scheduler can't do anything about.
- The statistics calculations are purely time-based with a short window.
This works for steady, high load, but is more sensitive to outliers
with bursty workloads.
- It only considers the latency once an I/O has been submitted to the
device, but the user cares about the time spent in the kernel, as
well.
These are shortcomings of the generic blk-stat code which doesn't quite
fit the ideal use case for Kyber. So, this replaces the statistics with
a histogram used to calculate percentiles of total latency and I/O
latency, which we then use to adjust depths in a slightly more
intelligent manner:
- Sync and async writes are now the same domain.
- Discards are a separate domain.
- Domain queue depths are scaled by the ratio of the p99 total latency
to the target latency (e.g., if the p99 latency is double the target
latency, we will double the queue depth; if the p99 latency is half of
the target latency, we can halve the queue depth).
- We use the I/O latency to determine whether we should scale queue
depths down: we will only scale down if any domain's I/O latency
exceeds the target latency, which is an indicator of congestion in the
device.
These new heuristics are just as scalable as the heuristics they
replace.
Signed-off-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2018-09-28 01:55:54 +03:00
|
|
|
* Adjust the scheduling domain depths. If we determined that there was
|
|
|
|
* congestion, we throttle all domains with good latencies. Either way,
|
|
|
|
* we ease up on throttling domains with bad latencies.
|
2017-04-14 11:00:02 +03:00
|
|
|
*/
|
kyber: implement improved heuristics
Kyber's current heuristics have a few flaws:
- It's based on the mean latency, but p99 latency tends to be more
meaningful to anyone who cares about latency. The mean can also be
skewed by rare outliers that the scheduler can't do anything about.
- The statistics calculations are purely time-based with a short window.
This works for steady, high load, but is more sensitive to outliers
with bursty workloads.
- It only considers the latency once an I/O has been submitted to the
device, but the user cares about the time spent in the kernel, as
well.
These are shortcomings of the generic blk-stat code which doesn't quite
fit the ideal use case for Kyber. So, this replaces the statistics with
a histogram used to calculate percentiles of total latency and I/O
latency, which we then use to adjust depths in a slightly more
intelligent manner:
- Sync and async writes are now the same domain.
- Discards are a separate domain.
- Domain queue depths are scaled by the ratio of the p99 total latency
to the target latency (e.g., if the p99 latency is double the target
latency, we will double the queue depth; if the p99 latency is half of
the target latency, we can halve the queue depth).
- We use the I/O latency to determine whether we should scale queue
depths down: we will only scale down if any domain's I/O latency
exceeds the target latency, which is an indicator of congestion in the
device.
These new heuristics are just as scalable as the heuristics they
replace.
Signed-off-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2018-09-28 01:55:54 +03:00
|
|
|
for (sched_domain = 0; sched_domain < KYBER_OTHER; sched_domain++) {
|
|
|
|
unsigned int orig_depth, depth;
|
|
|
|
int p99;
|
|
|
|
|
|
|
|
p99 = calculate_percentile(kqd, sched_domain,
|
|
|
|
KYBER_TOTAL_LATENCY, 99);
|
|
|
|
/*
|
|
|
|
* This is kind of subtle: different domains will not
|
|
|
|
* necessarily have enough samples to calculate the latency
|
|
|
|
* percentiles during the same window, so we have to remember
|
|
|
|
* the p99 for the next time we observe congestion; once we do,
|
|
|
|
* we don't want to throttle again until we get more data, so we
|
|
|
|
* reset it to -1.
|
|
|
|
*/
|
|
|
|
if (bad) {
|
|
|
|
if (p99 < 0)
|
|
|
|
p99 = kqd->domain_p99[sched_domain];
|
|
|
|
kqd->domain_p99[sched_domain] = -1;
|
|
|
|
} else if (p99 >= 0) {
|
|
|
|
kqd->domain_p99[sched_domain] = p99;
|
|
|
|
}
|
|
|
|
if (p99 < 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If this domain has bad latency, throttle less. Otherwise,
|
|
|
|
* throttle more iff we determined that there is congestion.
|
|
|
|
*
|
|
|
|
* The new depth is scaled linearly with the p99 latency vs the
|
|
|
|
* latency target. E.g., if the p99 is 3/4 of the target, then
|
|
|
|
* we throttle down to 3/4 of the current depth, and if the p99
|
|
|
|
* is 2x the target, then we double the depth.
|
|
|
|
*/
|
|
|
|
if (bad || p99 >= KYBER_GOOD_BUCKETS) {
|
|
|
|
orig_depth = kqd->domain_tokens[sched_domain].sb.depth;
|
|
|
|
depth = (orig_depth * (p99 + 1)) >> KYBER_LATENCY_SHIFT;
|
|
|
|
kyber_resize_domain(kqd, sched_domain, depth);
|
|
|
|
}
|
|
|
|
}
|
2017-04-14 11:00:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct kyber_queue_data *kyber_queue_data_alloc(struct request_queue *q)
|
|
|
|
{
|
|
|
|
struct kyber_queue_data *kqd;
|
|
|
|
int ret = -ENOMEM;
|
|
|
|
int i;
|
|
|
|
|
kyber: implement improved heuristics
Kyber's current heuristics have a few flaws:
- It's based on the mean latency, but p99 latency tends to be more
meaningful to anyone who cares about latency. The mean can also be
skewed by rare outliers that the scheduler can't do anything about.
- The statistics calculations are purely time-based with a short window.
This works for steady, high load, but is more sensitive to outliers
with bursty workloads.
- It only considers the latency once an I/O has been submitted to the
device, but the user cares about the time spent in the kernel, as
well.
These are shortcomings of the generic blk-stat code which doesn't quite
fit the ideal use case for Kyber. So, this replaces the statistics with
a histogram used to calculate percentiles of total latency and I/O
latency, which we then use to adjust depths in a slightly more
intelligent manner:
- Sync and async writes are now the same domain.
- Discards are a separate domain.
- Domain queue depths are scaled by the ratio of the p99 total latency
to the target latency (e.g., if the p99 latency is double the target
latency, we will double the queue depth; if the p99 latency is half of
the target latency, we can halve the queue depth).
- We use the I/O latency to determine whether we should scale queue
depths down: we will only scale down if any domain's I/O latency
exceeds the target latency, which is an indicator of congestion in the
device.
These new heuristics are just as scalable as the heuristics they
replace.
Signed-off-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2018-09-28 01:55:54 +03:00
|
|
|
kqd = kzalloc_node(sizeof(*kqd), GFP_KERNEL, q->node);
|
2017-04-14 11:00:02 +03:00
|
|
|
if (!kqd)
|
|
|
|
goto err;
|
|
|
|
|
2018-09-28 01:55:55 +03:00
|
|
|
kqd->q = q;
|
2021-10-12 12:33:01 +03:00
|
|
|
kqd->dev = disk_devt(q->disk);
|
2018-09-28 01:55:55 +03:00
|
|
|
|
kyber: implement improved heuristics
Kyber's current heuristics have a few flaws:
- It's based on the mean latency, but p99 latency tends to be more
meaningful to anyone who cares about latency. The mean can also be
skewed by rare outliers that the scheduler can't do anything about.
- The statistics calculations are purely time-based with a short window.
This works for steady, high load, but is more sensitive to outliers
with bursty workloads.
- It only considers the latency once an I/O has been submitted to the
device, but the user cares about the time spent in the kernel, as
well.
These are shortcomings of the generic blk-stat code which doesn't quite
fit the ideal use case for Kyber. So, this replaces the statistics with
a histogram used to calculate percentiles of total latency and I/O
latency, which we then use to adjust depths in a slightly more
intelligent manner:
- Sync and async writes are now the same domain.
- Discards are a separate domain.
- Domain queue depths are scaled by the ratio of the p99 total latency
to the target latency (e.g., if the p99 latency is double the target
latency, we will double the queue depth; if the p99 latency is half of
the target latency, we can halve the queue depth).
- We use the I/O latency to determine whether we should scale queue
depths down: we will only scale down if any domain's I/O latency
exceeds the target latency, which is an indicator of congestion in the
device.
These new heuristics are just as scalable as the heuristics they
replace.
Signed-off-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2018-09-28 01:55:54 +03:00
|
|
|
kqd->cpu_latency = alloc_percpu_gfp(struct kyber_cpu_latency,
|
|
|
|
GFP_KERNEL | __GFP_ZERO);
|
|
|
|
if (!kqd->cpu_latency)
|
2017-04-14 11:00:02 +03:00
|
|
|
goto err_kqd;
|
|
|
|
|
kyber: implement improved heuristics
Kyber's current heuristics have a few flaws:
- It's based on the mean latency, but p99 latency tends to be more
meaningful to anyone who cares about latency. The mean can also be
skewed by rare outliers that the scheduler can't do anything about.
- The statistics calculations are purely time-based with a short window.
This works for steady, high load, but is more sensitive to outliers
with bursty workloads.
- It only considers the latency once an I/O has been submitted to the
device, but the user cares about the time spent in the kernel, as
well.
These are shortcomings of the generic blk-stat code which doesn't quite
fit the ideal use case for Kyber. So, this replaces the statistics with
a histogram used to calculate percentiles of total latency and I/O
latency, which we then use to adjust depths in a slightly more
intelligent manner:
- Sync and async writes are now the same domain.
- Discards are a separate domain.
- Domain queue depths are scaled by the ratio of the p99 total latency
to the target latency (e.g., if the p99 latency is double the target
latency, we will double the queue depth; if the p99 latency is half of
the target latency, we can halve the queue depth).
- We use the I/O latency to determine whether we should scale queue
depths down: we will only scale down if any domain's I/O latency
exceeds the target latency, which is an indicator of congestion in the
device.
These new heuristics are just as scalable as the heuristics they
replace.
Signed-off-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2018-09-28 01:55:54 +03:00
|
|
|
timer_setup(&kqd->timer, kyber_timer_fn, 0);
|
|
|
|
|
2017-04-14 11:00:02 +03:00
|
|
|
for (i = 0; i < KYBER_NUM_DOMAINS; i++) {
|
|
|
|
WARN_ON(!kyber_depth[i]);
|
|
|
|
WARN_ON(!kyber_batch_size[i]);
|
|
|
|
ret = sbitmap_queue_init_node(&kqd->domain_tokens[i],
|
kyber: don't make domain token sbitmap larger than necessary
The domain token sbitmaps are currently initialized to the device queue
depth or 256, whichever is larger, and immediately resized to the
maximum depth for that domain (256, 128, or 64 for read, write, and
other, respectively). The sbitmap is never resized larger than that, so
it's unnecessary to allocate a bitmap larger than the maximum depth.
Let's just allocate it to the maximum depth to begin with. This will use
marginally less memory, and more importantly, give us a more appropriate
number of bits per sbitmap word.
Signed-off-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2018-09-28 01:55:53 +03:00
|
|
|
kyber_depth[i], -1, false,
|
|
|
|
GFP_KERNEL, q->node);
|
2017-04-14 11:00:02 +03:00
|
|
|
if (ret) {
|
|
|
|
while (--i >= 0)
|
|
|
|
sbitmap_queue_free(&kqd->domain_tokens[i]);
|
kyber: implement improved heuristics
Kyber's current heuristics have a few flaws:
- It's based on the mean latency, but p99 latency tends to be more
meaningful to anyone who cares about latency. The mean can also be
skewed by rare outliers that the scheduler can't do anything about.
- The statistics calculations are purely time-based with a short window.
This works for steady, high load, but is more sensitive to outliers
with bursty workloads.
- It only considers the latency once an I/O has been submitted to the
device, but the user cares about the time spent in the kernel, as
well.
These are shortcomings of the generic blk-stat code which doesn't quite
fit the ideal use case for Kyber. So, this replaces the statistics with
a histogram used to calculate percentiles of total latency and I/O
latency, which we then use to adjust depths in a slightly more
intelligent manner:
- Sync and async writes are now the same domain.
- Discards are a separate domain.
- Domain queue depths are scaled by the ratio of the p99 total latency
to the target latency (e.g., if the p99 latency is double the target
latency, we will double the queue depth; if the p99 latency is half of
the target latency, we can halve the queue depth).
- We use the I/O latency to determine whether we should scale queue
depths down: we will only scale down if any domain's I/O latency
exceeds the target latency, which is an indicator of congestion in the
device.
These new heuristics are just as scalable as the heuristics they
replace.
Signed-off-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2018-09-28 01:55:54 +03:00
|
|
|
goto err_buckets;
|
2017-04-14 11:00:02 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
kyber: implement improved heuristics
Kyber's current heuristics have a few flaws:
- It's based on the mean latency, but p99 latency tends to be more
meaningful to anyone who cares about latency. The mean can also be
skewed by rare outliers that the scheduler can't do anything about.
- The statistics calculations are purely time-based with a short window.
This works for steady, high load, but is more sensitive to outliers
with bursty workloads.
- It only considers the latency once an I/O has been submitted to the
device, but the user cares about the time spent in the kernel, as
well.
These are shortcomings of the generic blk-stat code which doesn't quite
fit the ideal use case for Kyber. So, this replaces the statistics with
a histogram used to calculate percentiles of total latency and I/O
latency, which we then use to adjust depths in a slightly more
intelligent manner:
- Sync and async writes are now the same domain.
- Discards are a separate domain.
- Domain queue depths are scaled by the ratio of the p99 total latency
to the target latency (e.g., if the p99 latency is double the target
latency, we will double the queue depth; if the p99 latency is half of
the target latency, we can halve the queue depth).
- We use the I/O latency to determine whether we should scale queue
depths down: we will only scale down if any domain's I/O latency
exceeds the target latency, which is an indicator of congestion in the
device.
These new heuristics are just as scalable as the heuristics they
replace.
Signed-off-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2018-09-28 01:55:54 +03:00
|
|
|
for (i = 0; i < KYBER_OTHER; i++) {
|
|
|
|
kqd->domain_p99[i] = -1;
|
|
|
|
kqd->latency_targets[i] = kyber_latency_targets[i];
|
|
|
|
}
|
2017-04-14 11:00:02 +03:00
|
|
|
|
|
|
|
return kqd;
|
|
|
|
|
kyber: implement improved heuristics
Kyber's current heuristics have a few flaws:
- It's based on the mean latency, but p99 latency tends to be more
meaningful to anyone who cares about latency. The mean can also be
skewed by rare outliers that the scheduler can't do anything about.
- The statistics calculations are purely time-based with a short window.
This works for steady, high load, but is more sensitive to outliers
with bursty workloads.
- It only considers the latency once an I/O has been submitted to the
device, but the user cares about the time spent in the kernel, as
well.
These are shortcomings of the generic blk-stat code which doesn't quite
fit the ideal use case for Kyber. So, this replaces the statistics with
a histogram used to calculate percentiles of total latency and I/O
latency, which we then use to adjust depths in a slightly more
intelligent manner:
- Sync and async writes are now the same domain.
- Discards are a separate domain.
- Domain queue depths are scaled by the ratio of the p99 total latency
to the target latency (e.g., if the p99 latency is double the target
latency, we will double the queue depth; if the p99 latency is half of
the target latency, we can halve the queue depth).
- We use the I/O latency to determine whether we should scale queue
depths down: we will only scale down if any domain's I/O latency
exceeds the target latency, which is an indicator of congestion in the
device.
These new heuristics are just as scalable as the heuristics they
replace.
Signed-off-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2018-09-28 01:55:54 +03:00
|
|
|
err_buckets:
|
|
|
|
free_percpu(kqd->cpu_latency);
|
2017-04-14 11:00:02 +03:00
|
|
|
err_kqd:
|
|
|
|
kfree(kqd);
|
|
|
|
err:
|
|
|
|
return ERR_PTR(ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int kyber_init_sched(struct request_queue *q, struct elevator_type *e)
|
|
|
|
{
|
|
|
|
struct kyber_queue_data *kqd;
|
|
|
|
struct elevator_queue *eq;
|
|
|
|
|
|
|
|
eq = elevator_alloc(q, e);
|
|
|
|
if (!eq)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
kqd = kyber_queue_data_alloc(q);
|
|
|
|
if (IS_ERR(kqd)) {
|
|
|
|
kobject_put(&eq->kobj);
|
|
|
|
return PTR_ERR(kqd);
|
|
|
|
}
|
|
|
|
|
kyber: implement improved heuristics
Kyber's current heuristics have a few flaws:
- It's based on the mean latency, but p99 latency tends to be more
meaningful to anyone who cares about latency. The mean can also be
skewed by rare outliers that the scheduler can't do anything about.
- The statistics calculations are purely time-based with a short window.
This works for steady, high load, but is more sensitive to outliers
with bursty workloads.
- It only considers the latency once an I/O has been submitted to the
device, but the user cares about the time spent in the kernel, as
well.
These are shortcomings of the generic blk-stat code which doesn't quite
fit the ideal use case for Kyber. So, this replaces the statistics with
a histogram used to calculate percentiles of total latency and I/O
latency, which we then use to adjust depths in a slightly more
intelligent manner:
- Sync and async writes are now the same domain.
- Discards are a separate domain.
- Domain queue depths are scaled by the ratio of the p99 total latency
to the target latency (e.g., if the p99 latency is double the target
latency, we will double the queue depth; if the p99 latency is half of
the target latency, we can halve the queue depth).
- We use the I/O latency to determine whether we should scale queue
depths down: we will only scale down if any domain's I/O latency
exceeds the target latency, which is an indicator of congestion in the
device.
These new heuristics are just as scalable as the heuristics they
replace.
Signed-off-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2018-09-28 01:55:54 +03:00
|
|
|
blk_stat_enable_accounting(q);
|
|
|
|
|
2022-06-16 04:44:00 +03:00
|
|
|
blk_queue_flag_clear(QUEUE_FLAG_SQ_SCHED, q);
|
|
|
|
|
2017-04-14 11:00:02 +03:00
|
|
|
eq->elevator_data = kqd;
|
|
|
|
q->elevator = eq;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void kyber_exit_sched(struct elevator_queue *e)
|
|
|
|
{
|
|
|
|
struct kyber_queue_data *kqd = e->elevator_data;
|
|
|
|
int i;
|
|
|
|
|
kyber: implement improved heuristics
Kyber's current heuristics have a few flaws:
- It's based on the mean latency, but p99 latency tends to be more
meaningful to anyone who cares about latency. The mean can also be
skewed by rare outliers that the scheduler can't do anything about.
- The statistics calculations are purely time-based with a short window.
This works for steady, high load, but is more sensitive to outliers
with bursty workloads.
- It only considers the latency once an I/O has been submitted to the
device, but the user cares about the time spent in the kernel, as
well.
These are shortcomings of the generic blk-stat code which doesn't quite
fit the ideal use case for Kyber. So, this replaces the statistics with
a histogram used to calculate percentiles of total latency and I/O
latency, which we then use to adjust depths in a slightly more
intelligent manner:
- Sync and async writes are now the same domain.
- Discards are a separate domain.
- Domain queue depths are scaled by the ratio of the p99 total latency
to the target latency (e.g., if the p99 latency is double the target
latency, we will double the queue depth; if the p99 latency is half of
the target latency, we can halve the queue depth).
- We use the I/O latency to determine whether we should scale queue
depths down: we will only scale down if any domain's I/O latency
exceeds the target latency, which is an indicator of congestion in the
device.
These new heuristics are just as scalable as the heuristics they
replace.
Signed-off-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2018-09-28 01:55:54 +03:00
|
|
|
del_timer_sync(&kqd->timer);
|
2021-12-15 03:23:05 +03:00
|
|
|
blk_stat_disable_accounting(kqd->q);
|
2017-04-14 11:00:02 +03:00
|
|
|
|
|
|
|
for (i = 0; i < KYBER_NUM_DOMAINS; i++)
|
|
|
|
sbitmap_queue_free(&kqd->domain_tokens[i]);
|
kyber: implement improved heuristics
Kyber's current heuristics have a few flaws:
- It's based on the mean latency, but p99 latency tends to be more
meaningful to anyone who cares about latency. The mean can also be
skewed by rare outliers that the scheduler can't do anything about.
- The statistics calculations are purely time-based with a short window.
This works for steady, high load, but is more sensitive to outliers
with bursty workloads.
- It only considers the latency once an I/O has been submitted to the
device, but the user cares about the time spent in the kernel, as
well.
These are shortcomings of the generic blk-stat code which doesn't quite
fit the ideal use case for Kyber. So, this replaces the statistics with
a histogram used to calculate percentiles of total latency and I/O
latency, which we then use to adjust depths in a slightly more
intelligent manner:
- Sync and async writes are now the same domain.
- Discards are a separate domain.
- Domain queue depths are scaled by the ratio of the p99 total latency
to the target latency (e.g., if the p99 latency is double the target
latency, we will double the queue depth; if the p99 latency is half of
the target latency, we can halve the queue depth).
- We use the I/O latency to determine whether we should scale queue
depths down: we will only scale down if any domain's I/O latency
exceeds the target latency, which is an indicator of congestion in the
device.
These new heuristics are just as scalable as the heuristics they
replace.
Signed-off-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2018-09-28 01:55:54 +03:00
|
|
|
free_percpu(kqd->cpu_latency);
|
2017-04-14 11:00:02 +03:00
|
|
|
kfree(kqd);
|
|
|
|
}
|
|
|
|
|
block: kyber: make kyber more friendly with merging
Currently, kyber is very unfriendly with merging. kyber depends
on ctx rq_list to do merging, however, most of time, it will not
leave any requests in ctx rq_list. This is because even if tokens
of one domain is used up, kyber will try to dispatch requests
from other domain and flush the rq_list there.
To improve this, we setup kyber_ctx_queue (kcq) which is similar
with ctx, but it has rq_lists for different domain and build same
mapping between kcq and khd as the ctx & hctx. Then we could merge,
insert and dispatch for different domains separately. At the same
time, only flush the rq_list of kcq when get domain token successfully.
Then if one domain token is used up, the requests could be left in
the rq_list of that domain and maybe merged with following io.
Following is my test result on machine with 8 cores and NVMe card
INTEL SSDPEKKR128G7
fio size=256m ioengine=libaio iodepth=64 direct=1 numjobs=8
seq/random
+------+---------------------------------------------------------------+
|patch?| bw(MB/s) | iops | slat(usec) | clat(usec) | merge |
+----------------------------------------------------------------------+
| w/o | 606/612 | 151k/153k | 6.89/7.03 | 3349.21/3305.40 | 0/0 |
+----------------------------------------------------------------------+
| w/ | 1083/616 | 277k/154k | 4.93/6.95 | 1830.62/3279.95 | 223k/3k |
+----------------------------------------------------------------------+
When set numjobs to 16, the bw and iops could reach 1662MB/s and 425k
on my platform.
Signed-off-by: Jianchao Wang <jianchao.w.wang@oracle.com>
Tested-by: Holger Hoffstätte <holger@applied-asynchrony.com>
Reviewed-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2018-05-30 19:47:40 +03:00
|
|
|
static void kyber_ctx_queue_init(struct kyber_ctx_queue *kcq)
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
spin_lock_init(&kcq->lock);
|
|
|
|
for (i = 0; i < KYBER_NUM_DOMAINS; i++)
|
|
|
|
INIT_LIST_HEAD(&kcq->rq_list[i]);
|
|
|
|
}
|
|
|
|
|
2021-02-05 12:13:10 +03:00
|
|
|
static void kyber_depth_updated(struct blk_mq_hw_ctx *hctx)
|
2017-04-14 11:00:02 +03:00
|
|
|
{
|
2018-05-09 22:55:14 +03:00
|
|
|
struct kyber_queue_data *kqd = hctx->queue->elevator->elevator_data;
|
2021-02-05 12:13:10 +03:00
|
|
|
struct blk_mq_tags *tags = hctx->sched_tags;
|
2021-10-05 13:23:38 +03:00
|
|
|
unsigned int shift = tags->bitmap_tags.sb.shift;
|
2021-02-05 12:13:10 +03:00
|
|
|
|
|
|
|
kqd->async_depth = (1U << shift) * KYBER_ASYNC_PERCENT / 100U;
|
|
|
|
|
2021-10-05 13:23:38 +03:00
|
|
|
sbitmap_queue_min_shallow_depth(&tags->bitmap_tags, kqd->async_depth);
|
2021-02-05 12:13:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static int kyber_init_hctx(struct blk_mq_hw_ctx *hctx, unsigned int hctx_idx)
|
|
|
|
{
|
2017-04-14 11:00:02 +03:00
|
|
|
struct kyber_hctx_data *khd;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
khd = kmalloc_node(sizeof(*khd), GFP_KERNEL, hctx->numa_node);
|
|
|
|
if (!khd)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
block: kyber: make kyber more friendly with merging
Currently, kyber is very unfriendly with merging. kyber depends
on ctx rq_list to do merging, however, most of time, it will not
leave any requests in ctx rq_list. This is because even if tokens
of one domain is used up, kyber will try to dispatch requests
from other domain and flush the rq_list there.
To improve this, we setup kyber_ctx_queue (kcq) which is similar
with ctx, but it has rq_lists for different domain and build same
mapping between kcq and khd as the ctx & hctx. Then we could merge,
insert and dispatch for different domains separately. At the same
time, only flush the rq_list of kcq when get domain token successfully.
Then if one domain token is used up, the requests could be left in
the rq_list of that domain and maybe merged with following io.
Following is my test result on machine with 8 cores and NVMe card
INTEL SSDPEKKR128G7
fio size=256m ioengine=libaio iodepth=64 direct=1 numjobs=8
seq/random
+------+---------------------------------------------------------------+
|patch?| bw(MB/s) | iops | slat(usec) | clat(usec) | merge |
+----------------------------------------------------------------------+
| w/o | 606/612 | 151k/153k | 6.89/7.03 | 3349.21/3305.40 | 0/0 |
+----------------------------------------------------------------------+
| w/ | 1083/616 | 277k/154k | 4.93/6.95 | 1830.62/3279.95 | 223k/3k |
+----------------------------------------------------------------------+
When set numjobs to 16, the bw and iops could reach 1662MB/s and 425k
on my platform.
Signed-off-by: Jianchao Wang <jianchao.w.wang@oracle.com>
Tested-by: Holger Hoffstätte <holger@applied-asynchrony.com>
Reviewed-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2018-05-30 19:47:40 +03:00
|
|
|
khd->kcqs = kmalloc_array_node(hctx->nr_ctx,
|
|
|
|
sizeof(struct kyber_ctx_queue),
|
|
|
|
GFP_KERNEL, hctx->numa_node);
|
|
|
|
if (!khd->kcqs)
|
|
|
|
goto err_khd;
|
|
|
|
|
|
|
|
for (i = 0; i < hctx->nr_ctx; i++)
|
|
|
|
kyber_ctx_queue_init(&khd->kcqs[i]);
|
|
|
|
|
|
|
|
for (i = 0; i < KYBER_NUM_DOMAINS; i++) {
|
|
|
|
if (sbitmap_init_node(&khd->kcq_map[i], hctx->nr_ctx,
|
2021-01-22 05:33:06 +03:00
|
|
|
ilog2(8), GFP_KERNEL, hctx->numa_node,
|
2021-01-22 05:33:08 +03:00
|
|
|
false, false)) {
|
block: kyber: make kyber more friendly with merging
Currently, kyber is very unfriendly with merging. kyber depends
on ctx rq_list to do merging, however, most of time, it will not
leave any requests in ctx rq_list. This is because even if tokens
of one domain is used up, kyber will try to dispatch requests
from other domain and flush the rq_list there.
To improve this, we setup kyber_ctx_queue (kcq) which is similar
with ctx, but it has rq_lists for different domain and build same
mapping between kcq and khd as the ctx & hctx. Then we could merge,
insert and dispatch for different domains separately. At the same
time, only flush the rq_list of kcq when get domain token successfully.
Then if one domain token is used up, the requests could be left in
the rq_list of that domain and maybe merged with following io.
Following is my test result on machine with 8 cores and NVMe card
INTEL SSDPEKKR128G7
fio size=256m ioengine=libaio iodepth=64 direct=1 numjobs=8
seq/random
+------+---------------------------------------------------------------+
|patch?| bw(MB/s) | iops | slat(usec) | clat(usec) | merge |
+----------------------------------------------------------------------+
| w/o | 606/612 | 151k/153k | 6.89/7.03 | 3349.21/3305.40 | 0/0 |
+----------------------------------------------------------------------+
| w/ | 1083/616 | 277k/154k | 4.93/6.95 | 1830.62/3279.95 | 223k/3k |
+----------------------------------------------------------------------+
When set numjobs to 16, the bw and iops could reach 1662MB/s and 425k
on my platform.
Signed-off-by: Jianchao Wang <jianchao.w.wang@oracle.com>
Tested-by: Holger Hoffstätte <holger@applied-asynchrony.com>
Reviewed-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2018-05-30 19:47:40 +03:00
|
|
|
while (--i >= 0)
|
|
|
|
sbitmap_free(&khd->kcq_map[i]);
|
|
|
|
goto err_kcqs;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-14 11:00:02 +03:00
|
|
|
spin_lock_init(&khd->lock);
|
|
|
|
|
|
|
|
for (i = 0; i < KYBER_NUM_DOMAINS; i++) {
|
|
|
|
INIT_LIST_HEAD(&khd->rqs[i]);
|
2018-12-20 18:50:58 +03:00
|
|
|
khd->domain_wait[i].sbq = NULL;
|
|
|
|
init_waitqueue_func_entry(&khd->domain_wait[i].wait,
|
2017-12-06 09:57:43 +03:00
|
|
|
kyber_domain_wake);
|
2018-12-20 18:50:58 +03:00
|
|
|
khd->domain_wait[i].wait.private = hctx;
|
|
|
|
INIT_LIST_HEAD(&khd->domain_wait[i].wait.entry);
|
2017-04-14 11:00:02 +03:00
|
|
|
atomic_set(&khd->wait_index[i], 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
khd->cur_domain = 0;
|
|
|
|
khd->batching = 0;
|
|
|
|
|
|
|
|
hctx->sched_data = khd;
|
2021-02-05 12:13:10 +03:00
|
|
|
kyber_depth_updated(hctx);
|
2017-04-14 11:00:02 +03:00
|
|
|
|
|
|
|
return 0;
|
block: kyber: make kyber more friendly with merging
Currently, kyber is very unfriendly with merging. kyber depends
on ctx rq_list to do merging, however, most of time, it will not
leave any requests in ctx rq_list. This is because even if tokens
of one domain is used up, kyber will try to dispatch requests
from other domain and flush the rq_list there.
To improve this, we setup kyber_ctx_queue (kcq) which is similar
with ctx, but it has rq_lists for different domain and build same
mapping between kcq and khd as the ctx & hctx. Then we could merge,
insert and dispatch for different domains separately. At the same
time, only flush the rq_list of kcq when get domain token successfully.
Then if one domain token is used up, the requests could be left in
the rq_list of that domain and maybe merged with following io.
Following is my test result on machine with 8 cores and NVMe card
INTEL SSDPEKKR128G7
fio size=256m ioengine=libaio iodepth=64 direct=1 numjobs=8
seq/random
+------+---------------------------------------------------------------+
|patch?| bw(MB/s) | iops | slat(usec) | clat(usec) | merge |
+----------------------------------------------------------------------+
| w/o | 606/612 | 151k/153k | 6.89/7.03 | 3349.21/3305.40 | 0/0 |
+----------------------------------------------------------------------+
| w/ | 1083/616 | 277k/154k | 4.93/6.95 | 1830.62/3279.95 | 223k/3k |
+----------------------------------------------------------------------+
When set numjobs to 16, the bw and iops could reach 1662MB/s and 425k
on my platform.
Signed-off-by: Jianchao Wang <jianchao.w.wang@oracle.com>
Tested-by: Holger Hoffstätte <holger@applied-asynchrony.com>
Reviewed-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2018-05-30 19:47:40 +03:00
|
|
|
|
|
|
|
err_kcqs:
|
|
|
|
kfree(khd->kcqs);
|
|
|
|
err_khd:
|
|
|
|
kfree(khd);
|
|
|
|
return -ENOMEM;
|
2017-04-14 11:00:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void kyber_exit_hctx(struct blk_mq_hw_ctx *hctx, unsigned int hctx_idx)
|
|
|
|
{
|
block: kyber: make kyber more friendly with merging
Currently, kyber is very unfriendly with merging. kyber depends
on ctx rq_list to do merging, however, most of time, it will not
leave any requests in ctx rq_list. This is because even if tokens
of one domain is used up, kyber will try to dispatch requests
from other domain and flush the rq_list there.
To improve this, we setup kyber_ctx_queue (kcq) which is similar
with ctx, but it has rq_lists for different domain and build same
mapping between kcq and khd as the ctx & hctx. Then we could merge,
insert and dispatch for different domains separately. At the same
time, only flush the rq_list of kcq when get domain token successfully.
Then if one domain token is used up, the requests could be left in
the rq_list of that domain and maybe merged with following io.
Following is my test result on machine with 8 cores and NVMe card
INTEL SSDPEKKR128G7
fio size=256m ioengine=libaio iodepth=64 direct=1 numjobs=8
seq/random
+------+---------------------------------------------------------------+
|patch?| bw(MB/s) | iops | slat(usec) | clat(usec) | merge |
+----------------------------------------------------------------------+
| w/o | 606/612 | 151k/153k | 6.89/7.03 | 3349.21/3305.40 | 0/0 |
+----------------------------------------------------------------------+
| w/ | 1083/616 | 277k/154k | 4.93/6.95 | 1830.62/3279.95 | 223k/3k |
+----------------------------------------------------------------------+
When set numjobs to 16, the bw and iops could reach 1662MB/s and 425k
on my platform.
Signed-off-by: Jianchao Wang <jianchao.w.wang@oracle.com>
Tested-by: Holger Hoffstätte <holger@applied-asynchrony.com>
Reviewed-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2018-05-30 19:47:40 +03:00
|
|
|
struct kyber_hctx_data *khd = hctx->sched_data;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < KYBER_NUM_DOMAINS; i++)
|
|
|
|
sbitmap_free(&khd->kcq_map[i]);
|
|
|
|
kfree(khd->kcqs);
|
2017-04-14 11:00:02 +03:00
|
|
|
kfree(hctx->sched_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int rq_get_domain_token(struct request *rq)
|
|
|
|
{
|
|
|
|
return (long)rq->elv.priv[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
static void rq_set_domain_token(struct request *rq, int token)
|
|
|
|
{
|
|
|
|
rq->elv.priv[0] = (void *)(long)token;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void rq_clear_domain_token(struct kyber_queue_data *kqd,
|
|
|
|
struct request *rq)
|
|
|
|
{
|
|
|
|
unsigned int sched_domain;
|
|
|
|
int nr;
|
|
|
|
|
|
|
|
nr = rq_get_domain_token(rq);
|
|
|
|
if (nr != -1) {
|
block: kyber: make kyber more friendly with merging
Currently, kyber is very unfriendly with merging. kyber depends
on ctx rq_list to do merging, however, most of time, it will not
leave any requests in ctx rq_list. This is because even if tokens
of one domain is used up, kyber will try to dispatch requests
from other domain and flush the rq_list there.
To improve this, we setup kyber_ctx_queue (kcq) which is similar
with ctx, but it has rq_lists for different domain and build same
mapping between kcq and khd as the ctx & hctx. Then we could merge,
insert and dispatch for different domains separately. At the same
time, only flush the rq_list of kcq when get domain token successfully.
Then if one domain token is used up, the requests could be left in
the rq_list of that domain and maybe merged with following io.
Following is my test result on machine with 8 cores and NVMe card
INTEL SSDPEKKR128G7
fio size=256m ioengine=libaio iodepth=64 direct=1 numjobs=8
seq/random
+------+---------------------------------------------------------------+
|patch?| bw(MB/s) | iops | slat(usec) | clat(usec) | merge |
+----------------------------------------------------------------------+
| w/o | 606/612 | 151k/153k | 6.89/7.03 | 3349.21/3305.40 | 0/0 |
+----------------------------------------------------------------------+
| w/ | 1083/616 | 277k/154k | 4.93/6.95 | 1830.62/3279.95 | 223k/3k |
+----------------------------------------------------------------------+
When set numjobs to 16, the bw and iops could reach 1662MB/s and 425k
on my platform.
Signed-off-by: Jianchao Wang <jianchao.w.wang@oracle.com>
Tested-by: Holger Hoffstätte <holger@applied-asynchrony.com>
Reviewed-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2018-05-30 19:47:40 +03:00
|
|
|
sched_domain = kyber_sched_domain(rq->cmd_flags);
|
2017-04-14 11:00:02 +03:00
|
|
|
sbitmap_queue_clear(&kqd->domain_tokens[sched_domain], nr,
|
|
|
|
rq->mq_ctx->cpu);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-14 21:06:35 +03:00
|
|
|
static void kyber_limit_depth(blk_opf_t opf, struct blk_mq_alloc_data *data)
|
2017-04-14 11:00:02 +03:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* We use the scheduler tags as per-hardware queue queueing tokens.
|
|
|
|
* Async requests can be limited at this stage.
|
|
|
|
*/
|
2022-07-14 21:06:35 +03:00
|
|
|
if (!op_is_sync(opf)) {
|
2017-06-16 19:15:26 +03:00
|
|
|
struct kyber_queue_data *kqd = data->q->elevator->elevator_data;
|
|
|
|
|
2017-04-14 11:00:02 +03:00
|
|
|
data->shallow_depth = kqd->async_depth;
|
2017-06-16 19:15:26 +03:00
|
|
|
}
|
|
|
|
}
|
2017-04-14 11:00:02 +03:00
|
|
|
|
2021-05-11 03:05:35 +03:00
|
|
|
static bool kyber_bio_merge(struct request_queue *q, struct bio *bio,
|
2019-06-06 13:29:01 +03:00
|
|
|
unsigned int nr_segs)
|
block: kyber: make kyber more friendly with merging
Currently, kyber is very unfriendly with merging. kyber depends
on ctx rq_list to do merging, however, most of time, it will not
leave any requests in ctx rq_list. This is because even if tokens
of one domain is used up, kyber will try to dispatch requests
from other domain and flush the rq_list there.
To improve this, we setup kyber_ctx_queue (kcq) which is similar
with ctx, but it has rq_lists for different domain and build same
mapping between kcq and khd as the ctx & hctx. Then we could merge,
insert and dispatch for different domains separately. At the same
time, only flush the rq_list of kcq when get domain token successfully.
Then if one domain token is used up, the requests could be left in
the rq_list of that domain and maybe merged with following io.
Following is my test result on machine with 8 cores and NVMe card
INTEL SSDPEKKR128G7
fio size=256m ioengine=libaio iodepth=64 direct=1 numjobs=8
seq/random
+------+---------------------------------------------------------------+
|patch?| bw(MB/s) | iops | slat(usec) | clat(usec) | merge |
+----------------------------------------------------------------------+
| w/o | 606/612 | 151k/153k | 6.89/7.03 | 3349.21/3305.40 | 0/0 |
+----------------------------------------------------------------------+
| w/ | 1083/616 | 277k/154k | 4.93/6.95 | 1830.62/3279.95 | 223k/3k |
+----------------------------------------------------------------------+
When set numjobs to 16, the bw and iops could reach 1662MB/s and 425k
on my platform.
Signed-off-by: Jianchao Wang <jianchao.w.wang@oracle.com>
Tested-by: Holger Hoffstätte <holger@applied-asynchrony.com>
Reviewed-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2018-05-30 19:47:40 +03:00
|
|
|
{
|
2021-05-11 03:05:35 +03:00
|
|
|
struct blk_mq_ctx *ctx = blk_mq_get_ctx(q);
|
|
|
|
struct blk_mq_hw_ctx *hctx = blk_mq_map_queue(q, bio->bi_opf, ctx);
|
block: kyber: make kyber more friendly with merging
Currently, kyber is very unfriendly with merging. kyber depends
on ctx rq_list to do merging, however, most of time, it will not
leave any requests in ctx rq_list. This is because even if tokens
of one domain is used up, kyber will try to dispatch requests
from other domain and flush the rq_list there.
To improve this, we setup kyber_ctx_queue (kcq) which is similar
with ctx, but it has rq_lists for different domain and build same
mapping between kcq and khd as the ctx & hctx. Then we could merge,
insert and dispatch for different domains separately. At the same
time, only flush the rq_list of kcq when get domain token successfully.
Then if one domain token is used up, the requests could be left in
the rq_list of that domain and maybe merged with following io.
Following is my test result on machine with 8 cores and NVMe card
INTEL SSDPEKKR128G7
fio size=256m ioengine=libaio iodepth=64 direct=1 numjobs=8
seq/random
+------+---------------------------------------------------------------+
|patch?| bw(MB/s) | iops | slat(usec) | clat(usec) | merge |
+----------------------------------------------------------------------+
| w/o | 606/612 | 151k/153k | 6.89/7.03 | 3349.21/3305.40 | 0/0 |
+----------------------------------------------------------------------+
| w/ | 1083/616 | 277k/154k | 4.93/6.95 | 1830.62/3279.95 | 223k/3k |
+----------------------------------------------------------------------+
When set numjobs to 16, the bw and iops could reach 1662MB/s and 425k
on my platform.
Signed-off-by: Jianchao Wang <jianchao.w.wang@oracle.com>
Tested-by: Holger Hoffstätte <holger@applied-asynchrony.com>
Reviewed-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2018-05-30 19:47:40 +03:00
|
|
|
struct kyber_hctx_data *khd = hctx->sched_data;
|
2018-10-29 22:13:29 +03:00
|
|
|
struct kyber_ctx_queue *kcq = &khd->kcqs[ctx->index_hw[hctx->type]];
|
block: kyber: make kyber more friendly with merging
Currently, kyber is very unfriendly with merging. kyber depends
on ctx rq_list to do merging, however, most of time, it will not
leave any requests in ctx rq_list. This is because even if tokens
of one domain is used up, kyber will try to dispatch requests
from other domain and flush the rq_list there.
To improve this, we setup kyber_ctx_queue (kcq) which is similar
with ctx, but it has rq_lists for different domain and build same
mapping between kcq and khd as the ctx & hctx. Then we could merge,
insert and dispatch for different domains separately. At the same
time, only flush the rq_list of kcq when get domain token successfully.
Then if one domain token is used up, the requests could be left in
the rq_list of that domain and maybe merged with following io.
Following is my test result on machine with 8 cores and NVMe card
INTEL SSDPEKKR128G7
fio size=256m ioengine=libaio iodepth=64 direct=1 numjobs=8
seq/random
+------+---------------------------------------------------------------+
|patch?| bw(MB/s) | iops | slat(usec) | clat(usec) | merge |
+----------------------------------------------------------------------+
| w/o | 606/612 | 151k/153k | 6.89/7.03 | 3349.21/3305.40 | 0/0 |
+----------------------------------------------------------------------+
| w/ | 1083/616 | 277k/154k | 4.93/6.95 | 1830.62/3279.95 | 223k/3k |
+----------------------------------------------------------------------+
When set numjobs to 16, the bw and iops could reach 1662MB/s and 425k
on my platform.
Signed-off-by: Jianchao Wang <jianchao.w.wang@oracle.com>
Tested-by: Holger Hoffstätte <holger@applied-asynchrony.com>
Reviewed-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2018-05-30 19:47:40 +03:00
|
|
|
unsigned int sched_domain = kyber_sched_domain(bio->bi_opf);
|
|
|
|
struct list_head *rq_list = &kcq->rq_list[sched_domain];
|
|
|
|
bool merged;
|
|
|
|
|
|
|
|
spin_lock(&kcq->lock);
|
2020-08-28 05:52:55 +03:00
|
|
|
merged = blk_bio_list_merge(hctx->queue, rq_list, bio, nr_segs);
|
block: kyber: make kyber more friendly with merging
Currently, kyber is very unfriendly with merging. kyber depends
on ctx rq_list to do merging, however, most of time, it will not
leave any requests in ctx rq_list. This is because even if tokens
of one domain is used up, kyber will try to dispatch requests
from other domain and flush the rq_list there.
To improve this, we setup kyber_ctx_queue (kcq) which is similar
with ctx, but it has rq_lists for different domain and build same
mapping between kcq and khd as the ctx & hctx. Then we could merge,
insert and dispatch for different domains separately. At the same
time, only flush the rq_list of kcq when get domain token successfully.
Then if one domain token is used up, the requests could be left in
the rq_list of that domain and maybe merged with following io.
Following is my test result on machine with 8 cores and NVMe card
INTEL SSDPEKKR128G7
fio size=256m ioengine=libaio iodepth=64 direct=1 numjobs=8
seq/random
+------+---------------------------------------------------------------+
|patch?| bw(MB/s) | iops | slat(usec) | clat(usec) | merge |
+----------------------------------------------------------------------+
| w/o | 606/612 | 151k/153k | 6.89/7.03 | 3349.21/3305.40 | 0/0 |
+----------------------------------------------------------------------+
| w/ | 1083/616 | 277k/154k | 4.93/6.95 | 1830.62/3279.95 | 223k/3k |
+----------------------------------------------------------------------+
When set numjobs to 16, the bw and iops could reach 1662MB/s and 425k
on my platform.
Signed-off-by: Jianchao Wang <jianchao.w.wang@oracle.com>
Tested-by: Holger Hoffstätte <holger@applied-asynchrony.com>
Reviewed-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2018-05-30 19:47:40 +03:00
|
|
|
spin_unlock(&kcq->lock);
|
|
|
|
|
|
|
|
return merged;
|
|
|
|
}
|
|
|
|
|
2020-05-29 16:53:08 +03:00
|
|
|
static void kyber_prepare_request(struct request *rq)
|
2017-06-16 19:15:26 +03:00
|
|
|
{
|
|
|
|
rq_set_domain_token(rq, -1);
|
2017-04-14 11:00:02 +03:00
|
|
|
}
|
|
|
|
|
block: kyber: make kyber more friendly with merging
Currently, kyber is very unfriendly with merging. kyber depends
on ctx rq_list to do merging, however, most of time, it will not
leave any requests in ctx rq_list. This is because even if tokens
of one domain is used up, kyber will try to dispatch requests
from other domain and flush the rq_list there.
To improve this, we setup kyber_ctx_queue (kcq) which is similar
with ctx, but it has rq_lists for different domain and build same
mapping between kcq and khd as the ctx & hctx. Then we could merge,
insert and dispatch for different domains separately. At the same
time, only flush the rq_list of kcq when get domain token successfully.
Then if one domain token is used up, the requests could be left in
the rq_list of that domain and maybe merged with following io.
Following is my test result on machine with 8 cores and NVMe card
INTEL SSDPEKKR128G7
fio size=256m ioengine=libaio iodepth=64 direct=1 numjobs=8
seq/random
+------+---------------------------------------------------------------+
|patch?| bw(MB/s) | iops | slat(usec) | clat(usec) | merge |
+----------------------------------------------------------------------+
| w/o | 606/612 | 151k/153k | 6.89/7.03 | 3349.21/3305.40 | 0/0 |
+----------------------------------------------------------------------+
| w/ | 1083/616 | 277k/154k | 4.93/6.95 | 1830.62/3279.95 | 223k/3k |
+----------------------------------------------------------------------+
When set numjobs to 16, the bw and iops could reach 1662MB/s and 425k
on my platform.
Signed-off-by: Jianchao Wang <jianchao.w.wang@oracle.com>
Tested-by: Holger Hoffstätte <holger@applied-asynchrony.com>
Reviewed-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2018-05-30 19:47:40 +03:00
|
|
|
static void kyber_insert_requests(struct blk_mq_hw_ctx *hctx,
|
|
|
|
struct list_head *rq_list, bool at_head)
|
|
|
|
{
|
|
|
|
struct kyber_hctx_data *khd = hctx->sched_data;
|
|
|
|
struct request *rq, *next;
|
|
|
|
|
|
|
|
list_for_each_entry_safe(rq, next, rq_list, queuelist) {
|
|
|
|
unsigned int sched_domain = kyber_sched_domain(rq->cmd_flags);
|
2018-10-29 22:13:29 +03:00
|
|
|
struct kyber_ctx_queue *kcq = &khd->kcqs[rq->mq_ctx->index_hw[hctx->type]];
|
block: kyber: make kyber more friendly with merging
Currently, kyber is very unfriendly with merging. kyber depends
on ctx rq_list to do merging, however, most of time, it will not
leave any requests in ctx rq_list. This is because even if tokens
of one domain is used up, kyber will try to dispatch requests
from other domain and flush the rq_list there.
To improve this, we setup kyber_ctx_queue (kcq) which is similar
with ctx, but it has rq_lists for different domain and build same
mapping between kcq and khd as the ctx & hctx. Then we could merge,
insert and dispatch for different domains separately. At the same
time, only flush the rq_list of kcq when get domain token successfully.
Then if one domain token is used up, the requests could be left in
the rq_list of that domain and maybe merged with following io.
Following is my test result on machine with 8 cores and NVMe card
INTEL SSDPEKKR128G7
fio size=256m ioengine=libaio iodepth=64 direct=1 numjobs=8
seq/random
+------+---------------------------------------------------------------+
|patch?| bw(MB/s) | iops | slat(usec) | clat(usec) | merge |
+----------------------------------------------------------------------+
| w/o | 606/612 | 151k/153k | 6.89/7.03 | 3349.21/3305.40 | 0/0 |
+----------------------------------------------------------------------+
| w/ | 1083/616 | 277k/154k | 4.93/6.95 | 1830.62/3279.95 | 223k/3k |
+----------------------------------------------------------------------+
When set numjobs to 16, the bw and iops could reach 1662MB/s and 425k
on my platform.
Signed-off-by: Jianchao Wang <jianchao.w.wang@oracle.com>
Tested-by: Holger Hoffstätte <holger@applied-asynchrony.com>
Reviewed-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2018-05-30 19:47:40 +03:00
|
|
|
struct list_head *head = &kcq->rq_list[sched_domain];
|
|
|
|
|
|
|
|
spin_lock(&kcq->lock);
|
2021-08-04 22:49:23 +03:00
|
|
|
trace_block_rq_insert(rq);
|
block: kyber: make kyber more friendly with merging
Currently, kyber is very unfriendly with merging. kyber depends
on ctx rq_list to do merging, however, most of time, it will not
leave any requests in ctx rq_list. This is because even if tokens
of one domain is used up, kyber will try to dispatch requests
from other domain and flush the rq_list there.
To improve this, we setup kyber_ctx_queue (kcq) which is similar
with ctx, but it has rq_lists for different domain and build same
mapping between kcq and khd as the ctx & hctx. Then we could merge,
insert and dispatch for different domains separately. At the same
time, only flush the rq_list of kcq when get domain token successfully.
Then if one domain token is used up, the requests could be left in
the rq_list of that domain and maybe merged with following io.
Following is my test result on machine with 8 cores and NVMe card
INTEL SSDPEKKR128G7
fio size=256m ioengine=libaio iodepth=64 direct=1 numjobs=8
seq/random
+------+---------------------------------------------------------------+
|patch?| bw(MB/s) | iops | slat(usec) | clat(usec) | merge |
+----------------------------------------------------------------------+
| w/o | 606/612 | 151k/153k | 6.89/7.03 | 3349.21/3305.40 | 0/0 |
+----------------------------------------------------------------------+
| w/ | 1083/616 | 277k/154k | 4.93/6.95 | 1830.62/3279.95 | 223k/3k |
+----------------------------------------------------------------------+
When set numjobs to 16, the bw and iops could reach 1662MB/s and 425k
on my platform.
Signed-off-by: Jianchao Wang <jianchao.w.wang@oracle.com>
Tested-by: Holger Hoffstätte <holger@applied-asynchrony.com>
Reviewed-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2018-05-30 19:47:40 +03:00
|
|
|
if (at_head)
|
|
|
|
list_move(&rq->queuelist, head);
|
|
|
|
else
|
|
|
|
list_move_tail(&rq->queuelist, head);
|
|
|
|
sbitmap_set_bit(&khd->kcq_map[sched_domain],
|
2018-10-29 22:13:29 +03:00
|
|
|
rq->mq_ctx->index_hw[hctx->type]);
|
block: kyber: make kyber more friendly with merging
Currently, kyber is very unfriendly with merging. kyber depends
on ctx rq_list to do merging, however, most of time, it will not
leave any requests in ctx rq_list. This is because even if tokens
of one domain is used up, kyber will try to dispatch requests
from other domain and flush the rq_list there.
To improve this, we setup kyber_ctx_queue (kcq) which is similar
with ctx, but it has rq_lists for different domain and build same
mapping between kcq and khd as the ctx & hctx. Then we could merge,
insert and dispatch for different domains separately. At the same
time, only flush the rq_list of kcq when get domain token successfully.
Then if one domain token is used up, the requests could be left in
the rq_list of that domain and maybe merged with following io.
Following is my test result on machine with 8 cores and NVMe card
INTEL SSDPEKKR128G7
fio size=256m ioengine=libaio iodepth=64 direct=1 numjobs=8
seq/random
+------+---------------------------------------------------------------+
|patch?| bw(MB/s) | iops | slat(usec) | clat(usec) | merge |
+----------------------------------------------------------------------+
| w/o | 606/612 | 151k/153k | 6.89/7.03 | 3349.21/3305.40 | 0/0 |
+----------------------------------------------------------------------+
| w/ | 1083/616 | 277k/154k | 4.93/6.95 | 1830.62/3279.95 | 223k/3k |
+----------------------------------------------------------------------+
When set numjobs to 16, the bw and iops could reach 1662MB/s and 425k
on my platform.
Signed-off-by: Jianchao Wang <jianchao.w.wang@oracle.com>
Tested-by: Holger Hoffstätte <holger@applied-asynchrony.com>
Reviewed-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2018-05-30 19:47:40 +03:00
|
|
|
spin_unlock(&kcq->lock);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-16 19:15:21 +03:00
|
|
|
static void kyber_finish_request(struct request *rq)
|
2017-04-14 11:00:02 +03:00
|
|
|
{
|
2017-06-16 19:15:21 +03:00
|
|
|
struct kyber_queue_data *kqd = rq->q->elevator->elevator_data;
|
2017-04-14 11:00:02 +03:00
|
|
|
|
|
|
|
rq_clear_domain_token(kqd, rq);
|
|
|
|
}
|
|
|
|
|
kyber: implement improved heuristics
Kyber's current heuristics have a few flaws:
- It's based on the mean latency, but p99 latency tends to be more
meaningful to anyone who cares about latency. The mean can also be
skewed by rare outliers that the scheduler can't do anything about.
- The statistics calculations are purely time-based with a short window.
This works for steady, high load, but is more sensitive to outliers
with bursty workloads.
- It only considers the latency once an I/O has been submitted to the
device, but the user cares about the time spent in the kernel, as
well.
These are shortcomings of the generic blk-stat code which doesn't quite
fit the ideal use case for Kyber. So, this replaces the statistics with
a histogram used to calculate percentiles of total latency and I/O
latency, which we then use to adjust depths in a slightly more
intelligent manner:
- Sync and async writes are now the same domain.
- Discards are a separate domain.
- Domain queue depths are scaled by the ratio of the p99 total latency
to the target latency (e.g., if the p99 latency is double the target
latency, we will double the queue depth; if the p99 latency is half of
the target latency, we can halve the queue depth).
- We use the I/O latency to determine whether we should scale queue
depths down: we will only scale down if any domain's I/O latency
exceeds the target latency, which is an indicator of congestion in the
device.
These new heuristics are just as scalable as the heuristics they
replace.
Signed-off-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2018-09-28 01:55:54 +03:00
|
|
|
static void add_latency_sample(struct kyber_cpu_latency *cpu_latency,
|
|
|
|
unsigned int sched_domain, unsigned int type,
|
|
|
|
u64 target, u64 latency)
|
2017-04-14 11:00:02 +03:00
|
|
|
{
|
kyber: implement improved heuristics
Kyber's current heuristics have a few flaws:
- It's based on the mean latency, but p99 latency tends to be more
meaningful to anyone who cares about latency. The mean can also be
skewed by rare outliers that the scheduler can't do anything about.
- The statistics calculations are purely time-based with a short window.
This works for steady, high load, but is more sensitive to outliers
with bursty workloads.
- It only considers the latency once an I/O has been submitted to the
device, but the user cares about the time spent in the kernel, as
well.
These are shortcomings of the generic blk-stat code which doesn't quite
fit the ideal use case for Kyber. So, this replaces the statistics with
a histogram used to calculate percentiles of total latency and I/O
latency, which we then use to adjust depths in a slightly more
intelligent manner:
- Sync and async writes are now the same domain.
- Discards are a separate domain.
- Domain queue depths are scaled by the ratio of the p99 total latency
to the target latency (e.g., if the p99 latency is double the target
latency, we will double the queue depth; if the p99 latency is half of
the target latency, we can halve the queue depth).
- We use the I/O latency to determine whether we should scale queue
depths down: we will only scale down if any domain's I/O latency
exceeds the target latency, which is an indicator of congestion in the
device.
These new heuristics are just as scalable as the heuristics they
replace.
Signed-off-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2018-09-28 01:55:54 +03:00
|
|
|
unsigned int bucket;
|
|
|
|
u64 divisor;
|
2017-04-14 11:00:02 +03:00
|
|
|
|
kyber: implement improved heuristics
Kyber's current heuristics have a few flaws:
- It's based on the mean latency, but p99 latency tends to be more
meaningful to anyone who cares about latency. The mean can also be
skewed by rare outliers that the scheduler can't do anything about.
- The statistics calculations are purely time-based with a short window.
This works for steady, high load, but is more sensitive to outliers
with bursty workloads.
- It only considers the latency once an I/O has been submitted to the
device, but the user cares about the time spent in the kernel, as
well.
These are shortcomings of the generic blk-stat code which doesn't quite
fit the ideal use case for Kyber. So, this replaces the statistics with
a histogram used to calculate percentiles of total latency and I/O
latency, which we then use to adjust depths in a slightly more
intelligent manner:
- Sync and async writes are now the same domain.
- Discards are a separate domain.
- Domain queue depths are scaled by the ratio of the p99 total latency
to the target latency (e.g., if the p99 latency is double the target
latency, we will double the queue depth; if the p99 latency is half of
the target latency, we can halve the queue depth).
- We use the I/O latency to determine whether we should scale queue
depths down: we will only scale down if any domain's I/O latency
exceeds the target latency, which is an indicator of congestion in the
device.
These new heuristics are just as scalable as the heuristics they
replace.
Signed-off-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2018-09-28 01:55:54 +03:00
|
|
|
if (latency > 0) {
|
|
|
|
divisor = max_t(u64, target >> KYBER_LATENCY_SHIFT, 1);
|
|
|
|
bucket = min_t(unsigned int, div64_u64(latency - 1, divisor),
|
|
|
|
KYBER_LATENCY_BUCKETS - 1);
|
|
|
|
} else {
|
|
|
|
bucket = 0;
|
2017-04-14 11:00:02 +03:00
|
|
|
}
|
|
|
|
|
kyber: implement improved heuristics
Kyber's current heuristics have a few flaws:
- It's based on the mean latency, but p99 latency tends to be more
meaningful to anyone who cares about latency. The mean can also be
skewed by rare outliers that the scheduler can't do anything about.
- The statistics calculations are purely time-based with a short window.
This works for steady, high load, but is more sensitive to outliers
with bursty workloads.
- It only considers the latency once an I/O has been submitted to the
device, but the user cares about the time spent in the kernel, as
well.
These are shortcomings of the generic blk-stat code which doesn't quite
fit the ideal use case for Kyber. So, this replaces the statistics with
a histogram used to calculate percentiles of total latency and I/O
latency, which we then use to adjust depths in a slightly more
intelligent manner:
- Sync and async writes are now the same domain.
- Discards are a separate domain.
- Domain queue depths are scaled by the ratio of the p99 total latency
to the target latency (e.g., if the p99 latency is double the target
latency, we will double the queue depth; if the p99 latency is half of
the target latency, we can halve the queue depth).
- We use the I/O latency to determine whether we should scale queue
depths down: we will only scale down if any domain's I/O latency
exceeds the target latency, which is an indicator of congestion in the
device.
These new heuristics are just as scalable as the heuristics they
replace.
Signed-off-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2018-09-28 01:55:54 +03:00
|
|
|
atomic_inc(&cpu_latency->buckets[sched_domain][type][bucket]);
|
|
|
|
}
|
2017-04-14 11:00:02 +03:00
|
|
|
|
kyber: implement improved heuristics
Kyber's current heuristics have a few flaws:
- It's based on the mean latency, but p99 latency tends to be more
meaningful to anyone who cares about latency. The mean can also be
skewed by rare outliers that the scheduler can't do anything about.
- The statistics calculations are purely time-based with a short window.
This works for steady, high load, but is more sensitive to outliers
with bursty workloads.
- It only considers the latency once an I/O has been submitted to the
device, but the user cares about the time spent in the kernel, as
well.
These are shortcomings of the generic blk-stat code which doesn't quite
fit the ideal use case for Kyber. So, this replaces the statistics with
a histogram used to calculate percentiles of total latency and I/O
latency, which we then use to adjust depths in a slightly more
intelligent manner:
- Sync and async writes are now the same domain.
- Discards are a separate domain.
- Domain queue depths are scaled by the ratio of the p99 total latency
to the target latency (e.g., if the p99 latency is double the target
latency, we will double the queue depth; if the p99 latency is half of
the target latency, we can halve the queue depth).
- We use the I/O latency to determine whether we should scale queue
depths down: we will only scale down if any domain's I/O latency
exceeds the target latency, which is an indicator of congestion in the
device.
These new heuristics are just as scalable as the heuristics they
replace.
Signed-off-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2018-09-28 01:55:54 +03:00
|
|
|
static void kyber_completed_request(struct request *rq, u64 now)
|
|
|
|
{
|
|
|
|
struct kyber_queue_data *kqd = rq->q->elevator->elevator_data;
|
|
|
|
struct kyber_cpu_latency *cpu_latency;
|
|
|
|
unsigned int sched_domain;
|
|
|
|
u64 target;
|
|
|
|
|
|
|
|
sched_domain = kyber_sched_domain(rq->cmd_flags);
|
|
|
|
if (sched_domain == KYBER_OTHER)
|
2017-04-14 11:00:02 +03:00
|
|
|
return;
|
|
|
|
|
kyber: implement improved heuristics
Kyber's current heuristics have a few flaws:
- It's based on the mean latency, but p99 latency tends to be more
meaningful to anyone who cares about latency. The mean can also be
skewed by rare outliers that the scheduler can't do anything about.
- The statistics calculations are purely time-based with a short window.
This works for steady, high load, but is more sensitive to outliers
with bursty workloads.
- It only considers the latency once an I/O has been submitted to the
device, but the user cares about the time spent in the kernel, as
well.
These are shortcomings of the generic blk-stat code which doesn't quite
fit the ideal use case for Kyber. So, this replaces the statistics with
a histogram used to calculate percentiles of total latency and I/O
latency, which we then use to adjust depths in a slightly more
intelligent manner:
- Sync and async writes are now the same domain.
- Discards are a separate domain.
- Domain queue depths are scaled by the ratio of the p99 total latency
to the target latency (e.g., if the p99 latency is double the target
latency, we will double the queue depth; if the p99 latency is half of
the target latency, we can halve the queue depth).
- We use the I/O latency to determine whether we should scale queue
depths down: we will only scale down if any domain's I/O latency
exceeds the target latency, which is an indicator of congestion in the
device.
These new heuristics are just as scalable as the heuristics they
replace.
Signed-off-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2018-09-28 01:55:54 +03:00
|
|
|
cpu_latency = get_cpu_ptr(kqd->cpu_latency);
|
|
|
|
target = kqd->latency_targets[sched_domain];
|
|
|
|
add_latency_sample(cpu_latency, sched_domain, KYBER_TOTAL_LATENCY,
|
|
|
|
target, now - rq->start_time_ns);
|
|
|
|
add_latency_sample(cpu_latency, sched_domain, KYBER_IO_LATENCY, target,
|
|
|
|
now - rq->io_start_time_ns);
|
|
|
|
put_cpu_ptr(kqd->cpu_latency);
|
2017-04-14 11:00:02 +03:00
|
|
|
|
kyber: implement improved heuristics
Kyber's current heuristics have a few flaws:
- It's based on the mean latency, but p99 latency tends to be more
meaningful to anyone who cares about latency. The mean can also be
skewed by rare outliers that the scheduler can't do anything about.
- The statistics calculations are purely time-based with a short window.
This works for steady, high load, but is more sensitive to outliers
with bursty workloads.
- It only considers the latency once an I/O has been submitted to the
device, but the user cares about the time spent in the kernel, as
well.
These are shortcomings of the generic blk-stat code which doesn't quite
fit the ideal use case for Kyber. So, this replaces the statistics with
a histogram used to calculate percentiles of total latency and I/O
latency, which we then use to adjust depths in a slightly more
intelligent manner:
- Sync and async writes are now the same domain.
- Discards are a separate domain.
- Domain queue depths are scaled by the ratio of the p99 total latency
to the target latency (e.g., if the p99 latency is double the target
latency, we will double the queue depth; if the p99 latency is half of
the target latency, we can halve the queue depth).
- We use the I/O latency to determine whether we should scale queue
depths down: we will only scale down if any domain's I/O latency
exceeds the target latency, which is an indicator of congestion in the
device.
These new heuristics are just as scalable as the heuristics they
replace.
Signed-off-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2018-09-28 01:55:54 +03:00
|
|
|
timer_reduce(&kqd->timer, jiffies + HZ / 10);
|
2017-04-14 11:00:02 +03:00
|
|
|
}
|
|
|
|
|
block: kyber: make kyber more friendly with merging
Currently, kyber is very unfriendly with merging. kyber depends
on ctx rq_list to do merging, however, most of time, it will not
leave any requests in ctx rq_list. This is because even if tokens
of one domain is used up, kyber will try to dispatch requests
from other domain and flush the rq_list there.
To improve this, we setup kyber_ctx_queue (kcq) which is similar
with ctx, but it has rq_lists for different domain and build same
mapping between kcq and khd as the ctx & hctx. Then we could merge,
insert and dispatch for different domains separately. At the same
time, only flush the rq_list of kcq when get domain token successfully.
Then if one domain token is used up, the requests could be left in
the rq_list of that domain and maybe merged with following io.
Following is my test result on machine with 8 cores and NVMe card
INTEL SSDPEKKR128G7
fio size=256m ioengine=libaio iodepth=64 direct=1 numjobs=8
seq/random
+------+---------------------------------------------------------------+
|patch?| bw(MB/s) | iops | slat(usec) | clat(usec) | merge |
+----------------------------------------------------------------------+
| w/o | 606/612 | 151k/153k | 6.89/7.03 | 3349.21/3305.40 | 0/0 |
+----------------------------------------------------------------------+
| w/ | 1083/616 | 277k/154k | 4.93/6.95 | 1830.62/3279.95 | 223k/3k |
+----------------------------------------------------------------------+
When set numjobs to 16, the bw and iops could reach 1662MB/s and 425k
on my platform.
Signed-off-by: Jianchao Wang <jianchao.w.wang@oracle.com>
Tested-by: Holger Hoffstätte <holger@applied-asynchrony.com>
Reviewed-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2018-05-30 19:47:40 +03:00
|
|
|
struct flush_kcq_data {
|
|
|
|
struct kyber_hctx_data *khd;
|
|
|
|
unsigned int sched_domain;
|
|
|
|
struct list_head *list;
|
|
|
|
};
|
|
|
|
|
|
|
|
static bool flush_busy_kcq(struct sbitmap *sb, unsigned int bitnr, void *data)
|
2017-04-14 11:00:02 +03:00
|
|
|
{
|
block: kyber: make kyber more friendly with merging
Currently, kyber is very unfriendly with merging. kyber depends
on ctx rq_list to do merging, however, most of time, it will not
leave any requests in ctx rq_list. This is because even if tokens
of one domain is used up, kyber will try to dispatch requests
from other domain and flush the rq_list there.
To improve this, we setup kyber_ctx_queue (kcq) which is similar
with ctx, but it has rq_lists for different domain and build same
mapping between kcq and khd as the ctx & hctx. Then we could merge,
insert and dispatch for different domains separately. At the same
time, only flush the rq_list of kcq when get domain token successfully.
Then if one domain token is used up, the requests could be left in
the rq_list of that domain and maybe merged with following io.
Following is my test result on machine with 8 cores and NVMe card
INTEL SSDPEKKR128G7
fio size=256m ioengine=libaio iodepth=64 direct=1 numjobs=8
seq/random
+------+---------------------------------------------------------------+
|patch?| bw(MB/s) | iops | slat(usec) | clat(usec) | merge |
+----------------------------------------------------------------------+
| w/o | 606/612 | 151k/153k | 6.89/7.03 | 3349.21/3305.40 | 0/0 |
+----------------------------------------------------------------------+
| w/ | 1083/616 | 277k/154k | 4.93/6.95 | 1830.62/3279.95 | 223k/3k |
+----------------------------------------------------------------------+
When set numjobs to 16, the bw and iops could reach 1662MB/s and 425k
on my platform.
Signed-off-by: Jianchao Wang <jianchao.w.wang@oracle.com>
Tested-by: Holger Hoffstätte <holger@applied-asynchrony.com>
Reviewed-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2018-05-30 19:47:40 +03:00
|
|
|
struct flush_kcq_data *flush_data = data;
|
|
|
|
struct kyber_ctx_queue *kcq = &flush_data->khd->kcqs[bitnr];
|
2017-04-14 11:00:02 +03:00
|
|
|
|
block: kyber: make kyber more friendly with merging
Currently, kyber is very unfriendly with merging. kyber depends
on ctx rq_list to do merging, however, most of time, it will not
leave any requests in ctx rq_list. This is because even if tokens
of one domain is used up, kyber will try to dispatch requests
from other domain and flush the rq_list there.
To improve this, we setup kyber_ctx_queue (kcq) which is similar
with ctx, but it has rq_lists for different domain and build same
mapping between kcq and khd as the ctx & hctx. Then we could merge,
insert and dispatch for different domains separately. At the same
time, only flush the rq_list of kcq when get domain token successfully.
Then if one domain token is used up, the requests could be left in
the rq_list of that domain and maybe merged with following io.
Following is my test result on machine with 8 cores and NVMe card
INTEL SSDPEKKR128G7
fio size=256m ioengine=libaio iodepth=64 direct=1 numjobs=8
seq/random
+------+---------------------------------------------------------------+
|patch?| bw(MB/s) | iops | slat(usec) | clat(usec) | merge |
+----------------------------------------------------------------------+
| w/o | 606/612 | 151k/153k | 6.89/7.03 | 3349.21/3305.40 | 0/0 |
+----------------------------------------------------------------------+
| w/ | 1083/616 | 277k/154k | 4.93/6.95 | 1830.62/3279.95 | 223k/3k |
+----------------------------------------------------------------------+
When set numjobs to 16, the bw and iops could reach 1662MB/s and 425k
on my platform.
Signed-off-by: Jianchao Wang <jianchao.w.wang@oracle.com>
Tested-by: Holger Hoffstätte <holger@applied-asynchrony.com>
Reviewed-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2018-05-30 19:47:40 +03:00
|
|
|
spin_lock(&kcq->lock);
|
|
|
|
list_splice_tail_init(&kcq->rq_list[flush_data->sched_domain],
|
|
|
|
flush_data->list);
|
|
|
|
sbitmap_clear_bit(sb, bitnr);
|
|
|
|
spin_unlock(&kcq->lock);
|
2017-04-14 11:00:02 +03:00
|
|
|
|
block: kyber: make kyber more friendly with merging
Currently, kyber is very unfriendly with merging. kyber depends
on ctx rq_list to do merging, however, most of time, it will not
leave any requests in ctx rq_list. This is because even if tokens
of one domain is used up, kyber will try to dispatch requests
from other domain and flush the rq_list there.
To improve this, we setup kyber_ctx_queue (kcq) which is similar
with ctx, but it has rq_lists for different domain and build same
mapping between kcq and khd as the ctx & hctx. Then we could merge,
insert and dispatch for different domains separately. At the same
time, only flush the rq_list of kcq when get domain token successfully.
Then if one domain token is used up, the requests could be left in
the rq_list of that domain and maybe merged with following io.
Following is my test result on machine with 8 cores and NVMe card
INTEL SSDPEKKR128G7
fio size=256m ioengine=libaio iodepth=64 direct=1 numjobs=8
seq/random
+------+---------------------------------------------------------------+
|patch?| bw(MB/s) | iops | slat(usec) | clat(usec) | merge |
+----------------------------------------------------------------------+
| w/o | 606/612 | 151k/153k | 6.89/7.03 | 3349.21/3305.40 | 0/0 |
+----------------------------------------------------------------------+
| w/ | 1083/616 | 277k/154k | 4.93/6.95 | 1830.62/3279.95 | 223k/3k |
+----------------------------------------------------------------------+
When set numjobs to 16, the bw and iops could reach 1662MB/s and 425k
on my platform.
Signed-off-by: Jianchao Wang <jianchao.w.wang@oracle.com>
Tested-by: Holger Hoffstätte <holger@applied-asynchrony.com>
Reviewed-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2018-05-30 19:47:40 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void kyber_flush_busy_kcqs(struct kyber_hctx_data *khd,
|
|
|
|
unsigned int sched_domain,
|
|
|
|
struct list_head *list)
|
|
|
|
{
|
|
|
|
struct flush_kcq_data data = {
|
|
|
|
.khd = khd,
|
|
|
|
.sched_domain = sched_domain,
|
|
|
|
.list = list,
|
|
|
|
};
|
|
|
|
|
|
|
|
sbitmap_for_each_set(&khd->kcq_map[sched_domain],
|
|
|
|
flush_busy_kcq, &data);
|
2017-04-14 11:00:02 +03:00
|
|
|
}
|
|
|
|
|
2018-12-20 18:50:58 +03:00
|
|
|
static int kyber_domain_wake(wait_queue_entry_t *wqe, unsigned mode, int flags,
|
2017-04-14 11:00:02 +03:00
|
|
|
void *key)
|
|
|
|
{
|
2018-12-20 18:50:58 +03:00
|
|
|
struct blk_mq_hw_ctx *hctx = READ_ONCE(wqe->private);
|
|
|
|
struct sbq_wait *wait = container_of(wqe, struct sbq_wait, wait);
|
2017-04-14 11:00:02 +03:00
|
|
|
|
2018-12-20 18:50:58 +03:00
|
|
|
sbitmap_del_wait_queue(wait);
|
2017-04-14 11:00:02 +03:00
|
|
|
blk_mq_run_hw_queue(hctx, true);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int kyber_get_domain_token(struct kyber_queue_data *kqd,
|
|
|
|
struct kyber_hctx_data *khd,
|
|
|
|
struct blk_mq_hw_ctx *hctx)
|
|
|
|
{
|
|
|
|
unsigned int sched_domain = khd->cur_domain;
|
|
|
|
struct sbitmap_queue *domain_tokens = &kqd->domain_tokens[sched_domain];
|
2018-12-20 18:50:58 +03:00
|
|
|
struct sbq_wait *wait = &khd->domain_wait[sched_domain];
|
2017-04-14 11:00:02 +03:00
|
|
|
struct sbq_wait_state *ws;
|
|
|
|
int nr;
|
|
|
|
|
|
|
|
nr = __sbitmap_queue_get(domain_tokens);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If we failed to get a domain token, make sure the hardware queue is
|
|
|
|
* run when one becomes available. Note that this is serialized on
|
|
|
|
* khd->lock, but we still need to be careful about the waker.
|
|
|
|
*/
|
2018-12-20 18:50:58 +03:00
|
|
|
if (nr < 0 && list_empty_careful(&wait->wait.entry)) {
|
2017-04-14 11:00:02 +03:00
|
|
|
ws = sbq_wait_ptr(domain_tokens,
|
|
|
|
&khd->wait_index[sched_domain]);
|
2017-12-06 09:57:43 +03:00
|
|
|
khd->domain_ws[sched_domain] = ws;
|
2018-12-20 18:50:58 +03:00
|
|
|
sbitmap_add_wait_queue(domain_tokens, ws, wait);
|
2017-04-14 11:00:02 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Try again in case a token was freed before we got on the wait
|
2017-12-06 09:57:43 +03:00
|
|
|
* queue.
|
2017-04-14 11:00:02 +03:00
|
|
|
*/
|
|
|
|
nr = __sbitmap_queue_get(domain_tokens);
|
2017-12-06 09:57:43 +03:00
|
|
|
}
|
2017-10-11 20:39:15 +03:00
|
|
|
|
2017-12-06 09:57:43 +03:00
|
|
|
/*
|
|
|
|
* If we got a token while we were on the wait queue, remove ourselves
|
|
|
|
* from the wait queue to ensure that all wake ups make forward
|
|
|
|
* progress. It's possible that the waker already deleted the entry
|
|
|
|
* between the !list_empty_careful() check and us grabbing the lock, but
|
|
|
|
* list_del_init() is okay with that.
|
|
|
|
*/
|
2018-12-20 18:50:58 +03:00
|
|
|
if (nr >= 0 && !list_empty_careful(&wait->wait.entry)) {
|
2017-12-06 09:57:43 +03:00
|
|
|
ws = khd->domain_ws[sched_domain];
|
|
|
|
spin_lock_irq(&ws->wait.lock);
|
2018-12-20 18:50:58 +03:00
|
|
|
sbitmap_del_wait_queue(wait);
|
2017-12-06 09:57:43 +03:00
|
|
|
spin_unlock_irq(&ws->wait.lock);
|
2017-04-14 11:00:02 +03:00
|
|
|
}
|
2017-12-06 09:57:43 +03:00
|
|
|
|
2017-04-14 11:00:02 +03:00
|
|
|
return nr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct request *
|
|
|
|
kyber_dispatch_cur_domain(struct kyber_queue_data *kqd,
|
|
|
|
struct kyber_hctx_data *khd,
|
block: kyber: make kyber more friendly with merging
Currently, kyber is very unfriendly with merging. kyber depends
on ctx rq_list to do merging, however, most of time, it will not
leave any requests in ctx rq_list. This is because even if tokens
of one domain is used up, kyber will try to dispatch requests
from other domain and flush the rq_list there.
To improve this, we setup kyber_ctx_queue (kcq) which is similar
with ctx, but it has rq_lists for different domain and build same
mapping between kcq and khd as the ctx & hctx. Then we could merge,
insert and dispatch for different domains separately. At the same
time, only flush the rq_list of kcq when get domain token successfully.
Then if one domain token is used up, the requests could be left in
the rq_list of that domain and maybe merged with following io.
Following is my test result on machine with 8 cores and NVMe card
INTEL SSDPEKKR128G7
fio size=256m ioengine=libaio iodepth=64 direct=1 numjobs=8
seq/random
+------+---------------------------------------------------------------+
|patch?| bw(MB/s) | iops | slat(usec) | clat(usec) | merge |
+----------------------------------------------------------------------+
| w/o | 606/612 | 151k/153k | 6.89/7.03 | 3349.21/3305.40 | 0/0 |
+----------------------------------------------------------------------+
| w/ | 1083/616 | 277k/154k | 4.93/6.95 | 1830.62/3279.95 | 223k/3k |
+----------------------------------------------------------------------+
When set numjobs to 16, the bw and iops could reach 1662MB/s and 425k
on my platform.
Signed-off-by: Jianchao Wang <jianchao.w.wang@oracle.com>
Tested-by: Holger Hoffstätte <holger@applied-asynchrony.com>
Reviewed-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2018-05-30 19:47:40 +03:00
|
|
|
struct blk_mq_hw_ctx *hctx)
|
2017-04-14 11:00:02 +03:00
|
|
|
{
|
|
|
|
struct list_head *rqs;
|
|
|
|
struct request *rq;
|
|
|
|
int nr;
|
|
|
|
|
|
|
|
rqs = &khd->rqs[khd->cur_domain];
|
|
|
|
|
|
|
|
/*
|
block: kyber: make kyber more friendly with merging
Currently, kyber is very unfriendly with merging. kyber depends
on ctx rq_list to do merging, however, most of time, it will not
leave any requests in ctx rq_list. This is because even if tokens
of one domain is used up, kyber will try to dispatch requests
from other domain and flush the rq_list there.
To improve this, we setup kyber_ctx_queue (kcq) which is similar
with ctx, but it has rq_lists for different domain and build same
mapping between kcq and khd as the ctx & hctx. Then we could merge,
insert and dispatch for different domains separately. At the same
time, only flush the rq_list of kcq when get domain token successfully.
Then if one domain token is used up, the requests could be left in
the rq_list of that domain and maybe merged with following io.
Following is my test result on machine with 8 cores and NVMe card
INTEL SSDPEKKR128G7
fio size=256m ioengine=libaio iodepth=64 direct=1 numjobs=8
seq/random
+------+---------------------------------------------------------------+
|patch?| bw(MB/s) | iops | slat(usec) | clat(usec) | merge |
+----------------------------------------------------------------------+
| w/o | 606/612 | 151k/153k | 6.89/7.03 | 3349.21/3305.40 | 0/0 |
+----------------------------------------------------------------------+
| w/ | 1083/616 | 277k/154k | 4.93/6.95 | 1830.62/3279.95 | 223k/3k |
+----------------------------------------------------------------------+
When set numjobs to 16, the bw and iops could reach 1662MB/s and 425k
on my platform.
Signed-off-by: Jianchao Wang <jianchao.w.wang@oracle.com>
Tested-by: Holger Hoffstätte <holger@applied-asynchrony.com>
Reviewed-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2018-05-30 19:47:40 +03:00
|
|
|
* If we already have a flushed request, then we just need to get a
|
|
|
|
* token for it. Otherwise, if there are pending requests in the kcqs,
|
|
|
|
* flush the kcqs, but only if we can get a token. If not, we should
|
|
|
|
* leave the requests in the kcqs so that they can be merged. Note that
|
|
|
|
* khd->lock serializes the flushes, so if we observed any bit set in
|
|
|
|
* the kcq_map, we will always get a request.
|
2017-04-14 11:00:02 +03:00
|
|
|
*/
|
block: kyber: make kyber more friendly with merging
Currently, kyber is very unfriendly with merging. kyber depends
on ctx rq_list to do merging, however, most of time, it will not
leave any requests in ctx rq_list. This is because even if tokens
of one domain is used up, kyber will try to dispatch requests
from other domain and flush the rq_list there.
To improve this, we setup kyber_ctx_queue (kcq) which is similar
with ctx, but it has rq_lists for different domain and build same
mapping between kcq and khd as the ctx & hctx. Then we could merge,
insert and dispatch for different domains separately. At the same
time, only flush the rq_list of kcq when get domain token successfully.
Then if one domain token is used up, the requests could be left in
the rq_list of that domain and maybe merged with following io.
Following is my test result on machine with 8 cores and NVMe card
INTEL SSDPEKKR128G7
fio size=256m ioengine=libaio iodepth=64 direct=1 numjobs=8
seq/random
+------+---------------------------------------------------------------+
|patch?| bw(MB/s) | iops | slat(usec) | clat(usec) | merge |
+----------------------------------------------------------------------+
| w/o | 606/612 | 151k/153k | 6.89/7.03 | 3349.21/3305.40 | 0/0 |
+----------------------------------------------------------------------+
| w/ | 1083/616 | 277k/154k | 4.93/6.95 | 1830.62/3279.95 | 223k/3k |
+----------------------------------------------------------------------+
When set numjobs to 16, the bw and iops could reach 1662MB/s and 425k
on my platform.
Signed-off-by: Jianchao Wang <jianchao.w.wang@oracle.com>
Tested-by: Holger Hoffstätte <holger@applied-asynchrony.com>
Reviewed-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2018-05-30 19:47:40 +03:00
|
|
|
rq = list_first_entry_or_null(rqs, struct request, queuelist);
|
2017-04-14 11:00:02 +03:00
|
|
|
if (rq) {
|
|
|
|
nr = kyber_get_domain_token(kqd, khd, hctx);
|
|
|
|
if (nr >= 0) {
|
|
|
|
khd->batching++;
|
|
|
|
rq_set_domain_token(rq, nr);
|
|
|
|
list_del_init(&rq->queuelist);
|
|
|
|
return rq;
|
2018-09-28 01:55:55 +03:00
|
|
|
} else {
|
2021-10-12 12:33:01 +03:00
|
|
|
trace_kyber_throttled(kqd->dev,
|
2018-09-28 01:55:55 +03:00
|
|
|
kyber_domain_names[khd->cur_domain]);
|
2017-04-14 11:00:02 +03:00
|
|
|
}
|
block: kyber: make kyber more friendly with merging
Currently, kyber is very unfriendly with merging. kyber depends
on ctx rq_list to do merging, however, most of time, it will not
leave any requests in ctx rq_list. This is because even if tokens
of one domain is used up, kyber will try to dispatch requests
from other domain and flush the rq_list there.
To improve this, we setup kyber_ctx_queue (kcq) which is similar
with ctx, but it has rq_lists for different domain and build same
mapping between kcq and khd as the ctx & hctx. Then we could merge,
insert and dispatch for different domains separately. At the same
time, only flush the rq_list of kcq when get domain token successfully.
Then if one domain token is used up, the requests could be left in
the rq_list of that domain and maybe merged with following io.
Following is my test result on machine with 8 cores and NVMe card
INTEL SSDPEKKR128G7
fio size=256m ioengine=libaio iodepth=64 direct=1 numjobs=8
seq/random
+------+---------------------------------------------------------------+
|patch?| bw(MB/s) | iops | slat(usec) | clat(usec) | merge |
+----------------------------------------------------------------------+
| w/o | 606/612 | 151k/153k | 6.89/7.03 | 3349.21/3305.40 | 0/0 |
+----------------------------------------------------------------------+
| w/ | 1083/616 | 277k/154k | 4.93/6.95 | 1830.62/3279.95 | 223k/3k |
+----------------------------------------------------------------------+
When set numjobs to 16, the bw and iops could reach 1662MB/s and 425k
on my platform.
Signed-off-by: Jianchao Wang <jianchao.w.wang@oracle.com>
Tested-by: Holger Hoffstätte <holger@applied-asynchrony.com>
Reviewed-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2018-05-30 19:47:40 +03:00
|
|
|
} else if (sbitmap_any_bit_set(&khd->kcq_map[khd->cur_domain])) {
|
|
|
|
nr = kyber_get_domain_token(kqd, khd, hctx);
|
|
|
|
if (nr >= 0) {
|
|
|
|
kyber_flush_busy_kcqs(khd, khd->cur_domain, rqs);
|
|
|
|
rq = list_first_entry(rqs, struct request, queuelist);
|
|
|
|
khd->batching++;
|
|
|
|
rq_set_domain_token(rq, nr);
|
|
|
|
list_del_init(&rq->queuelist);
|
|
|
|
return rq;
|
2018-09-28 01:55:55 +03:00
|
|
|
} else {
|
2021-10-12 12:33:01 +03:00
|
|
|
trace_kyber_throttled(kqd->dev,
|
2018-09-28 01:55:55 +03:00
|
|
|
kyber_domain_names[khd->cur_domain]);
|
block: kyber: make kyber more friendly with merging
Currently, kyber is very unfriendly with merging. kyber depends
on ctx rq_list to do merging, however, most of time, it will not
leave any requests in ctx rq_list. This is because even if tokens
of one domain is used up, kyber will try to dispatch requests
from other domain and flush the rq_list there.
To improve this, we setup kyber_ctx_queue (kcq) which is similar
with ctx, but it has rq_lists for different domain and build same
mapping between kcq and khd as the ctx & hctx. Then we could merge,
insert and dispatch for different domains separately. At the same
time, only flush the rq_list of kcq when get domain token successfully.
Then if one domain token is used up, the requests could be left in
the rq_list of that domain and maybe merged with following io.
Following is my test result on machine with 8 cores and NVMe card
INTEL SSDPEKKR128G7
fio size=256m ioengine=libaio iodepth=64 direct=1 numjobs=8
seq/random
+------+---------------------------------------------------------------+
|patch?| bw(MB/s) | iops | slat(usec) | clat(usec) | merge |
+----------------------------------------------------------------------+
| w/o | 606/612 | 151k/153k | 6.89/7.03 | 3349.21/3305.40 | 0/0 |
+----------------------------------------------------------------------+
| w/ | 1083/616 | 277k/154k | 4.93/6.95 | 1830.62/3279.95 | 223k/3k |
+----------------------------------------------------------------------+
When set numjobs to 16, the bw and iops could reach 1662MB/s and 425k
on my platform.
Signed-off-by: Jianchao Wang <jianchao.w.wang@oracle.com>
Tested-by: Holger Hoffstätte <holger@applied-asynchrony.com>
Reviewed-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2018-05-30 19:47:40 +03:00
|
|
|
}
|
2017-04-14 11:00:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* There were either no pending requests or no tokens. */
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct request *kyber_dispatch_request(struct blk_mq_hw_ctx *hctx)
|
|
|
|
{
|
|
|
|
struct kyber_queue_data *kqd = hctx->queue->elevator->elevator_data;
|
|
|
|
struct kyber_hctx_data *khd = hctx->sched_data;
|
|
|
|
struct request *rq;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
spin_lock(&khd->lock);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* First, if we are still entitled to batch, try to dispatch a request
|
|
|
|
* from the batch.
|
|
|
|
*/
|
|
|
|
if (khd->batching < kyber_batch_size[khd->cur_domain]) {
|
block: kyber: make kyber more friendly with merging
Currently, kyber is very unfriendly with merging. kyber depends
on ctx rq_list to do merging, however, most of time, it will not
leave any requests in ctx rq_list. This is because even if tokens
of one domain is used up, kyber will try to dispatch requests
from other domain and flush the rq_list there.
To improve this, we setup kyber_ctx_queue (kcq) which is similar
with ctx, but it has rq_lists for different domain and build same
mapping between kcq and khd as the ctx & hctx. Then we could merge,
insert and dispatch for different domains separately. At the same
time, only flush the rq_list of kcq when get domain token successfully.
Then if one domain token is used up, the requests could be left in
the rq_list of that domain and maybe merged with following io.
Following is my test result on machine with 8 cores and NVMe card
INTEL SSDPEKKR128G7
fio size=256m ioengine=libaio iodepth=64 direct=1 numjobs=8
seq/random
+------+---------------------------------------------------------------+
|patch?| bw(MB/s) | iops | slat(usec) | clat(usec) | merge |
+----------------------------------------------------------------------+
| w/o | 606/612 | 151k/153k | 6.89/7.03 | 3349.21/3305.40 | 0/0 |
+----------------------------------------------------------------------+
| w/ | 1083/616 | 277k/154k | 4.93/6.95 | 1830.62/3279.95 | 223k/3k |
+----------------------------------------------------------------------+
When set numjobs to 16, the bw and iops could reach 1662MB/s and 425k
on my platform.
Signed-off-by: Jianchao Wang <jianchao.w.wang@oracle.com>
Tested-by: Holger Hoffstätte <holger@applied-asynchrony.com>
Reviewed-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2018-05-30 19:47:40 +03:00
|
|
|
rq = kyber_dispatch_cur_domain(kqd, khd, hctx);
|
2017-04-14 11:00:02 +03:00
|
|
|
if (rq)
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Either,
|
|
|
|
* 1. We were no longer entitled to a batch.
|
|
|
|
* 2. The domain we were batching didn't have any requests.
|
|
|
|
* 3. The domain we were batching was out of tokens.
|
|
|
|
*
|
|
|
|
* Start another batch. Note that this wraps back around to the original
|
|
|
|
* domain if no other domains have requests or tokens.
|
|
|
|
*/
|
|
|
|
khd->batching = 0;
|
|
|
|
for (i = 0; i < KYBER_NUM_DOMAINS; i++) {
|
|
|
|
if (khd->cur_domain == KYBER_NUM_DOMAINS - 1)
|
|
|
|
khd->cur_domain = 0;
|
|
|
|
else
|
|
|
|
khd->cur_domain++;
|
|
|
|
|
block: kyber: make kyber more friendly with merging
Currently, kyber is very unfriendly with merging. kyber depends
on ctx rq_list to do merging, however, most of time, it will not
leave any requests in ctx rq_list. This is because even if tokens
of one domain is used up, kyber will try to dispatch requests
from other domain and flush the rq_list there.
To improve this, we setup kyber_ctx_queue (kcq) which is similar
with ctx, but it has rq_lists for different domain and build same
mapping between kcq and khd as the ctx & hctx. Then we could merge,
insert and dispatch for different domains separately. At the same
time, only flush the rq_list of kcq when get domain token successfully.
Then if one domain token is used up, the requests could be left in
the rq_list of that domain and maybe merged with following io.
Following is my test result on machine with 8 cores and NVMe card
INTEL SSDPEKKR128G7
fio size=256m ioengine=libaio iodepth=64 direct=1 numjobs=8
seq/random
+------+---------------------------------------------------------------+
|patch?| bw(MB/s) | iops | slat(usec) | clat(usec) | merge |
+----------------------------------------------------------------------+
| w/o | 606/612 | 151k/153k | 6.89/7.03 | 3349.21/3305.40 | 0/0 |
+----------------------------------------------------------------------+
| w/ | 1083/616 | 277k/154k | 4.93/6.95 | 1830.62/3279.95 | 223k/3k |
+----------------------------------------------------------------------+
When set numjobs to 16, the bw and iops could reach 1662MB/s and 425k
on my platform.
Signed-off-by: Jianchao Wang <jianchao.w.wang@oracle.com>
Tested-by: Holger Hoffstätte <holger@applied-asynchrony.com>
Reviewed-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2018-05-30 19:47:40 +03:00
|
|
|
rq = kyber_dispatch_cur_domain(kqd, khd, hctx);
|
2017-04-14 11:00:02 +03:00
|
|
|
if (rq)
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
rq = NULL;
|
|
|
|
out:
|
|
|
|
spin_unlock(&khd->lock);
|
|
|
|
return rq;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool kyber_has_work(struct blk_mq_hw_ctx *hctx)
|
|
|
|
{
|
|
|
|
struct kyber_hctx_data *khd = hctx->sched_data;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < KYBER_NUM_DOMAINS; i++) {
|
block: kyber: make kyber more friendly with merging
Currently, kyber is very unfriendly with merging. kyber depends
on ctx rq_list to do merging, however, most of time, it will not
leave any requests in ctx rq_list. This is because even if tokens
of one domain is used up, kyber will try to dispatch requests
from other domain and flush the rq_list there.
To improve this, we setup kyber_ctx_queue (kcq) which is similar
with ctx, but it has rq_lists for different domain and build same
mapping between kcq and khd as the ctx & hctx. Then we could merge,
insert and dispatch for different domains separately. At the same
time, only flush the rq_list of kcq when get domain token successfully.
Then if one domain token is used up, the requests could be left in
the rq_list of that domain and maybe merged with following io.
Following is my test result on machine with 8 cores and NVMe card
INTEL SSDPEKKR128G7
fio size=256m ioengine=libaio iodepth=64 direct=1 numjobs=8
seq/random
+------+---------------------------------------------------------------+
|patch?| bw(MB/s) | iops | slat(usec) | clat(usec) | merge |
+----------------------------------------------------------------------+
| w/o | 606/612 | 151k/153k | 6.89/7.03 | 3349.21/3305.40 | 0/0 |
+----------------------------------------------------------------------+
| w/ | 1083/616 | 277k/154k | 4.93/6.95 | 1830.62/3279.95 | 223k/3k |
+----------------------------------------------------------------------+
When set numjobs to 16, the bw and iops could reach 1662MB/s and 425k
on my platform.
Signed-off-by: Jianchao Wang <jianchao.w.wang@oracle.com>
Tested-by: Holger Hoffstätte <holger@applied-asynchrony.com>
Reviewed-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2018-05-30 19:47:40 +03:00
|
|
|
if (!list_empty_careful(&khd->rqs[i]) ||
|
|
|
|
sbitmap_any_bit_set(&khd->kcq_map[i]))
|
2017-04-14 11:00:02 +03:00
|
|
|
return true;
|
|
|
|
}
|
block: kyber: make kyber more friendly with merging
Currently, kyber is very unfriendly with merging. kyber depends
on ctx rq_list to do merging, however, most of time, it will not
leave any requests in ctx rq_list. This is because even if tokens
of one domain is used up, kyber will try to dispatch requests
from other domain and flush the rq_list there.
To improve this, we setup kyber_ctx_queue (kcq) which is similar
with ctx, but it has rq_lists for different domain and build same
mapping between kcq and khd as the ctx & hctx. Then we could merge,
insert and dispatch for different domains separately. At the same
time, only flush the rq_list of kcq when get domain token successfully.
Then if one domain token is used up, the requests could be left in
the rq_list of that domain and maybe merged with following io.
Following is my test result on machine with 8 cores and NVMe card
INTEL SSDPEKKR128G7
fio size=256m ioengine=libaio iodepth=64 direct=1 numjobs=8
seq/random
+------+---------------------------------------------------------------+
|patch?| bw(MB/s) | iops | slat(usec) | clat(usec) | merge |
+----------------------------------------------------------------------+
| w/o | 606/612 | 151k/153k | 6.89/7.03 | 3349.21/3305.40 | 0/0 |
+----------------------------------------------------------------------+
| w/ | 1083/616 | 277k/154k | 4.93/6.95 | 1830.62/3279.95 | 223k/3k |
+----------------------------------------------------------------------+
When set numjobs to 16, the bw and iops could reach 1662MB/s and 425k
on my platform.
Signed-off-by: Jianchao Wang <jianchao.w.wang@oracle.com>
Tested-by: Holger Hoffstätte <holger@applied-asynchrony.com>
Reviewed-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2018-05-30 19:47:40 +03:00
|
|
|
|
|
|
|
return false;
|
2017-04-14 11:00:02 +03:00
|
|
|
}
|
|
|
|
|
kyber: implement improved heuristics
Kyber's current heuristics have a few flaws:
- It's based on the mean latency, but p99 latency tends to be more
meaningful to anyone who cares about latency. The mean can also be
skewed by rare outliers that the scheduler can't do anything about.
- The statistics calculations are purely time-based with a short window.
This works for steady, high load, but is more sensitive to outliers
with bursty workloads.
- It only considers the latency once an I/O has been submitted to the
device, but the user cares about the time spent in the kernel, as
well.
These are shortcomings of the generic blk-stat code which doesn't quite
fit the ideal use case for Kyber. So, this replaces the statistics with
a histogram used to calculate percentiles of total latency and I/O
latency, which we then use to adjust depths in a slightly more
intelligent manner:
- Sync and async writes are now the same domain.
- Discards are a separate domain.
- Domain queue depths are scaled by the ratio of the p99 total latency
to the target latency (e.g., if the p99 latency is double the target
latency, we will double the queue depth; if the p99 latency is half of
the target latency, we can halve the queue depth).
- We use the I/O latency to determine whether we should scale queue
depths down: we will only scale down if any domain's I/O latency
exceeds the target latency, which is an indicator of congestion in the
device.
These new heuristics are just as scalable as the heuristics they
replace.
Signed-off-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2018-09-28 01:55:54 +03:00
|
|
|
#define KYBER_LAT_SHOW_STORE(domain, name) \
|
|
|
|
static ssize_t kyber_##name##_lat_show(struct elevator_queue *e, \
|
|
|
|
char *page) \
|
2017-04-14 11:00:02 +03:00
|
|
|
{ \
|
|
|
|
struct kyber_queue_data *kqd = e->elevator_data; \
|
|
|
|
\
|
kyber: implement improved heuristics
Kyber's current heuristics have a few flaws:
- It's based on the mean latency, but p99 latency tends to be more
meaningful to anyone who cares about latency. The mean can also be
skewed by rare outliers that the scheduler can't do anything about.
- The statistics calculations are purely time-based with a short window.
This works for steady, high load, but is more sensitive to outliers
with bursty workloads.
- It only considers the latency once an I/O has been submitted to the
device, but the user cares about the time spent in the kernel, as
well.
These are shortcomings of the generic blk-stat code which doesn't quite
fit the ideal use case for Kyber. So, this replaces the statistics with
a histogram used to calculate percentiles of total latency and I/O
latency, which we then use to adjust depths in a slightly more
intelligent manner:
- Sync and async writes are now the same domain.
- Discards are a separate domain.
- Domain queue depths are scaled by the ratio of the p99 total latency
to the target latency (e.g., if the p99 latency is double the target
latency, we will double the queue depth; if the p99 latency is half of
the target latency, we can halve the queue depth).
- We use the I/O latency to determine whether we should scale queue
depths down: we will only scale down if any domain's I/O latency
exceeds the target latency, which is an indicator of congestion in the
device.
These new heuristics are just as scalable as the heuristics they
replace.
Signed-off-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2018-09-28 01:55:54 +03:00
|
|
|
return sprintf(page, "%llu\n", kqd->latency_targets[domain]); \
|
2017-04-14 11:00:02 +03:00
|
|
|
} \
|
|
|
|
\
|
kyber: implement improved heuristics
Kyber's current heuristics have a few flaws:
- It's based on the mean latency, but p99 latency tends to be more
meaningful to anyone who cares about latency. The mean can also be
skewed by rare outliers that the scheduler can't do anything about.
- The statistics calculations are purely time-based with a short window.
This works for steady, high load, but is more sensitive to outliers
with bursty workloads.
- It only considers the latency once an I/O has been submitted to the
device, but the user cares about the time spent in the kernel, as
well.
These are shortcomings of the generic blk-stat code which doesn't quite
fit the ideal use case for Kyber. So, this replaces the statistics with
a histogram used to calculate percentiles of total latency and I/O
latency, which we then use to adjust depths in a slightly more
intelligent manner:
- Sync and async writes are now the same domain.
- Discards are a separate domain.
- Domain queue depths are scaled by the ratio of the p99 total latency
to the target latency (e.g., if the p99 latency is double the target
latency, we will double the queue depth; if the p99 latency is half of
the target latency, we can halve the queue depth).
- We use the I/O latency to determine whether we should scale queue
depths down: we will only scale down if any domain's I/O latency
exceeds the target latency, which is an indicator of congestion in the
device.
These new heuristics are just as scalable as the heuristics they
replace.
Signed-off-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2018-09-28 01:55:54 +03:00
|
|
|
static ssize_t kyber_##name##_lat_store(struct elevator_queue *e, \
|
|
|
|
const char *page, size_t count) \
|
2017-04-14 11:00:02 +03:00
|
|
|
{ \
|
|
|
|
struct kyber_queue_data *kqd = e->elevator_data; \
|
|
|
|
unsigned long long nsec; \
|
|
|
|
int ret; \
|
|
|
|
\
|
|
|
|
ret = kstrtoull(page, 10, &nsec); \
|
|
|
|
if (ret) \
|
|
|
|
return ret; \
|
|
|
|
\
|
kyber: implement improved heuristics
Kyber's current heuristics have a few flaws:
- It's based on the mean latency, but p99 latency tends to be more
meaningful to anyone who cares about latency. The mean can also be
skewed by rare outliers that the scheduler can't do anything about.
- The statistics calculations are purely time-based with a short window.
This works for steady, high load, but is more sensitive to outliers
with bursty workloads.
- It only considers the latency once an I/O has been submitted to the
device, but the user cares about the time spent in the kernel, as
well.
These are shortcomings of the generic blk-stat code which doesn't quite
fit the ideal use case for Kyber. So, this replaces the statistics with
a histogram used to calculate percentiles of total latency and I/O
latency, which we then use to adjust depths in a slightly more
intelligent manner:
- Sync and async writes are now the same domain.
- Discards are a separate domain.
- Domain queue depths are scaled by the ratio of the p99 total latency
to the target latency (e.g., if the p99 latency is double the target
latency, we will double the queue depth; if the p99 latency is half of
the target latency, we can halve the queue depth).
- We use the I/O latency to determine whether we should scale queue
depths down: we will only scale down if any domain's I/O latency
exceeds the target latency, which is an indicator of congestion in the
device.
These new heuristics are just as scalable as the heuristics they
replace.
Signed-off-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2018-09-28 01:55:54 +03:00
|
|
|
kqd->latency_targets[domain] = nsec; \
|
2017-04-14 11:00:02 +03:00
|
|
|
\
|
|
|
|
return count; \
|
|
|
|
}
|
kyber: implement improved heuristics
Kyber's current heuristics have a few flaws:
- It's based on the mean latency, but p99 latency tends to be more
meaningful to anyone who cares about latency. The mean can also be
skewed by rare outliers that the scheduler can't do anything about.
- The statistics calculations are purely time-based with a short window.
This works for steady, high load, but is more sensitive to outliers
with bursty workloads.
- It only considers the latency once an I/O has been submitted to the
device, but the user cares about the time spent in the kernel, as
well.
These are shortcomings of the generic blk-stat code which doesn't quite
fit the ideal use case for Kyber. So, this replaces the statistics with
a histogram used to calculate percentiles of total latency and I/O
latency, which we then use to adjust depths in a slightly more
intelligent manner:
- Sync and async writes are now the same domain.
- Discards are a separate domain.
- Domain queue depths are scaled by the ratio of the p99 total latency
to the target latency (e.g., if the p99 latency is double the target
latency, we will double the queue depth; if the p99 latency is half of
the target latency, we can halve the queue depth).
- We use the I/O latency to determine whether we should scale queue
depths down: we will only scale down if any domain's I/O latency
exceeds the target latency, which is an indicator of congestion in the
device.
These new heuristics are just as scalable as the heuristics they
replace.
Signed-off-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2018-09-28 01:55:54 +03:00
|
|
|
KYBER_LAT_SHOW_STORE(KYBER_READ, read);
|
|
|
|
KYBER_LAT_SHOW_STORE(KYBER_WRITE, write);
|
2017-04-14 11:00:02 +03:00
|
|
|
#undef KYBER_LAT_SHOW_STORE
|
|
|
|
|
|
|
|
#define KYBER_LAT_ATTR(op) __ATTR(op##_lat_nsec, 0644, kyber_##op##_lat_show, kyber_##op##_lat_store)
|
|
|
|
static struct elv_fs_entry kyber_sched_attrs[] = {
|
|
|
|
KYBER_LAT_ATTR(read),
|
|
|
|
KYBER_LAT_ATTR(write),
|
|
|
|
__ATTR_NULL
|
|
|
|
};
|
|
|
|
#undef KYBER_LAT_ATTR
|
|
|
|
|
2017-05-04 10:31:33 +03:00
|
|
|
#ifdef CONFIG_BLK_DEBUG_FS
|
|
|
|
#define KYBER_DEBUGFS_DOMAIN_ATTRS(domain, name) \
|
|
|
|
static int kyber_##name##_tokens_show(void *data, struct seq_file *m) \
|
|
|
|
{ \
|
|
|
|
struct request_queue *q = data; \
|
|
|
|
struct kyber_queue_data *kqd = q->elevator->elevator_data; \
|
|
|
|
\
|
|
|
|
sbitmap_queue_show(&kqd->domain_tokens[domain], m); \
|
|
|
|
return 0; \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
static void *kyber_##name##_rqs_start(struct seq_file *m, loff_t *pos) \
|
|
|
|
__acquires(&khd->lock) \
|
|
|
|
{ \
|
|
|
|
struct blk_mq_hw_ctx *hctx = m->private; \
|
|
|
|
struct kyber_hctx_data *khd = hctx->sched_data; \
|
|
|
|
\
|
|
|
|
spin_lock(&khd->lock); \
|
|
|
|
return seq_list_start(&khd->rqs[domain], *pos); \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
static void *kyber_##name##_rqs_next(struct seq_file *m, void *v, \
|
|
|
|
loff_t *pos) \
|
|
|
|
{ \
|
|
|
|
struct blk_mq_hw_ctx *hctx = m->private; \
|
|
|
|
struct kyber_hctx_data *khd = hctx->sched_data; \
|
|
|
|
\
|
|
|
|
return seq_list_next(v, &khd->rqs[domain], pos); \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
static void kyber_##name##_rqs_stop(struct seq_file *m, void *v) \
|
|
|
|
__releases(&khd->lock) \
|
|
|
|
{ \
|
|
|
|
struct blk_mq_hw_ctx *hctx = m->private; \
|
|
|
|
struct kyber_hctx_data *khd = hctx->sched_data; \
|
|
|
|
\
|
|
|
|
spin_unlock(&khd->lock); \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
static const struct seq_operations kyber_##name##_rqs_seq_ops = { \
|
|
|
|
.start = kyber_##name##_rqs_start, \
|
|
|
|
.next = kyber_##name##_rqs_next, \
|
|
|
|
.stop = kyber_##name##_rqs_stop, \
|
|
|
|
.show = blk_mq_debugfs_rq_show, \
|
|
|
|
}; \
|
|
|
|
\
|
|
|
|
static int kyber_##name##_waiting_show(void *data, struct seq_file *m) \
|
|
|
|
{ \
|
|
|
|
struct blk_mq_hw_ctx *hctx = data; \
|
|
|
|
struct kyber_hctx_data *khd = hctx->sched_data; \
|
2018-12-20 18:50:58 +03:00
|
|
|
wait_queue_entry_t *wait = &khd->domain_wait[domain].wait; \
|
2017-05-04 10:31:33 +03:00
|
|
|
\
|
sched/wait: Disambiguate wq_entry->task_list and wq_head->task_list naming
So I've noticed a number of instances where it was not obvious from the
code whether ->task_list was for a wait-queue head or a wait-queue entry.
Furthermore, there's a number of wait-queue users where the lists are
not for 'tasks' but other entities (poll tables, etc.), in which case
the 'task_list' name is actively confusing.
To clear this all up, name the wait-queue head and entry list structure
fields unambiguously:
struct wait_queue_head::task_list => ::head
struct wait_queue_entry::task_list => ::entry
For example, this code:
rqw->wait.task_list.next != &wait->task_list
... is was pretty unclear (to me) what it's doing, while now it's written this way:
rqw->wait.head.next != &wait->entry
... which makes it pretty clear that we are iterating a list until we see the head.
Other examples are:
list_for_each_entry_safe(pos, next, &x->task_list, task_list) {
list_for_each_entry(wq, &fence->wait.task_list, task_list) {
... where it's unclear (to me) what we are iterating, and during review it's
hard to tell whether it's trying to walk a wait-queue entry (which would be
a bug), while now it's written as:
list_for_each_entry_safe(pos, next, &x->head, entry) {
list_for_each_entry(wq, &fence->wait.head, entry) {
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2017-06-20 13:06:46 +03:00
|
|
|
seq_printf(m, "%d\n", !list_empty_careful(&wait->entry)); \
|
2017-05-04 10:31:33 +03:00
|
|
|
return 0; \
|
|
|
|
}
|
|
|
|
KYBER_DEBUGFS_DOMAIN_ATTRS(KYBER_READ, read)
|
kyber: implement improved heuristics
Kyber's current heuristics have a few flaws:
- It's based on the mean latency, but p99 latency tends to be more
meaningful to anyone who cares about latency. The mean can also be
skewed by rare outliers that the scheduler can't do anything about.
- The statistics calculations are purely time-based with a short window.
This works for steady, high load, but is more sensitive to outliers
with bursty workloads.
- It only considers the latency once an I/O has been submitted to the
device, but the user cares about the time spent in the kernel, as
well.
These are shortcomings of the generic blk-stat code which doesn't quite
fit the ideal use case for Kyber. So, this replaces the statistics with
a histogram used to calculate percentiles of total latency and I/O
latency, which we then use to adjust depths in a slightly more
intelligent manner:
- Sync and async writes are now the same domain.
- Discards are a separate domain.
- Domain queue depths are scaled by the ratio of the p99 total latency
to the target latency (e.g., if the p99 latency is double the target
latency, we will double the queue depth; if the p99 latency is half of
the target latency, we can halve the queue depth).
- We use the I/O latency to determine whether we should scale queue
depths down: we will only scale down if any domain's I/O latency
exceeds the target latency, which is an indicator of congestion in the
device.
These new heuristics are just as scalable as the heuristics they
replace.
Signed-off-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2018-09-28 01:55:54 +03:00
|
|
|
KYBER_DEBUGFS_DOMAIN_ATTRS(KYBER_WRITE, write)
|
|
|
|
KYBER_DEBUGFS_DOMAIN_ATTRS(KYBER_DISCARD, discard)
|
2017-05-04 10:31:33 +03:00
|
|
|
KYBER_DEBUGFS_DOMAIN_ATTRS(KYBER_OTHER, other)
|
|
|
|
#undef KYBER_DEBUGFS_DOMAIN_ATTRS
|
|
|
|
|
|
|
|
static int kyber_async_depth_show(void *data, struct seq_file *m)
|
|
|
|
{
|
|
|
|
struct request_queue *q = data;
|
|
|
|
struct kyber_queue_data *kqd = q->elevator->elevator_data;
|
|
|
|
|
|
|
|
seq_printf(m, "%u\n", kqd->async_depth);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int kyber_cur_domain_show(void *data, struct seq_file *m)
|
|
|
|
{
|
|
|
|
struct blk_mq_hw_ctx *hctx = data;
|
|
|
|
struct kyber_hctx_data *khd = hctx->sched_data;
|
|
|
|
|
2018-09-28 01:55:55 +03:00
|
|
|
seq_printf(m, "%s\n", kyber_domain_names[khd->cur_domain]);
|
2017-05-04 10:31:33 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int kyber_batching_show(void *data, struct seq_file *m)
|
|
|
|
{
|
|
|
|
struct blk_mq_hw_ctx *hctx = data;
|
|
|
|
struct kyber_hctx_data *khd = hctx->sched_data;
|
|
|
|
|
|
|
|
seq_printf(m, "%u\n", khd->batching);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define KYBER_QUEUE_DOMAIN_ATTRS(name) \
|
|
|
|
{#name "_tokens", 0400, kyber_##name##_tokens_show}
|
|
|
|
static const struct blk_mq_debugfs_attr kyber_queue_debugfs_attrs[] = {
|
|
|
|
KYBER_QUEUE_DOMAIN_ATTRS(read),
|
kyber: implement improved heuristics
Kyber's current heuristics have a few flaws:
- It's based on the mean latency, but p99 latency tends to be more
meaningful to anyone who cares about latency. The mean can also be
skewed by rare outliers that the scheduler can't do anything about.
- The statistics calculations are purely time-based with a short window.
This works for steady, high load, but is more sensitive to outliers
with bursty workloads.
- It only considers the latency once an I/O has been submitted to the
device, but the user cares about the time spent in the kernel, as
well.
These are shortcomings of the generic blk-stat code which doesn't quite
fit the ideal use case for Kyber. So, this replaces the statistics with
a histogram used to calculate percentiles of total latency and I/O
latency, which we then use to adjust depths in a slightly more
intelligent manner:
- Sync and async writes are now the same domain.
- Discards are a separate domain.
- Domain queue depths are scaled by the ratio of the p99 total latency
to the target latency (e.g., if the p99 latency is double the target
latency, we will double the queue depth; if the p99 latency is half of
the target latency, we can halve the queue depth).
- We use the I/O latency to determine whether we should scale queue
depths down: we will only scale down if any domain's I/O latency
exceeds the target latency, which is an indicator of congestion in the
device.
These new heuristics are just as scalable as the heuristics they
replace.
Signed-off-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2018-09-28 01:55:54 +03:00
|
|
|
KYBER_QUEUE_DOMAIN_ATTRS(write),
|
|
|
|
KYBER_QUEUE_DOMAIN_ATTRS(discard),
|
2017-05-04 10:31:33 +03:00
|
|
|
KYBER_QUEUE_DOMAIN_ATTRS(other),
|
|
|
|
{"async_depth", 0400, kyber_async_depth_show},
|
|
|
|
{},
|
|
|
|
};
|
|
|
|
#undef KYBER_QUEUE_DOMAIN_ATTRS
|
|
|
|
|
|
|
|
#define KYBER_HCTX_DOMAIN_ATTRS(name) \
|
|
|
|
{#name "_rqs", 0400, .seq_ops = &kyber_##name##_rqs_seq_ops}, \
|
|
|
|
{#name "_waiting", 0400, kyber_##name##_waiting_show}
|
|
|
|
static const struct blk_mq_debugfs_attr kyber_hctx_debugfs_attrs[] = {
|
|
|
|
KYBER_HCTX_DOMAIN_ATTRS(read),
|
kyber: implement improved heuristics
Kyber's current heuristics have a few flaws:
- It's based on the mean latency, but p99 latency tends to be more
meaningful to anyone who cares about latency. The mean can also be
skewed by rare outliers that the scheduler can't do anything about.
- The statistics calculations are purely time-based with a short window.
This works for steady, high load, but is more sensitive to outliers
with bursty workloads.
- It only considers the latency once an I/O has been submitted to the
device, but the user cares about the time spent in the kernel, as
well.
These are shortcomings of the generic blk-stat code which doesn't quite
fit the ideal use case for Kyber. So, this replaces the statistics with
a histogram used to calculate percentiles of total latency and I/O
latency, which we then use to adjust depths in a slightly more
intelligent manner:
- Sync and async writes are now the same domain.
- Discards are a separate domain.
- Domain queue depths are scaled by the ratio of the p99 total latency
to the target latency (e.g., if the p99 latency is double the target
latency, we will double the queue depth; if the p99 latency is half of
the target latency, we can halve the queue depth).
- We use the I/O latency to determine whether we should scale queue
depths down: we will only scale down if any domain's I/O latency
exceeds the target latency, which is an indicator of congestion in the
device.
These new heuristics are just as scalable as the heuristics they
replace.
Signed-off-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2018-09-28 01:55:54 +03:00
|
|
|
KYBER_HCTX_DOMAIN_ATTRS(write),
|
|
|
|
KYBER_HCTX_DOMAIN_ATTRS(discard),
|
2017-05-04 10:31:33 +03:00
|
|
|
KYBER_HCTX_DOMAIN_ATTRS(other),
|
|
|
|
{"cur_domain", 0400, kyber_cur_domain_show},
|
|
|
|
{"batching", 0400, kyber_batching_show},
|
|
|
|
{},
|
|
|
|
};
|
|
|
|
#undef KYBER_HCTX_DOMAIN_ATTRS
|
|
|
|
#endif
|
|
|
|
|
2017-04-14 11:00:02 +03:00
|
|
|
static struct elevator_type kyber_sched = {
|
2018-11-02 01:41:41 +03:00
|
|
|
.ops = {
|
2017-04-14 11:00:02 +03:00
|
|
|
.init_sched = kyber_init_sched,
|
|
|
|
.exit_sched = kyber_exit_sched,
|
|
|
|
.init_hctx = kyber_init_hctx,
|
|
|
|
.exit_hctx = kyber_exit_hctx,
|
2017-06-16 19:15:26 +03:00
|
|
|
.limit_depth = kyber_limit_depth,
|
block: kyber: make kyber more friendly with merging
Currently, kyber is very unfriendly with merging. kyber depends
on ctx rq_list to do merging, however, most of time, it will not
leave any requests in ctx rq_list. This is because even if tokens
of one domain is used up, kyber will try to dispatch requests
from other domain and flush the rq_list there.
To improve this, we setup kyber_ctx_queue (kcq) which is similar
with ctx, but it has rq_lists for different domain and build same
mapping between kcq and khd as the ctx & hctx. Then we could merge,
insert and dispatch for different domains separately. At the same
time, only flush the rq_list of kcq when get domain token successfully.
Then if one domain token is used up, the requests could be left in
the rq_list of that domain and maybe merged with following io.
Following is my test result on machine with 8 cores and NVMe card
INTEL SSDPEKKR128G7
fio size=256m ioengine=libaio iodepth=64 direct=1 numjobs=8
seq/random
+------+---------------------------------------------------------------+
|patch?| bw(MB/s) | iops | slat(usec) | clat(usec) | merge |
+----------------------------------------------------------------------+
| w/o | 606/612 | 151k/153k | 6.89/7.03 | 3349.21/3305.40 | 0/0 |
+----------------------------------------------------------------------+
| w/ | 1083/616 | 277k/154k | 4.93/6.95 | 1830.62/3279.95 | 223k/3k |
+----------------------------------------------------------------------+
When set numjobs to 16, the bw and iops could reach 1662MB/s and 425k
on my platform.
Signed-off-by: Jianchao Wang <jianchao.w.wang@oracle.com>
Tested-by: Holger Hoffstätte <holger@applied-asynchrony.com>
Reviewed-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2018-05-30 19:47:40 +03:00
|
|
|
.bio_merge = kyber_bio_merge,
|
2017-06-16 19:15:26 +03:00
|
|
|
.prepare_request = kyber_prepare_request,
|
block: kyber: make kyber more friendly with merging
Currently, kyber is very unfriendly with merging. kyber depends
on ctx rq_list to do merging, however, most of time, it will not
leave any requests in ctx rq_list. This is because even if tokens
of one domain is used up, kyber will try to dispatch requests
from other domain and flush the rq_list there.
To improve this, we setup kyber_ctx_queue (kcq) which is similar
with ctx, but it has rq_lists for different domain and build same
mapping between kcq and khd as the ctx & hctx. Then we could merge,
insert and dispatch for different domains separately. At the same
time, only flush the rq_list of kcq when get domain token successfully.
Then if one domain token is used up, the requests could be left in
the rq_list of that domain and maybe merged with following io.
Following is my test result on machine with 8 cores and NVMe card
INTEL SSDPEKKR128G7
fio size=256m ioengine=libaio iodepth=64 direct=1 numjobs=8
seq/random
+------+---------------------------------------------------------------+
|patch?| bw(MB/s) | iops | slat(usec) | clat(usec) | merge |
+----------------------------------------------------------------------+
| w/o | 606/612 | 151k/153k | 6.89/7.03 | 3349.21/3305.40 | 0/0 |
+----------------------------------------------------------------------+
| w/ | 1083/616 | 277k/154k | 4.93/6.95 | 1830.62/3279.95 | 223k/3k |
+----------------------------------------------------------------------+
When set numjobs to 16, the bw and iops could reach 1662MB/s and 425k
on my platform.
Signed-off-by: Jianchao Wang <jianchao.w.wang@oracle.com>
Tested-by: Holger Hoffstätte <holger@applied-asynchrony.com>
Reviewed-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2018-05-30 19:47:40 +03:00
|
|
|
.insert_requests = kyber_insert_requests,
|
2017-06-16 19:15:21 +03:00
|
|
|
.finish_request = kyber_finish_request,
|
2018-02-23 18:36:57 +03:00
|
|
|
.requeue_request = kyber_finish_request,
|
2017-04-14 11:00:02 +03:00
|
|
|
.completed_request = kyber_completed_request,
|
|
|
|
.dispatch_request = kyber_dispatch_request,
|
|
|
|
.has_work = kyber_has_work,
|
2021-02-05 12:13:10 +03:00
|
|
|
.depth_updated = kyber_depth_updated,
|
2017-04-14 11:00:02 +03:00
|
|
|
},
|
2017-05-04 10:31:33 +03:00
|
|
|
#ifdef CONFIG_BLK_DEBUG_FS
|
|
|
|
.queue_debugfs_attrs = kyber_queue_debugfs_attrs,
|
|
|
|
.hctx_debugfs_attrs = kyber_hctx_debugfs_attrs,
|
|
|
|
#endif
|
2017-04-14 11:00:02 +03:00
|
|
|
.elevator_attrs = kyber_sched_attrs,
|
|
|
|
.elevator_name = "kyber",
|
|
|
|
.elevator_owner = THIS_MODULE,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int __init kyber_init(void)
|
|
|
|
{
|
|
|
|
return elv_register(&kyber_sched);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit kyber_exit(void)
|
|
|
|
{
|
|
|
|
elv_unregister(&kyber_sched);
|
|
|
|
}
|
|
|
|
|
|
|
|
module_init(kyber_init);
|
|
|
|
module_exit(kyber_exit);
|
|
|
|
|
|
|
|
MODULE_AUTHOR("Omar Sandoval");
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
MODULE_DESCRIPTION("Kyber I/O scheduler");
|