IO cost model based work-conserving porportional controller
Subsystems (13)
Tejun Heo
maintainerPATCH 1/1 IO cost model based work-conserving porportional controller
One challenge of controlling IO resources is the lack of trivially observable cost metric. This is distinguished from CPU and memory where wallclock time and the number of bytes can serve as accurate enough approximations.
Bandwidth and iops are the most commonly used metrics for IO devices but depending on the type and specifics of the device, different IO patterns easily lead to multiple orders of magnitude variations rendering them useless for the purpose of IO capacity distribution. While on-device time, with a lot of clutches, could serve as a useful approximation for non-queued rotational devices, this is no longer viable with modern devices, even the rotational ones.
While there is no cost metric we can trivially observe, it isn't a complete mystery. For example, on a rotational device, seek cost dominates while a contiguous transfer contributes a smaller amount proportional to the size. If we can characterize at least the relative costs of these different types of IOs, it should be possible to implement a reasonable work-conserving proportional IO resource distribution.
This patchset implements IO cost model based work-conserving proportional controller. It currently has a simple linear cost model builtin where each IO is classified as sequential or random and given a base cost accordingly and additional size-proportional cost is added on top. Each IO is given a cost based on the model and the controller issues IOs for each cgroup according to their hierarchical weight.
By default, the controller adapts its overall IO rate so that it doesn't build up buffer bloat in the request_queue layer, which guarantees that the controller doesn't lose significant amount of total work. However, this may not provide sufficient differentiation as the underlying device may have a deep queue and not be fair in how the queued IOs are serviced. The controller provides extra QoS control knobs which allow tightening control feedback loop as necessary.
For more details on the control mechanism, implementation and interface, please refer to the comment at the top of block/blk-ioweight.c and Documentation/admin-guide/cgroup-v2.rst changes in the "blkcg: implement blk-ioweight" patch.
Here are some test results. Each test run goes through the following combinations with each combination running for a minute. All tests are performed against regular files on btrfs w/ deadline as the IO scheduler. Random IOs are direct w/ queue depth of 64. Sequential are normal buffered IOs.
high priority (weight=500) low priority (weight=100)
Rand read None
ditto Rand read
ditto Seq read
ditto Rand write
ditto Seq write
Seq read None
ditto Rand read
ditto Seq read
ditto Rand write
ditto Seq write
Rand write None
ditto Rand read
ditto Seq read
ditto Rand write
ditto Seq write
Seq write None
ditto Rand read
ditto Seq read
ditto Rand write
ditto Seq write
* 7200RPM SATA hard disk
* No IO control
https://photos.app.goo.gl/1KBHn7ykpC1LXRkB8 * ioweight, QoS: None https://photos.app.goo.gl/MLNQGxCtBQ8wAmjm7 * ioweight, QoS: rpct=95.00 rlat=40000 wpct=95.00 wlat=40000 min=25.00 max=200.00 https://photos.app.goo.gl/XqXHm3Mkbm9w6Db46 * NCQ-blacklisted SATA SSD (QD==1) * No IO control https://photos.app.goo.gl/wCTXeu2uJ6LYL4pk8 * ioweight, QoS: None https://photos.app.goo.gl/T2HedKD2sywQgj7R9
* ioweight, QoS: rpct=95.00 rlat=20000 wpct=95.00 wlat=20000 min=50.00 max=200.00
https://photos.app.goo.gl/urBTV8XQc1UqPJJw7
* SATA SSD (QD==32)
* No IO control
https://photos.app.goo.gl/TjEVykuVudSQcryh6
* ioweight, QoS: None
https://photos.app.goo.gl/iyQBsky7bmM54Xiq7
* ioweight, QoS: rpct=95.00 rlat=10000 wpct=95.00 wlat=20000 min=50.00 max=400.00
https://photos.app.goo.gl/q1a6URLDxPLMrnHy5
Even without explicit QoS configuration, read-heavy scenarios can obtain acceptable differentiation. However, when write-heavy, the deep buffering on the device side makes it difficult to maintain control. With QoS parameters set, the differentiation is acceptable across all combinations.
The implementation comes with default cost model parameters which are selected automatically which should provide acceptable behavior across most common devices. The parameters for hdd and consumer-grade SSDs seem pretty robust. The default parameter set and selection criteria for highend SSDs might need further adjustments.
It is fairly easy to configure the QoS parameters and, if needed, cost model coefficients. We'll follow up with tooling and further documentation. Also, the last RFC patch in the series implements support for bpf-based custom cost function. Originally we thought that we'd need per-device-type cost functions but the simple linear model now seem good enough to cover all common device classes. In case custom cost functions become necessary, we can fully develop the bpf based extension and also easily add different builtin cost models.
Andy Newell did the heavy lifting of analyzing IO workloads and device characteristics, exploring various cost models, determining the default model and parameters to use.
Josef Bacik implemented a prototype which explored the use of different types of cost metrics including on-device time and Andy's linear model.
This patchset is on top of
cgroup/for-5.3
git://git.kernel.org/pub/scm/linux/kernel/git/tj/cgroup.git for-5.3
+ [PATCHSET block/for-linus] Assorted blkcg fixes
http://lkml.kernel.org/r/[email protected]
+ [PATCHSET btrfs/for-next] btrfs: fix cgroup writeback support
http://[email protected]This patchset contains the following 10 patches.
0001-blkcg-pass-q-and-blkcg-into-blkcg_pol_alloc_pd_fn.patch 0002-blkcg-make-cpd_init_fn-optional.patch 0003-blkcg-separate-blkcg_conf_get_disk-out-of-blkg_conf_.patch 0004-block-rq_qos-add-rq_qos_merge.patch 0005-block-rq_qos-implement-rq_qos_ops-queue_depth_change.patch 0006-blkcg-s-RQ_QOS_CGROUP-RQ_QOS_LATENCY.patch 0007-blk-mq-add-optional-request-pre_start_time_ns.patch 0008-blkcg-implement-blk-ioweight.patch 0009-blkcg-add-tools-cgroup-monitor_ioweight.py.patch 0010-RFC-blkcg-implement-BPF_PROG_TYPE_IO_COST.patch
0001-0007 are prep patches.
0008 implements blk-ioweight.
0009 adds monitoring script.
0010 is the RFC patch for BPF cost function.
The patchset is also available in the following git branch.
git://git.kernel.org/pub/scm/linux/kernel/git/tj/cgroup.git review-iow
diffstat follows, Thanks.
Documentation/admin-guide/cgroup-v2.rst | 93 block/Kconfig | 12 block/Makefile | 1 block/bfq-cgroup.c | 5 block/blk-cgroup.c | 71 block/blk-core.c | 4 block/blk-iolatency.c | 8 block/blk-ioweight.c | 2509 +++++++++++++++++ block/blk-mq.c | 11 block/blk-rq-qos.c | 18 block/blk-rq-qos.h | 28 block/blk-settings.c | 2 block/blk-throttle.c | 6 block/blk-wbt.c | 18 block/blk-wbt.h | 4 block/blk.h | 8 block/ioctl.c | 4 include/linux/blk-cgroup.h | 4 include/linux/blk_types.h | 3 include/linux/blkdev.h | 7 include/linux/bpf_types.h | 3 include/trace/events/ioweight.h | 174 + include/uapi/linux/bpf.h | 11 include/uapi/linux/fs.h | 2 tools/bpf/bpftool/feature.c | 3 tools/bpf/bpftool/main.h | 1 tools/cgroup/monitor_ioweight.py | 264 + tools/include/uapi/linux/bpf.h | 11 tools/include/uapi/linux/fs.h | 2 tools/lib/bpf/libbpf.c | 2 tools/lib/bpf/libbpf_probes.c | 1 tools/testing/selftests/bpf/Makefile | 2 tools/testing/selftests/bpf/iocost_ctrl.c | 43 tools/testing/selftests/bpf/progs/iocost_linear_prog.c | 52 34 files changed, 3333 insertions(+), 54 deletions(-)
--
tejun
Tejun Heo
maintainerPATCH 1/10 blkcg: pass @q and @blkcg into blkcg_pol_alloc_pd_fn()
Instead of @node, pass in @q and @blkcg so that the alloc function has more context. This doesn't cause any behavior change and will be used by io.weight implementation.
--- block/bfq-cgroup.c | 5 +++-- block/blk-cgroup.c | 6 +++--- block/blk-iolatency.c | 6 ++++-- block/blk-throttle.c | 6 ++++-- include/linux/blk-cgroup.h | 3 ++- 5 files changed, 16 insertions(+), 10 deletions(-)
block/bfq-cgroup.c +3 -2
@@ -425,11 +425,12 @@ static void bfq_cpd_free(struct blkcg_policy_data *cpd)kfree (cpd_to_bfqgd (cpd)); } -static struct blkg_policy_data *bfq_pd_alloc (gfp_t gfp,int node) +static struct blkg_policy_data *bfq_pd_alloc (gfp_t gfp,struct request_queue *q, +struct blkcg *blkcg) {struct bfq_group *bfqg; - bfqg =kzalloc_node (sizeof (*bfqg), gfp, node); + bfqg =kzalloc_node (sizeof (*bfqg), gfp, q->node);if (!bfqg)return NULL ;
block/blk-cgroup.c +3 -3
@@ -174,7 +174,7 @@ static struct blkcg_gq *blkg_alloc(struct blkcg *blkcg, struct request_queue *q,continue ;/* alloc per-policy data and attach it to blkg */ - pd = pol->pd_alloc_fn (gfp_mask, q->node); + pd = pol->pd_alloc_fn (gfp_mask, q, blkcg);if (!pd) goto err_free;
@@ -1405,7 +1405,7 @@ int blkcg_activate_policy(struct request_queue *q,blk_mq_freeze_queue (q); pd_prealloc:if (!pd_prealloc) { - pd_prealloc = pol->pd_alloc_fn (GFP_KERNEL , q->node); + pd_prealloc = pol->pd_alloc_fn (GFP_KERNEL , q, &blkcg_root);if (!pd_prealloc) { ret = -ENOMEM ; goto out_bypass_end;
@@ -1421,7 +1421,7 @@ int blkcg_activate_policy(struct request_queue *q,if (blkg->pd[pol->plid])continue ; - pd = pol->pd_alloc_fn (GFP_NOWAIT | __GFP_NOWARN, q->node); + pd = pol->pd_alloc_fn (GFP_NOWAIT | __GFP_NOWARN, q, &blkcg_root);if (!pd)swap (pd, pd_prealloc);if (!pd) {
block/blk-iolatency.c +4 -2
@@ -950,11 +950,13 @@ static size_t iolatency_pd_stat(struct blkg_policy_data *pd, char *buf, } -static struct blkg_policy_data *iolatency_pd_alloc (gfp_t gfp,int node) +static struct blkg_policy_data *iolatency_pd_alloc (gfp_t gfp, +struct request_queue *q, +struct blkcg *blkcg) {struct iolatency_grp *iolat; - iolat =kzalloc_node (sizeof (*iolat), gfp, node); + iolat =kzalloc_node (sizeof (*iolat), gfp, q->node);if (!iolat)return NULL ; iolat->stats = __alloc_percpu_gfp(sizeof(struct latency_stat),
block/blk-throttle.c +4 -2
@@ -478,12 +478,14 @@ static void throtl_service_queue_init(struct throtl_service_queue *sq)timer_setup (&sq->pending_timer, throtl_pending_timer_fn,0 ); } -static struct blkg_policy_data *throtl_pd_alloc (gfp_t gfp,int node) +static struct blkg_policy_data *throtl_pd_alloc (gfp_t gfp, +struct request_queue *q, +struct blkcg *blkcg) {struct throtl_grp *tg;int rw; - tg =kzalloc_node (sizeof (*tg), gfp, node); + tg =kzalloc_node (sizeof (*tg), gfp, q->node);if (!tg)return NULL ;
include/linux/blk-cgroup.h +2 -1
@@ -151,7 +151,8 @@ typedef struct blkcg_policy_data *(blkcg_pol_alloc_cpd_fn)(gfp_t gfp);typedef void (blkcg_pol_init_cpd_fn )(struct blkcg_policy_data *cpd);typedef void (blkcg_pol_free_cpd_fn )(struct blkcg_policy_data *cpd);typedef void (blkcg_pol_bind_cpd_fn )(struct blkcg_policy_data *cpd); -typedef struct blkg_policy_data *(blkcg_pol_alloc_pd_fn )(gfp_t gfp,int node); +typedef struct blkg_policy_data *(blkcg_pol_alloc_pd_fn )(gfp_t gfp, +struct request_queue *q,struct blkcg *blkcg);typedef void (blkcg_pol_init_pd_fn )(struct blkg_policy_data *pd);typedef void (blkcg_pol_online_pd_fn )(struct blkg_policy_data *pd);typedef void (blkcg_pol_offline_pd_fn )(struct blkg_policy_data *pd);
Signature · 1 line
2.17.1
Tejun Heo
maintainerPATCH 2/10 blkcg: make ->cpd_init_fn() optional
In reply to Tejun HeoFor policies which can do enough initialization from ->cpd_alloc_fn(), make ->cpd_init_fn() optional.
--- block/blk-cgroup.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
block/blk-cgroup.c +2 -1
@@ -1534,7 +1534,8 @@ int blkcg_policy_register(struct blkcg_policy *pol) blkcg->cpd[pol->plid] = cpd; cpd->blkcg = blkcg; cpd->plid = pol->plid; - pol->cpd_init_fn (cpd); +if (pol->cpd_init_fn) + pol->cpd_init_fn (cpd); } }
Signature · 1 line
2.17.1
Tejun Heo
maintainerPATCH 3/10 blkcg: separate blkcg_conf_get_disk() out of blkg_conf_prep()
In reply to Tejun HeoSeparate out blkcg_conf_get_disk() so that it can be used by blkcg policy interface file input parsers before the policy is actually enabled. This doesn't introduce any functional changes.
--- block/blk-cgroup.c | 62 ++++++++++++++++++++++++++------------ include/linux/blk-cgroup.h | 1 + 2 files changed, 44 insertions(+), 19 deletions(-)
block/blk-cgroup.c +43 -19
@@ -809,6 +809,44 @@ static struct blkcg_gq *blkg_lookup_check(struct blkcg *blkcg,return __blkg_lookup (blkcg, q, true/* update_hint */ ); } +/** +* blkg_conf_prep - parse and prepare for per-blkg config update +* @inputp: input string pointer +* +* Parse the device node prefix part, MAJ:MIN, of per-blkg config update +* from @input and get and return the matching gendisk. *@inputp is +* updated to point past the device node prefix. Returns an ERR_PTR() +* value on error. +* +* Use this function iff blkg_conf_prep() can't be used for some reason. +*/ +struct gendisk *blkcg_conf_get_disk (char **inputp) +{ +char *input = *inputp; +unsigned int major, minor; +struct gendisk *disk; +int key_len, part; + +if (sscanf (input,"%u:%u%n" , &major, &minor, &key_len) !=2 ) +return ERR_PTR (-EINVAL ); + + input += key_len; +if (!isspace (*input)) +return ERR_PTR (-EINVAL ); + input =skip_spaces (input); + + disk =get_gendisk (MKDEV (major, minor), &part); +if (!disk) +return ERR_PTR (-ENODEV ); +if (part) { +put_disk_and_module (disk); +return ERR_PTR (-ENODEV ); + } + + *inputp = input; +return disk; +} +/** * blkg_conf_prep - parse and prepare for per-blkg config update * @blkcg: target block cgroup
@@ -828,25 +866,11 @@ int blkg_conf_prep(struct blkcg *blkcg, const struct blkcg_policy *pol,struct gendisk *disk;struct request_queue *q;struct blkcg_gq *blkg; -unsigned int major, minor; -int key_len, part, ret; -char *body; - -if (sscanf (input,"%u:%u%n" , &major, &minor, &key_len) !=2 ) -return -EINVAL ; - - body = input + key_len; -if (!isspace (*body)) -return -EINVAL ; - body =skip_spaces (body); +int ret; - disk =get_gendisk (MKDEV (major, minor), &part); -if (!disk) -return -ENODEV ; -if (part) { - ret = -ENODEV ; - goto fail; - } + disk =blkcg_conf_get_disk (&input); +if (IS_ERR (disk)) +return PTR_ERR (disk); q = disk->queue;
@@ -912,7 +936,7 @@ int blkg_conf_prep(struct blkcg *blkcg, const struct blkcg_policy *pol, success: ctx->disk = disk; ctx->blkg = blkg; - ctx->body = body; + ctx->body = input;return 0 ; fail_unlock:
include/linux/blk-cgroup.h +1 -0
@@ -231,6 +231,7 @@ struct blkg_conf_ctx {char *body; }; +struct gendisk *blkcg_conf_get_disk (char **inputp);int blkg_conf_prep (struct blkcg *blkcg,const struct blkcg_policy *pol,char *input,struct blkg_conf_ctx *ctx);void blkg_conf_finish (struct blkg_conf_ctx *ctx);
Signature · 1 line
2.17.1
Tejun Heo
maintainerPATCH 4/10 block/rq_qos: add rq_qos_merge()
In reply to Tejun HeoAdd a merge hook for rq_qos. This will be used by io.weight.
--- block/blk-core.c | 4 ++++ block/blk-rq-qos.c | 9 +++++++++ block/blk-rq-qos.h | 9 +++++++++ 3 files changed, 22 insertions(+)
block/blk-core.c +4 -0
@@ -559,6 +559,7 @@ bool bio_attempt_back_merge(struct request_queue *q, struct request *req,return false;trace_block_bio_backmerge (q, req, bio); +rq_qos_merge (q, req, bio);if ((req->cmd_flags &REQ_FAILFAST_MASK ) != ff)blk_rq_set_mixed_merge (req);
@@ -580,6 +581,7 @@ bool bio_attempt_front_merge(struct request_queue *q, struct request *req,return false;trace_block_bio_frontmerge (q, req, bio); +rq_qos_merge (q, req, bio);if ((req->cmd_flags &REQ_FAILFAST_MASK ) != ff)blk_rq_set_mixed_merge (req);
@@ -605,6 +607,8 @@ bool bio_attempt_discard_merge(struct request_queue *q, struct request *req, blk_rq_get_max_sectors(req, blk_rq_pos(req))) goto no_merge; +rq_qos_merge (q, req, bio); + req->biotail->bi_next = bio; req->biotail = bio; req->__data_len += bio->bi_iter.bi_size;
block/blk-rq-qos.c +9 -0
@@ -83,6 +83,15 @@ void __rq_qos_track(struct rq_qos *rqos, struct request *rq, struct bio *bio) }while (rqos); } +void __rq_qos_merge (struct rq_qos *rqos,struct request *rq,struct bio *bio) +{ +do { +if (rqos->ops->merge) + rqos->ops->merge (rqos, rq, bio); + rqos = rqos->next; + }while (rqos); +} +void __rq_qos_done_bio (struct rq_qos *rqos,struct bio *bio) { do {
block/blk-rq-qos.h +9 -0
@@ -35,6 +35,7 @@ struct rq_qos {struct rq_qos_ops {void (*throttle)(struct rq_qos *,struct bio *);void (*track)(struct rq_qos *,struct request *,struct bio *); +void (*merge)(struct rq_qos *,struct request *,struct bio *);void (*issue)(struct rq_qos *,struct request *);void (*requeue)(struct rq_qos *,struct request *);void (*done)(struct rq_qos *,struct request *);
@@ -135,6 +136,7 @@ void __rq_qos_issue(struct rq_qos *rqos, struct request *rq);void __rq_qos_requeue (struct rq_qos *rqos,struct request *rq);void __rq_qos_throttle (struct rq_qos *rqos,struct bio *bio);void __rq_qos_track (struct rq_qos *rqos,struct request *rq,struct bio *bio); +void __rq_qos_merge (struct rq_qos *rqos,struct request *rq,struct bio *bio);void __rq_qos_done_bio (struct rq_qos *rqos,struct bio *bio);static inline void rq_qos_cleanup (struct request_queue *q,struct bio *bio)
@@ -185,6 +187,13 @@ static inline void rq_qos_track(struct request_queue *q, struct request *rq, __rq_qos_track(q->rq_qos, rq, bio); } +static inline void rq_qos_merge (struct request_queue *q,struct request *rq, +struct bio *bio) +{ +if (q->rq_qos) +__rq_qos_merge (q->rq_qos, rq, bio); +} +void rq_qos_exit (struct request_queue *);#endif
Signature · 1 line
2.17.1
Tejun Heo
maintainerPATCH 5/10 block/rq_qos: implement rq_qos_ops->queue_depth_changed()
In reply to Tejun Heowbt already gets queue depth changed notification through wbt_set_queue_depth(). Generalize it into rq_qos_ops->queue_depth_changed() so that other rq_qos policies can easily hook into the events too.
--- block/blk-rq-qos.c | 9 +++++++++ block/blk-rq-qos.h | 8 ++++++++ block/blk-settings.c | 2 +- block/blk-wbt.c | 18 ++++++++---------- block/blk-wbt.h | 4 ---- 5 files changed, 26 insertions(+), 15 deletions(-)
block/blk-rq-qos.c +9 -0
@@ -101,6 +101,15 @@ void __rq_qos_done_bio(struct rq_qos *rqos, struct bio *bio) }while (rqos); } +void __rq_qos_queue_depth_changed (struct rq_qos *rqos) +{ +do { +if (rqos->ops->queue_depth_changed) + rqos->ops->queue_depth_changed (rqos); + rqos = rqos->next; + }while (rqos); +} +/* * Return true, if we can't increase the depth further by scaling */
block/blk-rq-qos.h +8 -0
@@ -41,6 +41,7 @@ struct rq_qos_ops {void (*done)(struct rq_qos *,struct request *);void (*done_bio)(struct rq_qos *,struct bio *);void (*cleanup)(struct rq_qos *,struct bio *); +void (*queue_depth_changed)(struct rq_qos *);void (*exit)(struct rq_qos *);const struct blk_mq_debugfs_attr *debugfs_attrs; };
@@ -138,6 +139,7 @@ void __rq_qos_throttle(struct rq_qos *rqos, struct bio *bio);void __rq_qos_track (struct rq_qos *rqos,struct request *rq,struct bio *bio);void __rq_qos_merge (struct rq_qos *rqos,struct request *rq,struct bio *bio);void __rq_qos_done_bio (struct rq_qos *rqos,struct bio *bio); +void __rq_qos_queue_depth_changed (struct rq_qos *rqos);static inline void rq_qos_cleanup (struct request_queue *q,struct bio *bio) {
@@ -194,6 +196,12 @@ static inline void rq_qos_merge(struct request_queue *q, struct request *rq, __rq_qos_merge(q->rq_qos, rq, bio); } +static inline void rq_qos_queue_depth_changed (struct request_queue *q) +{ +if (q->rq_qos) +__rq_qos_queue_depth_changed (q->rq_qos); +} +void rq_qos_exit (struct request_queue *);#endif
block/blk-settings.c +1 -1
@@ -804,7 +804,7 @@ EXPORT_SYMBOL(blk_queue_update_dma_alignment);void blk_set_queue_depth (struct request_queue *q,unsigned int depth) { q->queue_depth = depth; -wbt_set_queue_depth (q, depth); +rq_qos_queue_depth_changed (q); }EXPORT_SYMBOL (blk_set_queue_depth);
block/blk-wbt.c +8 -10
@@ -629,15 +629,6 @@ static void wbt_requeue(struct rq_qos *rqos, struct request *rq) } } -void wbt_set_queue_depth (struct request_queue *q,unsigned int depth) -{ -struct rq_qos *rqos =wbt_rq_qos (q); -if (rqos) { -RQWB (rqos)->rq_depth.queue_depth = depth; -__wbt_update_limits (RQWB (rqos)); - } -} -void wbt_set_write_cache (struct request_queue *q,bool write_cache_on) {struct rq_qos *rqos =wbt_rq_qos (q);
@@ -689,6 +680,12 @@ static int wbt_data_dir(const struct request *rq)return -1 ; } +static void wbt_queue_depth_changed (struct rq_qos *rqos) +{ +RQWB (rqos)->rq_depth.queue_depth =blk_queue_depth (rqos->q); +__wbt_update_limits (RQWB (rqos)); +} +static void wbt_exit (struct rq_qos *rqos) {struct rq_wb *rwb =RQWB (rqos);
@@ -811,6 +808,7 @@ static struct rq_qos_ops wbt_rqos_ops = { .requeue = wbt_requeue, .done = wbt_done, .cleanup = wbt_cleanup, + .queue_depth_changed = wbt_queue_depth_changed, .exit = wbt_exit, #ifdef CONFIG_BLK_DEBUG_FS .debugfs_attrs = wbt_debugfs_attrs,
@@ -853,7 +851,7 @@ int wbt_init(struct request_queue *q) rwb->min_lat_nsec =wbt_default_latency_nsec (q); -wbt_set_queue_depth (q,blk_queue_depth (q)); +wbt_queue_depth_changed (&rwb->rqos);wbt_set_write_cache (q,test_bit (QUEUE_FLAG_WC , &q->queue_flags));return 0 ;
block/blk-wbt.h +0 -4
@@ -95,7 +95,6 @@ void wbt_enable_default(struct request_queue *);u64 wbt_get_min_lat (struct request_queue *q);void wbt_set_min_lat (struct request_queue *q,u64 val); -void wbt_set_queue_depth (struct request_queue *,unsigned int );void wbt_set_write_cache (struct request_queue *,bool );u64 wbt_default_latency_nsec (struct request_queue *);
@@ -118,9 +117,6 @@ static inline void wbt_disable_default(struct request_queue *q)static inline void wbt_enable_default (struct request_queue *q) { } -static inline void wbt_set_queue_depth (struct request_queue *q,unsigned int depth) -{ -}static inline void wbt_set_write_cache (struct request_queue *q,bool wc) { }
Signature · 1 line
2.17.1
Tejun Heo
maintainerPATCH 6/10 blkcg: s/RQ_QOS_CGROUP/RQ_QOS_LATENCY/
In reply to Tejun Heoio.weight is gonna be another rq_qos cgroup mechanism. Let's rename RQ_QOS_CGROUP which is being used by io.latency to RQ_QOS_LATENCY in preparation.
--- block/blk-iolatency.c | 2 +- block/blk-rq-qos.h | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-)
block/blk-iolatency.c +1 -1
@@ -744,7 +744,7 @@ int blk_iolatency_init(struct request_queue *q)return -ENOMEM ; rqos = &blkiolat->rqos; - rqos->id =RQ_QOS_CGROUP ; + rqos->id =RQ_QOS_LATENCY ; rqos->ops = &blkcg_iolatency_ops; rqos->q = q;
block/blk-rq-qos.h +4 -4
@@ -14,7 +14,7 @@ struct blk_mq_debugfs_attr;enum rq_qos_id {RQ_QOS_WBT , -RQ_QOS_CGROUP , +RQ_QOS_LATENCY , };struct rq_wait {
@@ -74,7 +74,7 @@ static inline struct rq_qos *wbt_rq_qos(struct request_queue *q)static inline struct rq_qos *blkcg_rq_qos (struct request_queue *q) { -return rq_qos_id (q,RQ_QOS_CGROUP ); +return rq_qos_id (q,RQ_QOS_LATENCY ); }static inline const char *rq_qos_id_to_name (enum rq_qos_id id)
@@ -82,8 +82,8 @@ static inline const char *rq_qos_id_to_name(enum rq_qos_id id)switch (id) {case RQ_QOS_WBT :return "wbt" ; -case RQ_QOS_CGROUP : -return "cgroup" ; +case RQ_QOS_LATENCY : +return "latency" ; }return "unknown" ; }
Signature · 1 line
2.17.1
Tejun Heo
maintainerPATCH 7/10 blk-mq: add optional request->pre_start_time_ns
In reply to Tejun HeoThere are currently two start time timestamps - start_time_ns and io_start_time_ns. The former marks the request allocation and and the second issue-to-device time. The planned io.weight controller needs to measure the total time bios take to execute after it leaves rq_qos including the time spent waiting for request to become available, which can easily dominate on saturated devices.
This patch adds request->pre_start_time_ns which records when the request allocation attempt started. As it isn't used for the usual stats, make it optional behind QUEUE_FLAG_REC_PRESTART.
--- block/blk-mq.c | 11 +++++++++-- include/linux/blkdev.h | 7 ++++++- 2 files changed, 15 insertions(+), 3 deletions(-)
block/blk-mq.c +9 -2
@@ -291,7 +291,7 @@ static inline bool blk_mq_need_time_stamp(struct request *rq) }static struct request *blk_mq_rq_ctx_init (struct blk_mq_alloc_data *data, -unsigned int tag,unsigned int op) +unsigned int tag,unsigned int op,u64 pre_start_time_ns) {struct blk_mq_tags *tags =blk_mq_tags_from_data (data);struct request *rq = tags->static_rqs[tag];
@@ -325,6 +325,7 @@ static struct request *blk_mq_rq_ctx_init(struct blk_mq_alloc_data *data,RB_CLEAR_NODE (&rq->rb_node); rq->rq_disk =NULL ; rq->part =NULL ; + rq->pre_start_time_ns = pre_start_time_ns;if (blk_mq_need_time_stamp (rq)) rq->start_time_ns =ktime_get_ns ();else
@@ -356,8 +357,14 @@ static struct request *blk_mq_get_request(struct request_queue *q,struct request *rq;unsigned int tag;bool put_ctx_on_error = false; +u64 pre_start_time_ns =0 ;blk_queue_enter_live (q); + +/* pre_start_time includes depth and tag waits */ +if (blk_queue_rec_prestart (q)) + pre_start_time_ns =ktime_get_ns (); + data->q = q;if (likely (!data->ctx)) { data->ctx =blk_mq_get_ctx (q);
@@ -395,7 +402,7 @@ static struct request *blk_mq_get_request(struct request_queue *q,return NULL ; } - rq =blk_mq_rq_ctx_init (data, tag, data->cmd_flags); + rq =blk_mq_rq_ctx_init (data, tag, data->cmd_flags, pre_start_time_ns);if (!op_is_flush (data->cmd_flags)) { rq->elv.icq =NULL ;if (e && e->type->ops.prepare_request) {
include/linux/blkdev.h +6 -1
@@ -194,7 +194,9 @@ struct request {struct gendisk *rq_disk;struct hd_struct *part; -/* Time that I/O was submitted to the kernel. */ +/* Time that the first bio started allocating this request. */ +u64 pre_start_time_ns; +/* Time that this request was allocated for this IO. */ u64 start_time_ns;/* Time that I/O was submitted to the device. */ u64 io_start_time_ns;
@@ -606,6 +608,7 @@ struct request_queue {#define QUEUE_FLAG_SCSI_PASSTHROUGH 23/* queue supports SCSI commands */ #define QUEUE_FLAG_QUIESCED 24/* queue has been quiesced */ #define QUEUE_FLAG_PCI_P2PDMA 25/* device supports PCI p2p requests */ +#define QUEUE_FLAG_REC_PRESTART 26/* record pre_start_time_ns */ #define QUEUE_FLAG_MQ_DEFAULT ((1 << QUEUE_FLAG_IO_STAT) | \ (1 << QUEUE_FLAG_SAME_COMP))
@@ -632,6 +635,8 @@ bool blk_queue_flag_test_and_set(unsigned int flag, struct request_queue *q); test_bit(QUEUE_FLAG_SCSI_PASSTHROUGH, &(q)->queue_flags)#define blk_queue_pci_p2pdma (q) \ test_bit(QUEUE_FLAG_PCI_P2PDMA, &(q)->queue_flags) +#define blk_queue_rec_prestart (q) \ + test_bit(QUEUE_FLAG_REC_PRESTART, &(q)->queue_flags)#define blk_noretry_request (rq) \ ((rq)->cmd_flags & (REQ_FAILFAST_DEV|REQ_FAILFAST_TRANSPORT| \
Signature · 1 line
2.17.1
Tejun Heo
maintainerPATCH 8/10 blkcg: implement blk-ioweight
In reply to Tejun HeoThis patchset implements IO cost model based work-conserving proportional controller.
While io.latency provides the capability to comprehensively prioritize and protect IOs depending on the cgroups, its protection is binary - the lowest latency target cgroup which is suffering is protected at the cost of all others. In many use cases including stacking multiple workload containers in a single system, it's necessary to distribute IO capacity with better granularity.
One challenge of controlling IO resources is the lack of trivially observable cost metric. The most common metrics - bandwidth and iops
- can be off by orders of magnitude depending on the device type and IO pattern. However, the cost isn't a complete mystery. Given several key attributes, we can make fairly reliable predictions on how expensive a given stream of IOs would be, at least compared to other IO patterns.
The function which determines the cost of a given IO is the IO cost model for the device. This controller distributes IO capacity based on the costs estimated by such model. The more accurate the cost model the better but the controller adapts based on IO completion latency and as long as the relative costs across differents IO patterns are consistent and sensible, it'll adapt to the actual performance of the device.
Currently, the only implemented cost model is a simple linear one with a few sets of default parameters for different classes of device. This covers most common devices reasonably well. All the infrastructure to tune and add different cost models is already in place and a later patch will also allow using bpf progs for cost models.
Please see the top comment in blk-ioweight.c and documentation for more details.
--- Documentation/admin-guide/cgroup-v2.rst | 93 + block/Kconfig | 9 + block/Makefile | 1 + block/blk-ioweight.c | 2356 +++++++++++++++++++++++ block/blk-rq-qos.h | 3 + include/linux/blk_types.h | 3 + include/trace/events/ioweight.h | 174 ++ 7 files changed, 2639 insertions(+) create mode 100644 block/blk-ioweight.c create mode 100644 include/trace/events/ioweight.h
Documentation/admin-guide/cgroup-v2.rst +93 -0
@@ -1425,6 +1425,99 @@ IO Interface Files 8:16 rbytes=1459200 wbytes=314773504 rios=192 wios=353 dbytes=0 dios=0 8:0 rbytes=90430464 wbytes=299008000 rios=8950 wios=1252 dbytes=50331648 dios=3021 + io.weight.qos + A read-write nested-keyed file with exists only on the root + cgroup. + + This file configures the Quality of Service of the IO cost + model based proportional controller + (CONFIG_BLK_CGROUP_IOWEIGHT). Lines are keyed by $MAJ:$MIN + device numbers and not ordered. The line for a given device + is populated on the first write for the device on + "io.weight.qos" or "io.weight.cost_model". The following + nested keys are defined. + + ====== ===================================== + enable Weight-based control enable + ctrl "auto" or "user" + rpct Read latency percentile [0, 100] + rlat Read latency threshold + wpct Write latency percentile [0, 100] + wlat Write latency threshold + min Minimum scaling percentage [1, 10000] + max Maximum scaling percentage [1, 10000] + ====== ===================================== + + The controller is disabled by default and can be enabled by + setting "enable" to 1. "rpct" and "wpct" parameters default + to zero and the controller uses internal device saturation + state to adjust the overall IO rate between "min" and "max". + + When a better control quality is needed, latency QoS + parameters can be configured. For example:: + + 8:16 enable=1 ctrl=auto rpct=95.00 rlat=75000 wpct=95.00 wlat=150000 min=50.00 max=150.0 + + shows that on sdb, the controller is enabled, will consider + the device saturated if the 95th percentile of read completion + latencies is above 75ms or write 150ms, and adjust the overall + IO issue rate between 50% and 150% accordingly. + + The lower the saturation point, the better the latency QoS at + the cost of aggregate bandwidth. The narrower the allowed + adjustment range between "min" and "max", the more conformant + to the cost model the IO behavior. Note that the IO issue + base rate may be far off from 100% and setting "min" and "max" + blindly can lead to a significant loss of device capacity or + control quality. "min" and "max" are useful for regulating + devices which show wide temporary behavior changes - e.g. a + ssd which accepts writes at the line speed for a while and + then completely stalls for multiple seconds. + + When "ctrl" is "auto", the parameters are controlled by the + kernel and may change automatically. Setting "ctrl" to "user" + or setting any of the percentile and latency parameters puts + it into "user" mode and disables the automatic changes. The + automatic mode can be restored by setting "ctrl" to "auto". + + io.weight.cost_model + A read-write nested-keyed file with exists only on the root + cgroup. + + This file configures the cost model of the IO cost model based + proportional controller (CONFIG_BLK_CGROUP_IOWEIGHT). Lines + are keyed by $MAJ:$MIN device numbers and not ordered. The + line for a given device is populated on the first write for + the device on "io.weight.qos" or "io.weight.cost_model". The + following nested keys are defined. + + ===== ================================ + ctrl "auto" or "user" + model The cost model in use - "linear" + ===== ================================ + + When "ctrl" is "auto", the kernel may change all parameters + dynamically. When "ctrl" is set to "user" or any other + parameters are written to, "ctrl" become "user" and the + automatic changes are disabled. + + When "model" is "linear", the following model parameters are + defined. + + ============= ======================================== + [r|w]bps The maximum sequential IO throughput + [r|w]seqiops The maximum 4k sequential IOs per second + [r|w]randiops The maximum 4k random IOs per second + ============= ======================================== + + From the above, the builtin linear model determines the base + costs of a sequential and random IO and the cost coefficient + for the IO size. While simple, this model can cover most + common device classes acceptably. + + The IO cost model isn't expected to be accurate in absolute + sense and is scaled to the device behavior dynamically. + io.weight A read-write flat-keyed file which exists on non-root cgroups. The default is "default 100".
block/Kconfig +9 -0
@@ -132,6 +132,15 @@ config BLK_CGROUP_IOLATENCY Note, this is an experimental interface and could be changed someday. +config BLK_CGROUP_IOWEIGHT + bool "Enable support for weight based cgroup IO protection" + depends on BLK_CGROUP=y + ---help--- + Enabling this option enables the .weight interface for IO throttling. + The IO controller will attempt to maintain a IO distribution between + different groups based on their percentage of share of the overall + weight distribution. + config BLK_WBT_MQ bool "Multiqueue writeback throttling" default y
block/Makefile +1 -0
@@ -18,6 +18,7 @@ obj-$(CONFIG_BLK_DEV_BSGLIB) += bsg-lib.o obj-$(CONFIG_BLK_CGROUP) += blk-cgroup.o obj-$(CONFIG_BLK_DEV_THROTTLING) += blk-throttle.o obj-$(CONFIG_BLK_CGROUP_IOLATENCY) += blk-iolatency.o +obj-$(CONFIG_BLK_CGROUP_IOWEIGHT) += blk-ioweight.o obj-$(CONFIG_MQ_IOSCHED_DEADLINE) += mq-deadline.o obj-$(CONFIG_MQ_IOSCHED_KYBER) += kyber-iosched.o bfq-y := bfq-iosched.o bfq-wf2q.o bfq-cgroup.o
block/blk-ioweight.c new file +2356 -0
2,356 lines not on this page · raw message
block/blk-rq-qos.h +3 -0
@@ -15,6 +15,7 @@ struct blk_mq_debugfs_attr;enum rq_qos_id {RQ_QOS_WBT ,RQ_QOS_LATENCY , +RQ_QOS_WEIGHT , };struct rq_wait {
@@ -84,6 +85,8 @@ static inline const char *rq_qos_id_to_name(enum rq_qos_id id)return "wbt" ;case RQ_QOS_LATENCY :return "latency" ; +case RQ_QOS_WEIGHT : +return "weight" ; }return "unknown" ; }
include/linux/blk_types.h +3 -0
@@ -174,6 +174,9 @@ struct bio {*/ struct blkcg_gq *bi_blkg;struct bio_issue bi_issue; +#ifdef CONFIG_BLK_CGROUP_IOWEIGHT +u64 bi_ioweight_cost; +#endif #endif union {#if defined(CONFIG_BLK_DEV_INTEGRITY )
include/trace/events/ioweight.h new file +174 -0
174 lines not on this page · raw message
Signature · 1 line
2.17.1
Re: [PATCH 08/10] blkcg: implement blk-ioweight
Quoted 33 lines · Tejun Heo
This patchset implements IO cost model based work-conserving proportional controller.
While io.latency provides the capability to comprehensively prioritize and protect IOs depending on the cgroups, its protection is binary - the lowest latency target cgroup which is suffering is protected at the cost of all others. In many use cases including stacking multiple workload containers in a single system, it's necessary to distribute IO capacity with better granularity.
One challenge of controlling IO resources is the lack of trivially observable cost metric. The most common metrics - bandwidth and iops
- can be off by orders of magnitude depending on the device type and IO pattern. However, the cost isn't a complete mystery. Given several key attributes, we can make fairly reliable predictions on how expensive a given stream of IOs would be, at least compared to other IO patterns.The function which determines the cost of a given IO is the IO cost model for the device. This controller distributes IO capacity based on the costs estimated by such model. The more accurate the cost model the better but the controller adapts based on IO completion latency and as long as the relative costs across differents IO patterns are consistent and sensible, it'll adapt to the actual performance of the device.
Currently, the only implemented cost model is a simple linear one with a few sets of default parameters for different classes of device. This covers most common devices reasonably well. All the infrastructure to tune and add different cost models is already in place and a later patch will also allow using bpf progs for cost models.
Quoted 2 lines
Please see the top comment in
blk-ioweight.cand documentation for more details.
Reading through the description here and in the comment, and with the caveat that I am familiar with network packet scheduling but not with the IO layer, I think your approach sounds quite reasonable; and I'm happy to see improvements in this area!
One question: How are equal-weight cgroups scheduled relative to each other? Or requests from different processes within a single cgroup for that matter? FIFO? Round-robin? Something else?
Thanks,
-Toke
Tejun Heo
maintainerRe: [PATCH 08/10] blkcg: implement blk-ioweight
Hello, Toke.
Quoted 3 lines · Toke Høiland-Jørgensen
One question: How are equal-weight cgroups scheduled relative to each other? Or requests from different processes within a single cgroup for that matter? FIFO? Round-robin? Something else?
Once each cgroup got their hierarchical weight and current vtime for the period, they don't talk to each other. Each is expected to do the right thing on their own. When the period ends, the timer looks at how the device is performing, how much each used and so on and then make necessary adjustments. So, there's no direct cross-cgroup synchronization. Each is throttled to their target level independently.
Within a single cgroup, the IOs are FIFO. When an IO has enough vtime credit, it just passes through. When it doesn't, it always waits behind any other IOs which are already waiting.
Thanks.
Signature · 1 line
tejun
Re: [PATCH 08/10] blkcg: implement blk-ioweight
Quoted 7 lines · Tejun Heo
Hello, Toke.
Quoted 3 lines · Toke Høiland-Jørgensen
One question: How are equal-weight cgroups scheduled relative to each other? Or requests from different processes within a single cgroup for that matter? FIFO? Round-robin? Something else?
Quoted 7 lines
Once each cgroup got their hierarchical weight and current vtime for the period, they don't talk to each other. Each is expected to do the right thing on their own. When the period ends, the timer looks at how the device is performing, how much each used and so on and then make necessary adjustments. So, there's no direct cross-cgroup synchronization. Each is throttled to their target level independently.
Right, makes sense.
Quoted 3 lines
Within a single cgroup, the IOs are FIFO. When an IO has enough vtime credit, it just passes through. When it doesn't, it always waits behind any other IOs which are already waiting.
OK. Is there any fundamental reason why requests from individual processes could not be interleaved? Or does it just not give the same benefits in an IO request context as it does for network packets?
Thanks for the explanations! :)
-Toke
Tejun Heo
maintainerRe: [PATCH 08/10] blkcg: implement blk-ioweight
Hello,
Quoted 7 lines · Toke Høiland-Jørgensen
Quoted 3 lines
Within a single cgroup, the IOs are FIFO. When an IO has enough vtime credit, it just passes through. When it doesn't, it always waits behind any other IOs which are already waiting.
OK. Is there any fundamental reason why requests from individual processes could not be interleaved? Or does it just not give the same benefits in an IO request context as it does for network packets?
I don't think there's any fundamental reason we can't. Currently, it just isn't doing anything it doesn't have to do while preserving the existing ordering. One different from networking could be that there's more sharing - buffered writes are attributed to the whole domain (either system or cgroup) rather than individual tasks, so the ownership of IOs gets a bit mushy beyond resource domain level.
Thanks.
Signature · 1 line
tejun
Tejun Heo
maintainerPATCH 9/10 blkcg: add tools/cgroup/monitor_ioweight.py
In reply to Tejun HeoInstead of mucking with debugfs and ->pd_stat(), add drgn based monitoring script.
--- block/blk-ioweight.c | 21 +++ tools/cgroup/monitor_ioweight.py | 264 +++++++++++++++++++++++++++++++ 2 files changed, 285 insertions(+) create mode 100644 tools/cgroup/monitor_ioweight.py
block/blk-ioweight.c +21 -0
@@ -146,6 +146,27 @@* donate and should take back how much requires hweight propagations * anyway making it easier to implement and understand as a separate * mechanism. +* +* 3. Monitoring +* +* Instead of debugfs or other clumsy monitoring mechanisms, this +* controller uses a drgn based monitoring script - +* tools/cgroup/monitor_ioweight.py. For details on drgn, please see +* https://github.com/osandov/drgn. The ouput looks like the following. +* +* sdb RUN per=300ms cur_per=234.218:v203.695 busy= +1 vrate= 62.12% +* active weight hweight% inflt% del_ms usages% +* test/a * 50/ 50 33.33/ 33.33 27.65 0*041 033:033:033 +* test/b * 100/ 100 66.67/ 66.67 17.56 0*000 066:079:077 +* +* - per : Timer period +* - cur_per : Internal wall and device vtime clock +* - vrate : Device virtual time rate against wall clock +* - weight : Surplus-adjusted and configured weights +* - hweight : Surplus-adjusted and configured hierarchical weights +* - inflt : The percentage of in-flight IO cost at the end of last period +* - del_ms : Deferred issuer delay induction level and duration +* - usages : Usage history */ #include <linux/kernel.h>
tools/cgroup/monitor_ioweight.py new file +264 -0
264 lines not on this page · raw message
Signature · 1 line
2.17.1
Tejun Heo
maintainerPATCH 10/10 blkcg: implement BPF_PROG_TYPE_IO_COST
In reply to Tejun HeoCurrently, blkcg implements one builtin IO cost model - lienar. To allow customization and experimentation, allow a bpf program to override IO cost model.
--- block/Kconfig | 3 + block/blk-ioweight.c | 148 +++++++++++++++++- block/blk.h | 8 + block/ioctl.c | 4 + include/linux/bpf_types.h | 3 + include/uapi/linux/bpf.h | 11 ++ include/uapi/linux/fs.h | 2 + tools/bpf/bpftool/feature.c | 3 + tools/bpf/bpftool/main.h | 1 + tools/include/uapi/linux/bpf.h | 11 ++ tools/include/uapi/linux/fs.h | 2 + tools/lib/bpf/libbpf.c | 2 + tools/lib/bpf/libbpf_probes.c | 1 + tools/testing/selftests/bpf/Makefile | 2 +- tools/testing/selftests/bpf/iocost_ctrl.c | 43 +++++ .../selftests/bpf/progs/iocost_linear_prog.c | 52 ++++++ 16 files changed, 287 insertions(+), 9 deletions(-) create mode 100644 tools/testing/selftests/bpf/iocost_ctrl.c create mode 100644 tools/testing/selftests/bpf/progs/iocost_linear_prog.c
block/Kconfig +3 -0
@@ -204,4 +204,7 @@ config BLK_MQ_RDMA config BLK_PM def_bool BLOCK && PM +config BLK_BPF_IO_COST + def_bool BLK_CGROUP_IOWEIGHT && BPF_SYSCALL + source "block/Kconfig.iosched"
block/blk-ioweight.c +140 -8
190 lines not on this page · raw message
block/blk.h +8 -0
@@ -317,6 +317,14 @@ static inline void blk_queue_bounce(struct request_queue *q, struct bio **bio) }#endif /* CONFIG_BOUNCE */ +#ifdef CONFIG_BLK_BPF_IO_COST +int blk_bpf_io_cost_ioctl (struct block_device *bdev,unsigned cmd, +char __user *arg); +#else +static inline int blk_bpf_io_cost_ioctl (struct block_device *bdev,unsigned cmd, +char __user *arg) {return -ENOTTY ; } +#endif +#ifdef CONFIG_BLK_CGROUP_IOLATENCY extern int blk_iolatency_init (struct request_queue *q);#else
block/ioctl.c +4 -0
@@ -11,6 +11,8 @@#include <linux/pr.h> #include <linux/uaccess.h> +#include "blk.h" +static int blkpg_ioctl (struct block_device *bdev,struct blkpg_ioctl_arg __user *arg) {struct block_device *bdevp;
@@ -590,6 +592,8 @@ int blkdev_ioctl(struct block_device *bdev, fmode_t mode, unsigned cmd,case BLKTRACESETUP :case BLKTRACETEARDOWN :return blk_trace_ioctl (bdev, cmd, argp); +case BLKBPFIOCOST : +return blk_bpf_io_cost_ioctl (bdev, cmd, argp);case IOC_PR_REGISTER :return blkdev_pr_register (bdev, argp);case IOC_PR_RESERVE :
include/linux/bpf_types.h +3 -0
@@ -37,6 +37,9 @@ BPF_PROG_TYPE(BPF_PROG_TYPE_LIRC_MODE2, lirc_mode2)#ifdef CONFIG_INET BPF_PROG_TYPE(BPF_PROG_TYPE_SK_REUSEPORT, sk_reuseport)#endif +#ifdef CONFIG_BLK_BPF_IO_COST +BPF_PROG_TYPE(BPF_PROG_TYPE_IO_COST, io_cost) +#endif BPF_MAP_TYPE(BPF_MAP_TYPE_ARRAY, array_map_ops)BPF_MAP_TYPE (BPF_MAP_TYPE_PERCPU_ARRAY , percpu_array_map_ops)
include/uapi/linux/bpf.h +11 -0
@@ -170,6 +170,7 @@ enum bpf_prog_type {BPF_PROG_TYPE_FLOW_DISSECTOR ,BPF_PROG_TYPE_CGROUP_SYSCTL ,BPF_PROG_TYPE_RAW_TRACEPOINT_WRITABLE , + BPF_PROG_TYPE_IO_COST, }; enum bpf_attach_type {
@@ -3472,6 +3473,16 @@ struct bpf_flow_keys { }; }; +struct bpf_io_cost { +__u64 cost;/* output */ + +__u32 opf; +__u32 nr_sectors; +__u64 sector; +__u64 last_sector; +__u8 is_merge; +}; +struct bpf_func_info {__u32 insn_off;__u32 type_id;
include/uapi/linux/fs.h +2 -0
@@ -181,6 +181,8 @@ struct fsxattr {#define BLKSECDISCARD _IO(0x12,125)#define BLKROTATIONAL _IO(0x12,126)#define BLKZEROOUT _IO(0x12,127) +#define BLKBPFIOCOST _IO(0x12, 128) +/* * A jump here: 130-131 are reserved for zoned block devices * (see uapi/linux/blkzoned.h)
tools/bpf/bpftool/feature.c +3 -0
@@ -383,6 +383,9 @@ static void probe_kernel_image_config(void)/* bpftilter module with "user mode helper" */ "CONFIG_BPFILTER_UMH" , +/* Block */ +"CONFIG_BLK_IO_COST" , +/* test_bpf module for BPF tests */ "CONFIG_TEST_BPF", };
tools/bpf/bpftool/main.h +1 -0
@@ -74,6 +74,7 @@ static const char * const prog_type_name[] = { [BPF_PROG_TYPE_SK_REUSEPORT] = "sk_reuseport", [BPF_PROG_TYPE_FLOW_DISSECTOR] = "flow_dissector", [BPF_PROG_TYPE_CGROUP_SYSCTL] = "cgroup_sysctl", + [BPF_PROG_TYPE_IO_COST] = "io_cost", };extern const char *const map_type_name[];
tools/include/uapi/linux/bpf.h +11 -0
@@ -170,6 +170,7 @@ enum bpf_prog_type {BPF_PROG_TYPE_FLOW_DISSECTOR ,BPF_PROG_TYPE_CGROUP_SYSCTL ,BPF_PROG_TYPE_RAW_TRACEPOINT_WRITABLE , + BPF_PROG_TYPE_IO_COST, }; enum bpf_attach_type {
@@ -3472,6 +3473,16 @@ struct bpf_flow_keys { }; }; +struct bpf_io_cost { +__u64 cost;/* output */ + +__u32 opf; +__u32 nr_sectors; +__u64 sector; +__u64 last_sector; +__u8 is_merge; +}; +struct bpf_func_info {__u32 insn_off;__u32 type_id;
tools/include/uapi/linux/fs.h +2 -0
@@ -181,6 +181,8 @@ struct fsxattr {#define BLKSECDISCARD _IO(0x12,125)#define BLKROTATIONAL _IO(0x12,126)#define BLKZEROOUT _IO(0x12,127) +#define BLKBPFIOCOST _IO(0x12, 128) +/* * A jump here: 130-131 are reserved for zoned block devices * (see uapi/linux/blkzoned.h)
tools/lib/bpf/libbpf.c +2 -0
@@ -2266,6 +2266,7 @@ static bool bpf_prog_type__needs_kver(enum bpf_prog_type type)case BPF_PROG_TYPE_RAW_TRACEPOINT_WRITABLE :case BPF_PROG_TYPE_PERF_EVENT :case BPF_PROG_TYPE_CGROUP_SYSCTL : +case BPF_PROG_TYPE_IO_COST :return false;case BPF_PROG_TYPE_KPROBE :default :
@@ -3168,6 +3169,7 @@ static const struct {BPF_PROG_SEC ("lwt_out" ,BPF_PROG_TYPE_LWT_OUT ),BPF_PROG_SEC ("lwt_xmit" ,BPF_PROG_TYPE_LWT_XMIT ),BPF_PROG_SEC ("lwt_seg6local" ,BPF_PROG_TYPE_LWT_SEG6LOCAL ), +BPF_PROG_SEC ("io_cost" ,BPF_PROG_TYPE_IO_COST ),BPF_APROG_SEC ("cgroup_skb/ingress" ,BPF_PROG_TYPE_CGROUP_SKB ,BPF_CGROUP_INET_INGRESS ), BPF_APROG_SEC("cgroup_skb/egress", BPF_PROG_TYPE_CGROUP_SKB,
tools/lib/bpf/libbpf_probes.c +1 -0
@@ -101,6 +101,7 @@ probe_load(enum bpf_prog_type prog_type, const struct bpf_insn *insns,case BPF_PROG_TYPE_SK_REUSEPORT :case BPF_PROG_TYPE_FLOW_DISSECTOR :case BPF_PROG_TYPE_CGROUP_SYSCTL : +case BPF_PROG_TYPE_IO_COST :default :break ; }
tools/testing/selftests/bpf/Makefile +1 -1
@@ -23,7 +23,7 @@ TEST_GEN_PROGS = test_verifier test_tag test_maps test_lru_map test_lpm_map test test_align test_verifier_log test_dev_cgroup test_tcpbpf_user \ test_sock test_btf test_sockmap test_lirc_mode2_user get_cgroup_id_user \ test_socket_cookie test_cgroup_storage test_select_reuseport test_section_names \ - test_netcnt test_tcpnotify_user test_sock_fields test_sysctl + test_netcnt test_tcpnotify_user test_sock_fields test_sysctl iocost_ctrl BPF_OBJ_FILES = $(patsubst %.c,%.o, $(notdir $(wildcard progs/*.c))) TEST_GEN_FILES = $(BPF_OBJ_FILES)
tools/testing/selftests/bpf/iocost_ctrl.c new file +43 -0
43 lines not on this page · raw message
tools/testing/selftests/bpf/progs/iocost_linear_prog.c new file +52 -0
52 lines not on this page · raw message
Signature · 1 line
2.17.1
Re: [PATCH 10/10] blkcg: implement BPF_PROG_TYPE_IO_COST
2019-06-13 18:56 UTC-0700 ~ Tejun Heo <[email protected]>
Quoted 6 lines
Currently, blkcg implements one builtin IO cost model - lienar. To allow customization and experimentation, allow a bpf program to override IO cost model.
Signed-off-by Tejun Heo <[email protected]>---
[...]
Quoted 19 lines
tools/bpf/bpftool/feature.c +3
-0@@ -383,6 +383,9 @@ static void probe_kernel_image_config(void)/* bpftilter module with "user mode helper" */ "CONFIG_BPFILTER_UMH" , +/* Block */ +"CONFIG_BLK_IO_COST" , +/* test_bpf module for BPF tests */ "CONFIG_TEST_BPF", };tools/bpf/bpftool/main.h +0
-0
tools/bpf/bpftool/main.h static const char * const prog_type_name[] = { · line 80
Quoted 7 lines
tools/bpf/bpftool/main.h +1
-0@@ -74,6 +74,7 @@ static const char * const prog_type_name[] = { [BPF_PROG_TYPE_SK_REUSEPORT] = "sk_reuseport", [BPF_PROG_TYPE_FLOW_DISSECTOR] = "flow_dissector", [BPF_PROG_TYPE_CGROUP_SYSCTL] = "cgroup_sysctl", + [BPF_PROG_TYPE_IO_COST] = "io_cost", };extern const char *const map_type_name[];
Hi Tejun,
Please make sure to update the documentation and bash completion when adding the new type to bpftool. You probably want something like the diff below.
Thanks,
Quentin
tools/bpf/bpftool/Documentation/bpftool-prog.rst +1 -1
@@ -40,7 +40,7 @@ PROG COMMANDS | **lwt_seg6local** | **sockops** | **sk_skb** | **sk_msg** | **lirc_mode2** | | **cgroup/bind4** | **cgroup/bind6** | **cgroup/post_bind4** | **cgroup/post_bind6** | | **cgroup/connect4** | **cgroup/connect6** | **cgroup/sendmsg4** | **cgroup/sendmsg6** | -| **cgroup/sysctl** +| **cgroup/sysctl** | **io_cost** | } | *ATTACH_TYPE* := { | **msg_verdict** | **stream_verdict** | **stream_parser** | **flow_dissector**
tools/bpf/bpftool/bash-completion/bpftool +1 -1
@@ -378,7 +378,7 @@ _bpftool() cgroup/connect4 cgroup/connect6 \ cgroup/sendmsg4 cgroup/sendmsg6 \ cgroup/post_bind4 cgroup/post_bind6 \ - cgroup/sysctl" -- \ + cgroup/sysctl io_cost" -- \ "$cur" ) ) return 0 ;;
tools/bpf/bpftool/prog.c +1 -1
@@ -1070,7 +1070,7 @@ static int do_help(int argc, char **argv)" sk_reuseport | flow_dissector | cgroup/sysctl |\n" " cgroup/bind4 | cgroup/bind6 | cgroup/post_bind4 |\n" " cgroup/post_bind6 | cgroup/connect4 | cgroup/connect6 |\n" -" cgroup/sendmsg4 | cgroup/sendmsg6 }\n" +" cgroup/sendmsg4 | cgroup/sendmsg6 | io_cost }\n" " ATTACH_TYPE := { msg_verdict | stream_verdict | stream_parser |\n" " flow_dissector }\n" " " HELP_SPEC_OPTIONS "\n"
Tejun Heo
maintainerRe: [PATCH 10/10] blkcg: implement BPF_PROG_TYPE_IO_COST
Hello, Quentin.
Quoted 3 lines · Quentin Monnet
Please make sure to update the documentation and bash completion when adding the new type to bpftool. You probably want something like the diff below.
Thank you so much. Will incorporate them. Just in case, while it's noted in the head message, I lost the RFC marker while prepping this patch. It isn't yet clear whether we'd really need custom cost functions and this patch is included more as a proof of concept. If it turns out that this is beneficial enough, the followings need to be answered.
* Is block ioctl the right mechanism to attach these programs?
* Are there more parameters that need to be exposed to the programs?
* It'd be great to have efficient access to per-blockdev and per-blockdev-cgroup-pair storages available to these programs so that they can keep track of history. What'd be the best of way of doing that considering the fact that these programs will be called per each IO and the overhead can add up quickly?
Thanks.
Signature · 1 line
tejun
Re: [PATCH 10/10] blkcg: implement BPF_PROG_TYPE_IO_COST
Quoted 11 lines · Tejun Heo
Hello, Quentin.
Quoted 3 lines · Quentin Monnet
Please make sure to update the documentation and bash completion when adding the new type to bpftool. You probably want something like the diff below.
Thank you so much. Will incorporate them. Just in case, while it's noted in the head message, I lost the RFC marker while prepping this patch. It isn't yet clear whether we'd really need custom cost functions and this patch is included more as a proof of concept.
the example bpf prog looks flexible enough to allow some degree of experiments. The question is what kind of new algorithms you envision it will do? what other inputs it would need to make a decision? I think it's ok to start with what it does now and extend further when need arises.
Quoted 5 lines
If
it turns out that this is beneficial enough, the followings need to be answered.* Is block ioctl the right mechanism to attach these programs?
imo ioctl is a bit weird, but since its only one program per block device it's probably ok? Unless you see it being cgroup scoped in the future? Then cgroup-bpf style hooks will be more suitable and allow a chain of programs.
Quoted 7 lines
* Are there more parameters that need to be exposed to the programs?
* It'd be great to have efficient access to per-blockdev and per-blockdev-cgroup-pair storages available to these programs so that they can keep track of history. What'd be the best of way of doing that considering the fact that these programs will be called per each IO and the overhead can add up quickly?
Martin's socket local storage solved that issue for sockets. Something very similar can work for per-blockdev-per-cgroup.
Tejun Heo
maintainerRe: [PATCH 10/10] blkcg: implement BPF_PROG_TYPE_IO_COST
Hello, Alexei.
Quoted 5 lines · Alexei Starovoitov
the example bpf prog looks flexible enough to allow some degree of experiments. The question is what kind of new algorithms you envision it will do? what other inputs it would need to make a decision? I think it's ok to start with what it does now and extend further when need arises.
I'm not sure right now. The linear model worked a lot better than I originally expected and looks like it can cover most of the current use cases. It could easily be that we just haven't seen enough different cases yet.
At one point, quadratic model was on the table in case the linear model wasn't good enough. Also, one area which may need improvements could be factoring in r/w mixture into consideration. Some SSDs' performance nose-dive when r/w commands are mixed in certain proportions. Right now, we just deal with that by adjusting global performance ratio (vrate) but I can imagine a model which considers the issue history in the past X seconds of the cgroup and bumps the overall cost according to r/w mixture.
Quoted 6 lines
Quoted 1 line
* Is block ioctl the right mechanism to attach these programs?
imo ioctl is a bit weird, but since its only one program per block device it's probably ok? Unless you see it being cgroup scoped in the future? Then cgroup-bpf style hooks will be more suitable and allow a chain of programs.
As this is a device property, I think there should only be one program per block device.
Quoted 10 lines
Quoted 7 lines
* Are there more parameters that need to be exposed to the programs?
* It'd be great to have efficient access to per-blockdev and per-blockdev-cgroup-pair storages available to these programs so that they can keep track of history. What'd be the best of way of doing that considering the fact that these programs will be called per each IO and the overhead can add up quickly?
Martin's socket local storage solved that issue for sockets. Something very similar can work for per-blockdev-per-cgroup.
Cool, that sounds great in case we need to develop this further. Andy had this self-learning model which didn't need any external input and could tune itself solely based on device saturation state. If the prog can remember states cheaply, it'd be pretty cool to experiment with things like that in bpf.
Thanks.
Signature · 1 line
tejun
Tejun Heo
maintainerOn Thu, Jun 13, 2019 at 06:56:10PM -0700, Tejun Heo wrote:
...
Quoted 3 lines
The patchset is also available in the following git branch.
git://git.kernel.org/pub/scm/linux/kernel/git/tj/cgroup.gitreview-iow
Updated patchset available in the following branch. Just build fixes and cosmetic changes for now.
git://git.kernel.org/pub/scm/linux/kernel/git/tj/cgroup.git review-iow-v2
Thanks.
Signature · 1 line
tejun
Quoted 6 lines
Il giorno 14 giu 2019, alle ore 19:56, Tejun Heo <[email protected]> ha scritto:
On Thu, Jun 13, 2019 at 06:56:10PM -0700, Tejun Heo wrote:
...
Quoted 9 lines
Quoted 3 lines
The patchset is also available in the following git branch.
git://git.kernel.org/pub/scm/linux/kernel/git/tj/cgroup.gitreview-iowUpdated patchset available in the following branch. Just build fixes and cosmetic changes for now.
git://git.kernel.org/pub/scm/linux/kernel/git/tj/cgroup.gitreview-iow-v2
Hi Tejun,
I'm running the kernel in your tree above, in an Ubuntu 18.04.
After unmounting the v1 blkio controller that gets mounted at startup I have created v2 root as follows
$ mount -t cgroup2 none /cgroup
Then I have:
$ ls /cgroup cgroup.controllers cgroup.max.descendants cgroup.stat cgroup.threads io.weight.cost_model system.slice cgroup.max.depth cgroup.procs cgroup.subtree_control init.scope io.weight.qos user.slice
But the following command gives no output:
$ cat /cgroup/io.weight.qos
And, above all,
$ echo 1 > /cgroup/io.weight.qos bash: echo: write error: Invalid argument
No complain in the kernel log.
What am I doing wrong? How can I make the controller work?
Thanks,
Paolo
Quoted 4 lines
Thanks.
Signature · 1 line
tejun
Quoted 36 lines
Il giorno 20 ago 2019, alle ore 12:48, Paolo Valente <[email protected]> ha scritto:
Quoted 4 lines
Il giorno 14 giu 2019, alle ore 19:56, Tejun Heo <[email protected]> ha scritto:
On Thu, Jun 13, 2019 at 06:56:10PM -0700, Tejun Heo wrote:
...Quoted 9 lines
Quoted 3 lines
The patchset is also available in the following git branch.
git://git.kernel.org/pub/scm/linux/kernel/git/tj/cgroup.gitreview-iowUpdated patchset available in the following branch. Just build fixes and cosmetic changes for now.
git://git.kernel.org/pub/scm/linux/kernel/git/tj/cgroup.gitreview-iow-v2Hi Tejun,
I'm running the kernel in your tree above, in an Ubuntu 18.04.After unmounting the v1 blkio controller that gets mounted at startup I have created v2 root as follows
$ mount -t cgroup2 none /cgroupThen I have:
$ ls /cgroup cgroup.controllers cgroup.max.descendants cgroup.stat cgroup.threads io.weight.cost_model system.slice cgroup.max.depth cgroup.procs cgroup.subtree_control init.scope io.weight.qos user.sliceBut the following command gives no output:
$ cat /cgroup/io.weight.qos
Quoted 8 lines
And, above all,
$ echo 1 > /cgroup/io.weight.qos bash: echo: write error: Invalid argumentNo complain in the kernel log.
What am I doing wrong? How can I make the controller work?
I made it, sorry for my usual silly questions (for some reason, I thought the controller could be enabled globally by just passing a 1).
The problem now is that the controller doesn't seem to work. I've emulated 16 clients doing I/O on a SATA SSD. One client, the target, does random reads, while the remaining 15 clients, the interferers, do sequential reads.
Each client is encapsulated in a separate group, but whatever weight is assigned to the target group, the latter gets the same, extremely low bandwidth. I have tried with even the maximum weight ratio, i.e., 1000 for the target and only 1 for each interferer. Here are the results, compared with BFQ (bandwidth in MB/s):
io.weight BFQ
0.2 3.7
I ran this test with the script S/bandwidth-latency/bandwidth-latency.sh of the S benchmark suite [1], invoked as follows:
sudo ./bandwidth-latency.sh -t randread -s none -b weight -n 15 -w 1000 -W 1
The above command simply creates groups, assigns weights as follows
echo 1 > /cgroup/InterfererGroup0/io.weight
echo 1 > /cgroup/InterfererGroup1/io.weight
...
echo 1 > /cgroup/InterfererGroup14/io.weight
echo 1000 > /cgroup/interfered/io.weight
and makes one fio instance generate I/O for each group. The bandwidth reported above is that reported by the fio instance emulating the target client.
Am I missing something?
Thanks,
Paolo
[1] https://github.com/Algodev-github/S
Quoted 8 lines
Thanks,
PaoloQuoted 4 lines
Thanks.
Signature · 1 line
tejun
Tejun Heo
maintainerHello, Paolo.
Quoted 5 lines · Paolo Valente
and makes one fio instance generate I/O for each group. The bandwidth reported above is that reported by the fio instance emulating the target client.
Am I missing something?
If you didn't configure QoS targets, the controller is using device qdepth saturation as the sole guidance in determining whether the device needs throttling. Please try configuring the target latencies. The bandwidth you see for single stream of rand ios should have direct correlation with how the latency targets are configured. The head letter for the patchset has some examples.
Thanks.
Signature · 1 line
tejun
Quoted 11 lines
Il giorno 20 ago 2019, alle ore 17:19, Tejun Heo <[email protected]> ha scritto:
Hello, Paolo.
Quoted 4 lines · Paolo Valente
and makes one fio instance generate I/O for each group. The bandwidth reported above is that reported by the fio instance emulating the target client.
Quoted 9 lines
Quoted 1 line
Am I missing something?
If you didn't configure QoS targets, the controller is using device qdepth saturation as the sole guidance in determining whether the device needs throttling. Please try configuring the target latencies. The bandwidth you see for single stream of rand ios should have direct correlation with how the latency targets are configured. The head letter for the patchset has some examples.
Ok, I tried with the parameters reported for a SATA SSD:
rpct=95.00 rlat=10000 wpct=95.00 wlat=20000 min=50.00 max=400.00
and with a simpler configuration [1]: one target doing random reads and only four interferers doing sequential reads, with all the processes (groups) having the same weight.
But there seemed to be little or no control on I/O, because the target got only 1.84 MB/s, against 1.15 MB/s without any control.
So I tried with rlat=1000 and rlat=100.
Control did improve, with same results for both values of rlat. The problem is that these results still seem rather bad, both in terms of throughput guaranteed to the target and in terms of total throughput. Here are results compared with BFQ (throughputs measured in MB/s):
io.weight BFQ target's throughput 3.415 6.224 total throughput 159.14 321.375
Am I doing something else wrong?
Thanks,
Paolo
[1] sudo ./bandwidth-latency.sh -t randread -s none -b weight -n 4
Quoted 4 lines
Thanks.
Signature · 1 line
tejun
Tejun Heo
maintainerHello, Paolo.
Quoted 3 lines · Paolo Valente
Ok, I tried with the parameters reported for a SATA SSD:
rpct=95.00 rlat=10000 wpct=95.00 wlat=20000 min=50.00 max=400.00
Sorry, I should have explained it with a lot more details.
There are two things - the cost model and qos params. The default SSD cost model parameters are derived by averaging a number of mainstream SSD parameters. As a ballpark, this can be good enough because while the overall performance varied quite a bit from one ssd to another, the relative cost of different types of IOs wasn't drastically different.
However, this means that the performance baseline can easily be way off from 100% depending on the specific device in use. In the above, you're specifying min/max which limits how far the controller is allowed to adjust the overall cost estimation. 50% and 400% are numbers which may make sense if the cost model parameter is expected to fall somewhere around 100% - ie. if the parameters are for that specific device.
In your script, you're using default model params but limiting vrate range. It's likely that your device is significantly slower than what the default parameters are expecting. However, because min vrate is limited to 50%, it doesn't throttle below 50% of the estimated cost, so if the device is significantly slower than that, nothing gets controlled.
Quoted 1 line
and with a simpler configuration [1]: one target doing random reads
And without QoS latency targets, the controller is purely going by queue depth depletion which works fine for many usual workloads such as larger reads and writes but isn't likely to serve low-concurrency latency-sensitive IOs well.
Quoted 7 lines
and only four interferers doing sequential reads, with all the processes (groups) having the same weight.
But there seemed to be little or no control on I/O, because the target got only 1.84 MB/s, against 1.15 MB/s without any control.
So I tried with rlat=1000 and rlat=100.
And this won't do anything as all rlat/wlat does is regulating how the overall vrate should be adjusted and it's being min'd at 50%.
Quoted 8 lines
Control did improve, with same results for both values of rlat. The problem is that these results still seem rather bad, both in terms of throughput guaranteed to the target and in terms of total throughput. Here are results compared with BFQ (throughputs measured in MB/s):
io.weight BFQ target's throughput 3.415 6.224 total throughput 159.14 321.375
So, what should have been configured is something like
$ echo '8:0 enable=1 rpct=95 rlat=10000 wpct=95 wlat=20000' > /sys/fs/cgroup/io.cost.qos
which just says "target 10ms p(95) read latency and 20ms p(95) write latency" without putting any restrictions on vrate range.
With that, I got the following on Micron_1100_MTFDDAV256TBN which is a pretty old 256GB SATA drive.
Aggregated throughput:
min max avg std_dev conf99% 266.73 275.71 271.38 4.05144 45.7635 Interfered total throughput: min max avg std_dev 9.608 13.008 10.941 0.664938
During the run, iocost-monitor.py looked like the following.
sda RUN per=40ms cur_per=2074.351:v1008.844 busy= +0 vrate= 59.85% params=ssd_dfl(CQ)
active weight hweight% inflt% del_ms usages%
InterfererGroup0 * 100/ 100 22.94/ 20.00 0.00 0*000 023:023:023 InterfererGroup1 * 100/ 100 22.94/ 20.00 0.00 0*000 023:023:023 InterfererGroup2 * 100/ 100 22.94/ 20.00 0.00 0*000 025:023:021 InterfererGroup3 * 100/ 100 22.94/ 20.00 0.00 0*000 023:023:023 interfered * 36/ 100 8.26/ 20.00 0.42 0*000 003:004:004
Note that interfered is reported to only use 3-4% of the disk capacity while configured to consume 20%. This is because with single concurrency 4k randread job, its ability to consume IO capacity is limited by the completion latency.
10ms is pretty generous (ie. more work-conserving) target for SSDs. Let's say we're willing to tighten it to trade off total work for tighter latency.
$ echo '8:0 enable=1 rpct=95 rlat=2500 wpct=95 wlat=5000' > /sys/fs/cgroup/io.cost.qos
Aggregated throughput:
min max avg std_dev conf99% 147.06 172.18 154.608 11.783 133.096 Interfered total throughput: min max avg std_dev 17.992 19.32 18.698 0.313105
and the monitoring output
sda RUN per=10ms cur_per=2927.152:v1556.138 busy= -2 vrate= 34.74% params=ssd_dfl(CQ)
active weight hweight% inflt% del_ms usages%
InterfererGroup0 * 100/ 100 20.00/ 20.00 386.11 0*000 070:020:020 InterfererGroup1 * 100/ 100 20.00/ 20.00 386.11 0*000 070:020:020 InterfererGroup2 * 100/ 100 20.00/ 20.00 386.11 0*000 070:020:020 InterfererGroup3 * 100/ 100 20.00/ 20.00 0.00 0*000 020:020:020 interfered * 100/ 100 20.00/ 20.00 1.21 0*000 010:014:017
The followings happened.
* The vrate is now hovering way lower. The device is now doing less total work to acheive tighter completion latencies.
* The overall throughput dropped but interfered's utilization is now significantly higher along with its bandwidth from lower completion latencies.
For reference:
[Disabled]
Aggregated throughput:
min max avg std_dev conf99% 493.98 511.37 502.808 9.52773 107.621 Interfered total throughput: min max avg std_dev 0.056 0.304 0.107 0.0691052
[Enabled, no QoS config]
Aggregated throughput:
min max avg std_dev conf99% 429.07 449.59 437.597 8.64952 97.7015 Interfered total throughput: min max avg std_dev 0.456 3.12 1.08 0.774318
Thanks.
Signature · 1 line
tejun
Hi Tejun,
thank you very much for this extra information, I'll try the configuration you suggest. In this respect, is this still the branch to use
https://kernel.googlesource.com/pub/scm/linux/kernel/git/tj/cgroup/+/refs/heads/review-iocost-v2
also after the issue spotted two days ago [1]?
Thanks,
Paolo
[1] https://lkml.org/lkml/2019/8/29/910
Quoted 148 lines
Il giorno 31 ago 2019, alle ore 08:53, Tejun Heo <[email protected]> ha scritto:
Hello, Paolo.
Quoted 3 lines · Paolo Valente
Ok, I tried with the parameters reported for a SATA SSD:
rpct=95.00 rlat=10000 wpct=95.00 wlat=20000 min=50.00 max=400.00
Sorry, I should have explained it with a lot more details.
There are two things - the cost model and qos params. The default SSD cost model parameters are derived by averaging a number of mainstream SSD parameters. As a ballpark, this can be good enough because while the overall performance varied quite a bit from one ssd to another, the relative cost of different types of IOs wasn't drastically different.
However, this means that the performance baseline can easily be way off from 100% depending on the specific device in use. In the above, you're specifying min/max which limits how far the controller is allowed to adjust the overall cost estimation. 50% and 400% are numbers which may make sense if the cost model parameter is expected to fall somewhere around 100% - ie. if the parameters are for that specific device.
In your script, you're using default model params but limiting vrate range. It's likely that your device is significantly slower than what the default parameters are expecting. However, because min vrate is limited to 50%, it doesn't throttle below 50% of the estimated cost, so if the device is significantly slower than that, nothing gets controlled.
Quoted 1 line
and with a simpler configuration [1]: one target doing random reads
And without QoS latency targets, the controller is purely going by queue depth depletion which works fine for many usual workloads such as larger reads and writes but isn't likely to serve low-concurrency latency-sensitive IOs well.
Quoted 7 lines
and only four interferers doing sequential reads, with all the processes (groups) having the same weight.
But there seemed to be little or no control on I/O, because the target got only 1.84 MB/s, against 1.15 MB/s without any control.
So I tried with rlat=1000 and rlat=100.
And this won't do anything as all rlat/wlat does is regulating how the overall vrate should be adjusted and it's being min'd at 50%.
Quoted 8 lines
Control did improve, with same results for both values of rlat. The problem is that these results still seem rather bad, both in terms of throughput guaranteed to the target and in terms of total throughput. Here are results compared with BFQ (throughputs measured in MB/s):
io.weight BFQ
target's throughput 3.415 6.224 total throughput 159.14 321.375So, what should have been configured is something like
$ echo '8:0 enable=1 rpct=95 rlat=10000 wpct=95 wlat=20000' > /sys/fs/cgroup/io.cost.qoswhich just says "target 10ms p(95) read latency and 20ms p(95) write latency" without putting any restrictions on vrate range.
With that, I got the following on
Micron_1100_MTFDDAV256TBNwhich is a pretty old 256GB SATA drive.Aggregated throughput:
min max avg std_dev conf99% 266.73 275.71 271.38 4.05144 45.7635 Interfered total throughput: min max avg std_dev 9.608 13.008 10.941 0.664938During the run,
iocost-monitor.pylooked like the following.sda RUN per=40ms cur_per=2074.351:v1008.844 busy= +0 vrate= 59.85% params=ssd_dfl(CQ)
active weight hweight% inflt%del_msusages%InterfererGroup0 * 100/ 100 22.94/ 20.00 0.00 0*000 023:023:023 InterfererGroup1 * 100/ 100 22.94/ 20.00 0.00 0*000 023:023:023 InterfererGroup2 * 100/ 100 22.94/ 20.00 0.00 0*000 025:023:021 InterfererGroup3 * 100/ 100 22.94/ 20.00 0.00 0*000 023:023:023 interfered * 36/ 100 8.26/ 20.00 0.42 0*000 003:004:004Note that interfered is reported to only use 3-4% of the disk capacity while configured to consume 20%. This is because with single concurrency 4k randread job, its ability to consume IO capacity is limited by the completion latency.
10ms is pretty generous (ie. more work-conserving) target for SSDs. Let's say we're willing to tighten it to trade off total work for tighter latency.
$ echo '8:0 enable=1 rpct=95 rlat=2500 wpct=95 wlat=5000' > /sys/fs/cgroup/io.cost.qosAggregated throughput:
min max avg std_dev conf99% 147.06 172.18 154.608 11.783 133.096 Interfered total throughput: min max avg std_dev 17.992 19.32 18.698 0.313105and the monitoring output
sda RUN per=10ms cur_per=2927.152:v1556.138 busy= -2 vrate= 34.74% params=ssd_dfl(CQ)
active weight hweight% inflt%del_msusages%InterfererGroup0 * 100/ 100 20.00/ 20.00 386.11 0*000 070:020:020 InterfererGroup1 * 100/ 100 20.00/ 20.00 386.11 0*000 070:020:020 InterfererGroup2 * 100/ 100 20.00/ 20.00 386.11 0*000 070:020:020 InterfererGroup3 * 100/ 100 20.00/ 20.00 0.00 0*000 020:020:020 interfered * 100/ 100 20.00/ 20.00 1.21 0*000 010:014:017The followings happened.
* The vrate is now hovering way lower. The device is now doing less total work to acheive tighter completion latencies.
* The overall throughput dropped but interfered's utilization is now significantly higher along with its bandwidth from lower completion latencies.
For reference:
[Disabled]
Aggregated throughput:
min max avg std_dev conf99% 493.98 511.37 502.808 9.52773 107.621 Interfered total throughput: min max avg std_dev 0.056 0.304 0.107 0.0691052[Enabled, no QoS config]
Aggregated throughput:
min max avg std_dev conf99% 429.07 449.59 437.597 8.64952 97.7015 Interfered total throughput: min max avg std_dev 0.456 3.12 1.08 0.774318Thanks.
Signature · 1 line
tejun
Tejun Heo
maintainerHello,
Quoted 8 lines · Paolo Valente
Hi Tejun,
thank you very much for this extra information, I'll try the configuration you suggest. In this respect, is this still the branch to usehttps://kernel.googlesource.com/pub/scm/linux/kernel/git/tj/cgroup/+/refs/heads/review-iocost-v2
also after the issue spotted two days ago [1]?
block/for-next is the branch which has all the updates.
git://git.kernel.org/pub/scm/linux/kernel/git/axboe/linux-block.git for-next
Thanks.
Signature · 1 line
tejun
Quoted 6 lines
Il giorno 31 ago 2019, alle ore 08:53, Tejun Heo <[email protected]> ha scritto:
Hello, Paolo.
Hi Tejun,
Quoted 22 lines · Paolo Valente
Quoted 3 lines
Ok, I tried with the parameters reported for a SATA SSD:
rpct=95.00 rlat=10000 wpct=95.00 wlat=20000 min=50.00 max=400.00
Sorry, I should have explained it with a lot more details.
There are two things - the cost model and qos params. The default SSD cost model parameters are derived by averaging a number of mainstream SSD parameters. As a ballpark, this can be good enough because while the overall performance varied quite a bit from one ssd to another, the relative cost of different types of IOs wasn't drastically different.
However, this means that the performance baseline can easily be way off from 100% depending on the specific device in use. In the above, you're specifying min/max which limits how far the controller is allowed to adjust the overall cost estimation. 50% and 400% are numbers which may make sense if the cost model parameter is expected to fall somewhere around 100% - ie. if the parameters are for that specific device.
Quoted 7 lines
In your script, you're using default model params but limiting vrate range. It's likely that your device is significantly slower than what the default parameters are expecting. However, because min vrate is limited to 50%, it doesn't throttle below 50% of the estimated cost, so if the device is significantly slower than that, nothing gets controlled.
Thanks for this extra explanations. It is a little bit difficult for me to understand how the min/max teaks for exactly, but you did give me the general idea.
Quoted 23 lines
Quoted 1 line
and with a simpler configuration [1]: one target doing random reads
And without QoS latency targets, the controller is purely going by queue depth depletion which works fine for many usual workloads such as larger reads and writes but isn't likely to serve low-concurrency latency-sensitive IOs well.
Quoted 7 lines
and only four interferers doing sequential reads, with all the processes (groups) having the same weight.
But there seemed to be little or no control on I/O, because the target got only 1.84 MB/s, against 1.15 MB/s without any control.
So I tried with rlat=1000 and rlat=100.
And this won't do anything as all rlat/wlat does is regulating how the overall vrate should be adjusted and it's being min'd at 50%.
Quoted 5 lines
Control did improve, with same results for both values of rlat. The problem is that these results still seem rather bad, both in terms of throughput guaranteed to the target and in terms of total throughput. Here are results compared with BFQ (throughputs measured in MB/s):
Quoted 8 lines
Quoted 3 lines
io.weight BFQ
target's throughput 3.415 6.224 total throughput 159.14 321.375So, what should have been configured is something like
$ echo '8:0 enable=1 rpct=95 rlat=10000 wpct=95 wlat=20000' > /sys/fs/cgroup/io.cost.qos
Unfortunately, io.cost does not seem to control I/O with this configuration, as it gives the interfered the same bw as no I/O control (i.e., none as I/O scheduler and no I/O controller or policy active):
none io.weight BFQ
target's throughput 0.8 0.7 4 total throughput 506 506 344
The test case is still the rand reader against 7 seq readers.
Quoted 28 lines
which just says "target 10ms p(95) read latency and 20ms p(95) write latency" without putting any restrictions on vrate range.
With that, I got the following on
Micron_1100_MTFDDAV256TBNwhich is a pretty old 256GB SATA drive.Aggregated throughput:
min max avg std_dev conf99% 266.73 275.71 271.38 4.05144 45.7635 Interfered total throughput: min max avg std_dev 9.608 13.008 10.941 0.664938During the run,
iocost-monitor.pylooked like the following.sda RUN per=40ms cur_per=2074.351:v1008.844 busy= +0 vrate= 59.85% params=ssd_dfl(CQ)
active weight hweight% inflt%del_msusages%InterfererGroup0 * 100/ 100 22.94/ 20.00 0.00 0*000 023:023:023 InterfererGroup1 * 100/ 100 22.94/ 20.00 0.00 0*000 023:023:023 InterfererGroup2 * 100/ 100 22.94/ 20.00 0.00 0*000 025:023:021 InterfererGroup3 * 100/ 100 22.94/ 20.00 0.00 0*000 023:023:023 interfered * 36/ 100 8.26/ 20.00 0.42 0*000 003:004:004Note that interfered is reported to only use 3-4% of the disk capacity while configured to consume 20%. This is because with single concurrency 4k randread job, its ability to consume IO capacity is limited by the completion latency.
Quoted 6 lines
10ms is pretty generous (ie. more work-conserving) target for SSDs. Let's say we're willing to tighten it to trade off total work for tighter latency.
$ echo '8:0 enable=1 rpct=95 rlat=2500 wpct=95 wlat=5000' > /sys/fs/cgroup/io.cost.qos
Now io.weight does control I/O, but throughputs fluctuate a lot between runs and during each run. After extending the duration of each run to 20 seconds, an average run for io.weight and BFQ gives the following throughputs (same throughputs as above for none):
none io.weight BFQ target's throughput 0.8 2.3 3.6 total throughput 506 321 360
For completeness I tried also with rlat=1000. But throughputs dropped dramatically:
none io.weight BFQ
target's throughput 0.8 0.2 3.6 total throughput 506 17 360
Are these results in line with your expectations? If they are, then I'd like to extend benchmarks to more mixes of workloads. Or should I try some other QoS configuration first?
Thanks,
Paolo
Quoted 50 lines
Aggregated throughput:
min max avg std_dev conf99% 147.06 172.18 154.608 11.783 133.096 Interfered total throughput: min max avg std_dev 17.992 19.32 18.698 0.313105and the monitoring output
sda RUN per=10ms cur_per=2927.152:v1556.138 busy= -2 vrate= 34.74% params=ssd_dfl(CQ)
active weight hweight% inflt%del_msusages%InterfererGroup0 * 100/ 100 20.00/ 20.00 386.11 0*000 070:020:020 InterfererGroup1 * 100/ 100 20.00/ 20.00 386.11 0*000 070:020:020 InterfererGroup2 * 100/ 100 20.00/ 20.00 386.11 0*000 070:020:020 InterfererGroup3 * 100/ 100 20.00/ 20.00 0.00 0*000 020:020:020 interfered * 100/ 100 20.00/ 20.00 1.21 0*000 010:014:017The followings happened.
* The vrate is now hovering way lower. The device is now doing less total work to acheive tighter completion latencies.
* The overall throughput dropped but interfered's utilization is now significantly higher along with its bandwidth from lower completion latencies.
For reference:
[Disabled]
Aggregated throughput:
min max avg std_dev conf99% 493.98 511.37 502.808 9.52773 107.621 Interfered total throughput: min max avg std_dev 0.056 0.304 0.107 0.0691052[Enabled, no QoS config]
Aggregated throughput:
min max avg std_dev conf99% 429.07 449.59 437.597 8.64952 97.7015 Interfered total throughput: min max avg std_dev 0.456 3.12 1.08 0.774318Thanks.
Signature · 1 line
tejun
Tejun Heo
maintainerQuoted 3 lines · Paolo Valente
Thanks for this extra explanations. It is a little bit difficult for me to understand how the min/max teaks for exactly, but you did give me the general idea.
It just limits how far high and low the IO issue rate, measured in cost, can go. ie. if max is at 200%, the controller won't issue more than twice of what the cost model says 100% is.
Quoted 3 lines
Are these results in line with your expectations? If they are, then I'd like to extend benchmarks to more mixes of workloads. Or should I try some other QoS configuration first?
They aren't. Can you please include the content of io.cost.qos and io.cost.model before each run? Note that partial writes to subset of parameters don't clear other parameters.
Thanks.
Signature · 1 line
tejun
Quoted 13 lines
Il giorno 2 set 2019, alle ore 17:56, Tejun Heo <[email protected]> ha scritto:
Quoted 3 lines · Paolo Valente
Thanks for this extra explanations. It is a little bit difficult for me to understand how the min/max teaks for exactly, but you did give me the general idea.
It just limits how far high and low the IO issue rate, measured in cost, can go. ie. if max is at 200%, the controller won't issue more than twice of what the cost model says 100% is.
Quoted 8 lines
Quoted 3 lines
Are these results in line with your expectations? If they are, then I'd like to extend benchmarks to more mixes of workloads. Or should I try some other QoS configuration first?
They aren't. Can you please include the content of io.cost.qos and io.cost.model before each run? Note that partial writes to subset of parameters don't clear other parameters.
Yep. I've added the printing of the two parameters in the script, and I'm pasting the whole output, in case you could get also some other useful piece of information from it.
$ sudo ./bandwidth-latency.sh -t randread -s none -b weight -n 7 -d 20 Switching to none for sda echo "8:0 enable=1 rpct=95 rlat=2500 wpct=95 wlat=5000" > /cgroup/io.cost.qos /cgroup/io.cost.qos 8:0 enable=1 ctrl=user rpct=95.00 rlat=2500 wpct=95.00 wlat=5000 min=1.00 max=10000.00 /cgroup/io.cost.model 8:0 ctrl=auto model=linear rbps=488636629 rseqiops=8932 rrandiops=8518 wbps=427891549 wseqiops=28755 wrandiops=21940 Not changing weight/limits for interferer group 0 Not changing weight/limits for interferer group 1 Not changing weight/limits for interferer group 2 Not changing weight/limits for interferer group 3 Not changing weight/limits for interferer group 4 Not changing weight/limits for interferer group 5 Not changing weight/limits for interferer group 6 Not changing weight/limits for interfered Starting Interferer group 0 start_fio_jobs InterfererGroup0 0 default read MAX linear 1 1 0 0 4k /home/paolo/local-S/bandwidth-latency/../workfiles/largefile0 Starting Interferer group 1 start_fio_jobs InterfererGroup1 0 default read MAX linear 1 1 0 0 4k /home/paolo/local-S/bandwidth-latency/../workfiles/largefile1 Starting Interferer group 2 start_fio_jobs InterfererGroup2 0 default read MAX linear 1 1 0 0 4k /home/paolo/local-S/bandwidth-latency/../workfiles/largefile2 Starting Interferer group 3 start_fio_jobs InterfererGroup3 0 default read MAX linear 1 1 0 0 4k /home/paolo/local-S/bandwidth-latency/../workfiles/largefile3 Starting Interferer group 4 start_fio_jobs InterfererGroup4 0 default read MAX linear 1 1 0 0 4k /home/paolo/local-S/bandwidth-latency/../workfiles/largefile4 Starting Interferer group 5 start_fio_jobs InterfererGroup5 0 default read MAX linear 1 1 0 0 4k /home/paolo/local-S/bandwidth-latency/../workfiles/largefile5 Starting Interferer group 6 start_fio_jobs InterfererGroup6 0 default read MAX linear 1 1 0 0 4k /home/paolo/local-S/bandwidth-latency/../workfiles/largefile6 Linux 5.3.0-rc6+ (paolo-ThinkPad-W520) 02/09/2019 _x86_64_ (8 CPU)
02/09/2019 21:39:11
Device tps MB_read/s MB_wrtn/s MB_read MB_wrtn
sda 66.53 5.22 0.10 1385 27
start_fio_jobs interfered 20 default randread MAX poisson 1 1 0 0 4k /home/paolo/local-S/bandwidth-latency/../workfiles/largefile_interfered0 02/09/2019 21:39:14
Device tps MB_read/s MB_wrtn/s MB_read MB_wrtn
sda 154.67 20.63 0.05 61 0
02/09/2019 21:39:17
Device tps MB_read/s MB_wrtn/s MB_read MB_wrtn
sda 453.00 64.27 0.00 192 0
02/09/2019 21:39:20
Device tps MB_read/s MB_wrtn/s MB_read MB_wrtn
sda 675.33 95.99 0.00 287 0
02/09/2019 21:39:23
Device tps MB_read/s MB_wrtn/s MB_read MB_wrtn
sda 1907.67 348.61 0.00 1045 0
02/09/2019 21:39:26
Device tps MB_read/s MB_wrtn/s MB_read MB_wrtn
sda 2414.67 462.98 0.00 1388 0
02/09/2019 21:39:29
Device tps MB_read/s MB_wrtn/s MB_read MB_wrtn
sda 2429.67 438.71 0.00 1316 0
02/09/2019 21:39:32
Device tps MB_read/s MB_wrtn/s MB_read MB_wrtn
sda 2437.00 475.79 0.00 1427 0
02/09/2019 21:39:35
Device tps MB_read/s MB_wrtn/s MB_read MB_wrtn
sda 2162.33 346.97 0.00 1040 0
Results for one rand reader against 7 seq readers (I/O depth 1), weight-none with weights: (default, default) Aggregated throughput:
min max avg std_dev conf99%
64.27 475.79 319.046 171.233 1011.97
Read throughput:
min max avg std_dev conf99%
64.27 475.79 319.046 171.233 1011.97Write throughput:
min max avg std_dev conf99%
0 0 0 0 0
Interfered total throughput:
min max avg std_dev
1.032 4.455 2.266 0.742696
Interfered per-request total latency:
min max avg std_dev
0.11 12.005 1.7545 0.878281
Thanks,
Paolo
Quoted 4 lines
Thanks.
Signature · 1 line
tejun
Tejun Heo
maintainerHello, Paolo.
So, I'm currently verifying iocost in the FB fleet. Around three thousand machines running v5.2 (+ some backports) with btrfs on a handful of different models of consumer grade SSDs. I haven't seen complete loss of control as you're reporting. Given that you're reporting the same thing on io.latency, which is deployed on multiple orders of magnitude more machines at this point, it's likely that there's something common affecting your test setup. Can you please describe your test configuration and if you aren't already try testing on btrfs?
Thanks.
Signature · 1 line
tejun
Quoted 6 lines
Il giorno 5 set 2019, alle ore 18:55, Tejun Heo <[email protected]> ha scritto:
Hello, Paolo.
Quoted 7 lines
So, I'm currently verifying iocost in the FB fleet. Around three thousand machines running v5.2 (+ some backports) with btrfs on a handful of different models of consumer grade SSDs. I haven't seen complete loss of control as you're reporting. Given that you're reporting the same thing on io.latency, which is deployed on multiple orders of magnitude more machines at this point, it's likely that there's something common affecting your test setup.
Yep, I had that doubt too, so I extended my tests to one more PC and two more drives: a fast SAMSUNG NVMe SSD 970 PRO and an HITACHI HTS72755 HDD, using the QoS configurations suggested in your last email. As for the filesystem, I'm interested in ext4, because it is the most widely used file system, and, with some workloads, it makes it hard to control I/O while keeping throughput high. I'll provide hw and sw details in my reply to your next question. I'm willing to run tests with btrfs too, at a later time.
Something is wrong with io.cost also with the other PC and the other drives. In the next table, each pair of numbers contains the target's throughput and the total throughput:
none io.cost bfq
SAMSUNG SSD 11.373 3295.517 6.468 3273.892 10.802 1862.288 HITACHI HDD 0.026 11.531 0.042 30.299 0.067 76.642
With the SAMSUNG SSD, io.cost gives to the target less throughput than none (and bfq is behaving badly too, but this is my problem). On the HDD, io.cost gives to the target a little bit more than half the throughput guaranteed by bfq, and reaches less than half the total throughput reached by bfq.
I do agree that three thousand is an overwhelming number of machines, and I'll probably never have that many resources for my tests. Still, it seems rather unlikely that two different PCs, and three different drives, all suffer from a common anomaly that causes troubles only to io.cost and io.latency.
I try to never overlook also me being the problematic link in the chain. But I'm executing this test with the public script I mentioned in my previous emails; and all steps seem correct.
Quoted 4 lines
Can you please
describe your test configuration and if you aren't already try testing on btrfs?
PC 1: Thinkpad W520, Ubuntu 18.04 (no configuration change w.r.t. defaults), PLEXTOR SATA PX-256M5S SSD, HITACHI HTS72755 HDD, ext4.
PC 2: Thinkpad X1 Extreme, Ubuntu 19.04 (no configuration change w.r.t. defaults), SAMSUNG NVMe SSD 970 PRO, ext4.
If you need more details, just ask.
Thanks,
Paolo
Quoted 4 lines
Thanks.
Signature · 1 line
tejun
Tejun Heo
maintainerHello, Paolo.
Quoted 2 lines · Paolo Valente
email. As for the filesystem, I'm interested in ext4, because it is the most widely used file system, and, with some workloads, it makes
Ext4 can't do writeback control as it currently stands. It creates hard ordering across data writes from different cgroups. No matter what mechanism you use for IO control, it is broken. I'm sure it's fixable but does need some work.
That said, read-only tests like you're doing should work fine on ext4 too but the last time I tested io control on ext4 is more than a year ago so something might have changed in the meantime.
Just to rule out this isn't what you're hitting. Can you please run your test on btrfs with the following patchset applied?
http://lkml.kernel.org/r/[email protected]
And as I wrote in the previous reply, I did run your benchmark on one of the test machines and it did work fine.
Thanks.
Signature · 1 line
tejun
Hi Tejun
sorry for the long delay, but, before replying, I preferred to analyze io.cost deeply.
Quoted 4 lines
Il giorno 6 set 2019, alle ore 16:58, Tejun Heo <[email protected]> ha scritto:
Hello, Paolo.
Quoted 9 lines
Quoted 2 lines · Paolo Valente
email. As for the filesystem, I'm interested in ext4, because it is the most widely used file system, and, with some workloads, it makes
Ext4 can't do writeback control as it currently stands. It creates hard ordering across data writes from different cgroups. No matter what mechanism you use for IO control, it is broken. I'm sure it's fixable but does need some work.
Yep. However, with read+write mixes, bfq controls I/O while io.cost fails.
Quoted 9 lines
That said, read-only tests like you're doing should work fine on ext4 too but the last time I tested io control on ext4 is more than a year ago so something might have changed in the meantime.
Just to rule out this isn't what you're hitting. Can you please run your test on btrfs with the following patchset applied?
I've run tests with btrfs too, things get better, but the same issues show up with other workloads. This is one of the reasons why I decided to analyze the problem more deeply (see below).
Quoted 3 lines
And as I wrote in the previous reply, I did run your benchmark on one of the test machines and it did work fine.
To address this issue we repeated the same tests on a lot of different drives and machines. Here is a list:
- PLEXTOR SATA PX-256M5S SSD, mounted on a Thinkpad W520
- HITACHI HTS72755 HDD, mounted on a Thinkpad W520
- WDC WD10JPVX-22JC3T0 HDD, mounted on an Acer V3-572G-75CA
- TOSHIBA MQ04ABF1 HDD, mounted on a Dell G5 5590
- Samsung SSD 860 (500GB), mounted on ThinkPad X1 Extreme
Same outcome.
So, as I wrote above, I decided to analyze io.cost in depth, and to try to understand why it fails with some workloads. I've been writing my findings in an article.
I'm pasting the latex source of the (relatively long) section of this article devoted to explaining the failures of io.cost with come workloads. If this text is not enough, I'm willing to share the full article privately.
In this section we provide an explanation for each of the two failures of \iocost shown in the previous figures for some workloads: failure to guarantee a fair bandwidth distribution and failure to reach a high throughput. Then, in view of these explanations, we point out why \bfq does not suffer from this problem. Let us start by stating the root cause for both failures.
Drives have very complex transfer functions, because of multiple channels, in-channel pipelines, striping, locality-dependent parallelism, \emph{readahead}, I/O-request reordering, garbage collection, wearing, ... In particular, these features make the parameters of transfer functions non-linear, and variable with time and workloads. They also make these parameters hard to know or to compute precisely. Yet virtually all parameters of a transfer function play a non-negligible role in the actual behavior of a drive.
This important issue affects \iocost, because \iocost controls I/O by using exactly two time-varying, and hard-to-know-precisely parameters (of the transfer function of a drive). Incidentally, \iolatency controls I/O with a throttling logic somehow similar to that of \iocost, but based on much poorer knowledge of the transfer function of the drive.
The parameters used by \iocost are I/O costs and device-rate saturation. I/O costs affect the effectiveness of \iocost in both distributing bandwidth fairly and reaching a high throughput. We analyze the way I/O costs are involved in the fair-bandwidth-distribution failure first. Then we consider device saturation, which is involved only in the failure in reaching a high throughput.
\iocost currently uses a linear-cost model, where each I/O is classified as sequential or random, and as a read or a write. Each class of I/O is assigned a base cost and a cost coefficient. The cost of an I/O request is then computed as the sum of the base cost for its class of I/O, and of a variable cost, equal to the cost coefficient for its class of I/O multiplied by the size of the I/O. Using these estimated I/O costs, \iocost estimates the service received by each group, and tries to let each active group receive an amount of estimated service proportional to its weight. \iocost attains this goal by throttling groups that would receive more than their target service if not suspended for a while.
Both the base cost and the cost coefficient for an I/O request depend only on the class of I/O of the request, and are independent of any other parameter. In contrast, because of the opposite effects of, on one side, interference by other groups, and, on the other side, parallelism, pipelining, and any other sort of drive internal optimization, both the actual base cost of the same I/O request, and the very law by which the total cost of the request grows with the size of the request, may vary greatly with the workload mix and with the time. So they may vary even as a function of how \iocost itself modifies the I/O pattern by throttling groups. Finally, I/O workloads---and therefore I/O costs---may vary with the filesystem too, given the same sequence of userspace I/O operations.
The resulting deviations between estimated and actual I/O costs may lead to deviations between the estimated and the actual amounts of service received by groups, and therefore to bandwidth distributions that, for the same set of group weights, may deviate highly from each other, and from fair distributions. Before showing this problem at work in one of the benchmarks, we need to introduce one more bit of information on \iocost.
\iocost does take into account issues stemming from an inaccurate model; but only in terms of consequences on (total) throughput. In particular, to avoid that throughput drops because too much drive time is being granted to a low-throughput group, \iocost dynamically adjusts group weights internally, so as to make each group donate time to other groups, if this donation increases total throughput without penalizing the donor.
Yet, the above deviation between estimated and actual amounts of service may make it much more difficult, or just impossible, for this feedback-loop to converge to weight adjustments that are stable and reach a high throughput.
This last problem may be exacerbated by two more issues. First \iocost evaluates the service surplus or lag for a group by comparing the---possibly wrongly---estimated service received by the group with a threshold computed heuristically. In particular, this threshold is not computed as a function of the dynamically varying parameters of the transfer function of the drive. Secondly, weights are correctly changed in a direction that tends to bring target quantities back in the heuristically accepted ranges, but changes are heuristically applied with a timing and an intensity that does not take into account how and with what delay these changes modify I/O costs and target quantities themselves.
Depending on the actual transfer function of a drive, the combination of these imprecise-estimation and heuristic-update issues may make it hard for \iocost to control per-group I/O bandwidths in a stable and effective way. A real-life example may make it easier to understand the problem. After this example, we will finally apply the above facts to one of the scenarios in which \iocost fails to distribute bandwidths fairly.
Consider a building where little or no care has been put in implementing a stable and easy-to-control water-heating system. Enforcing a fair I/O bandwidth distribution, while at the same time using most of the speed of the drive, is as difficult as getting the shower temperature right in such a building. Knob rotations stimulate, non-linearly, a non-linear system that reacts with time-varying delays. Until we become familiar with the system, we know its parameters so little that we have almost no control on the temperature of the water. In addition, even after we make it to get the temperature we desire, changes in the rest of the system (e.g., one more shower open) may change parameters so much to make us burn ourselves with no action from our side!
The authors of \iocost and \iolatency did make it to get the right temperature for their \emph{showers}, because, most certainly, they patiently and skillfully tuned parameters, and modified algorithms where/as needed. But the same tweaks may not work on different systems. If a given I/O-cost model and feedback-loop logic do not comply with some parameters of the transfer function of a drive, then it may be hard or impossible to find a QoS and I/O-cost configuration that work.
We can now dive into the details of a failure case. We instrumented \iocost so as to trace the value of some of its internal parameters~\cite{io.cost-tracing} over time. Group weights are one of the traced parameters. Figure~\ref{fig:group-weights} shows the values of the weights of the target and of one of the interferers (all interferers exhibit the same weight fluctuation) during the benchmark whose results are shown in the third subplot in Figure~\ref{fig:SSD-rand-interferers}. In this subplot, a target doing sequential reads eats almost all the bandwidth, at the expense of interferers doing random reads. As for weights, \iocost detects, cyclically, that interferers get a service surplus, and therefore it cyclically lowers their weights, progressively but very quickly. Then this make the estimated service of the interfers lag above the threshold, which triggers a weight reset. At this point, the loop restarts.
The negligible total bandwidth obtained by interferers clearly shows that \iocost is throttling interferers too much, because of their I/O cost, and is also lowering interferer weights too much. The periodic weight reset does not balance the problem.
\begin{figure}
\includegraphics[width=\textwidth]{plots/weights-seq_rd_vs_rand_rd.png} \caption{Per-group weights during the benchmark.} \label{fig:group-weights}
\end{figure}
The other failure of \iocost concerns reaching a high throughput. To describe this failure we need to add one last bit of information on \iocost internals. \iocost dispatches I/O to the drive at an overall rate proportional to a quantity named \emph{virtual rate} (\vrate). \iocost dynamically adjusts the \vrate, so as to try to keep the drive always close to saturation, but not overloaded. To this goal, \iocost computes, heuristically, the \emph{busy level} of the drive, as a function of, first, the number of groups in service surplus and the number of groups lagging behind their target service, and, secondly, of I/O-request latencies. So, all the inaccuracy issues pointed out so far may affect the computation of the busy level and thus of the \vrate, plus the following extra issue.
Some I/O flows may suffer from a high or low per-request latency even if the device is actually not so close or very close to saturation, respectively. This may happen because of the nature of the flows, because of interference, or because of both reasons. So, depending on the I/O pattern, the same per-requests latency may have a different meaning in terms of actual device saturation. In this respect, \iocost itself modifies the I/O pattern by changing the \vrate. But, to evaluate saturation, \iocost compares request latencies with a heuristic, fixed threshold, and compares the number of requests above threshold with a further heuristic, fixed threshold. Unfortunately, these fixed thresholds do not and cannot take the above facts into account (thresholds can be modified by the user, but this does not change the essence of the problem).
The combination of all these issues may lead \iocost to lower or increase \vrate wrongly, and to establish a \vrate fluctuation that neither ends nor converges, at least on average, to a good I/O throughput. This is exactly what happens during the throughput failure reported in the third subplot in Figure~\ref{fig:SSD-seq-interferers} (both target and interferers doing sequential reads). Figure ~\ref{fig:vrate} shows the curves for the busy level, the number of groups detected as lagging and finally the \vrate (all traced with our tracing patch~\cite{io.cost-tracing}). The \vrate starts with a relatively high, although fluctuating, value. Yet, around time 10, \iocost detects a sudden rise of the busy level, which triggers a sudden drop of \vrate. \vrate remains stably low until time $\sim$23, when \iocost detects a low busy level and raises \vrate. But this raising causes a new rising of the busy level, which this time goes on for a while, causing \iocost to lower \vrate much more. Finally, from about time 23, the number of groups lagging starts to grow, which convinces \iocost to begin increasing the \vrate (slowly) again. All these detections of device saturations are evidently false positives, and result only in \iocost underutilizing the speed of the drive. The weight-adjusting mechanism is failing as well in boosting throughput. In particular, the weights of all groups remain constantly equal to 100 (not shown).
\begin{figure}
\includegraphics[width=\textwidth]{plots/vrate-seq_rd_vs_seq_rd.png} \caption{Busy level, number of groups lagging and \vrate during the
benchmark.}
\label{fig:vrate}
\end{figure}
As a last crosstest, we traced \iocost also for the throughput failure reported in the last subplot in Figure~\ref{fig:SSD-seq-interferers} (target doing sequential reads and interferes doing sequential writes). Results are reported in Figure~\ref{fig:vrate-writes}, and show the same \vrate estimation issues as in the failure with only reads.
\begin{figure}
\includegraphics[width=\textwidth]{plots/vrate-seq_rd_vs_seq_wr.png} \caption{Busy level, number of groups lagging and \vrate during the
benchmark.}
\label{fig:vrate-writes}
\end{figure}
The remaining question is then: why does \bfq make it? \bfq makes it because it \textbf{does not} use any transfer-function parameter to provide its main service guarantee. \bfq's main actuators are simply the fixed weights set by the user; and, given the total number of sectors transferred in a given time interval, \bfq just provides each process or group with a fraction of those sectors proportional to the weight of the process or group. There are feedback-loop mechanisms in \bfq too, but they intervene only to boost throughput. This is evidently an easier task than the combined task of boosting throughput and at the same time guaranteeing bandwidth and latency. Moreover, even if throughput boosting fails for some workload, service guarantees are however preserved.
Thanks,
Paolo
Quoted 4 lines
Thanks.
Signature · 1 line
tejun