Skip to contentSkip to conversation

IO cost model based work-conserving porportional controller

PATCH In review Tejun Heo 4 participants 29 messages Aug 28, 2019 – Nov 1, 2019 2 messages not in the archive

Subsystems (6)
lore
Share & tools
lore

Tejun Heo

author maintainer
#0 lore raw

PATCH v3 1/1 IO cost model based work-conserving porportional controller

Changes from v2[2]:

* Fixed a divide-by-zero bug in current_hweight().

* pre_start_time and friends renamed to alloc_time and now has its own CONFIG option which is selected by IOCOST.

Changes from v1[1]:

* Prerequisite patchsets had cosmetic changes and merged. Refreshed on top.

* Renamed from ioweight to iocost. All source code and tools are updated accordingly. Control knobs io.weight.qos and io.weight.cost_model are renamed to io.cost.qos and io.cost.model respectively. This is a more fitting name which won't become a misnomer when, for example, cost based io.max is added.

* Various bug fixes and improvements. A few bugs were discovered while testing against high-iops nvme device. Auto parameter selection improved and verified across different classes of SSDs.

* Dropped bpf iocost support for now.

* Added coef generation script.

* Verified on high-iops nvme device. Result is included below.

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-iocost.c and Documentation/admin-guide/cgroup-v2.rst changes in the "blkcg: implement blk-iocost" 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
  * iocost, QoS: None
    https://photos.app.goo.gl/MLNQGxCtBQ8wAmjm7
  * iocost, 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
  * iocost, QoS: None
    https://photos.app.goo.gl/T2HedKD2sywQgj7R9

* iocost, 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
* iocost, QoS: None

    https://photos.app.goo.gl/iyQBsky7bmM54Xiq7

* iocost, QoS: rpct=95.00 rlat=10000 wpct=95.00 wlat=20000 min=50.00 max=400.00
https://photos.app.goo.gl/q1a6URLDxPLMrnHy5
* NVME SSD (ran with 8 concurrent fio jobs to achieve saturation)
* No IO control

    https://photos.app.goo.gl/S6xjEVTJzcfb3w1j7

* iocost, QoS: None
https://photos.app.goo.gl/SjQUUotJBAGr7vqz7
* iocost, QoS: rpct=95.00 rlat=5000 wpct=95.00 wlat=5000 min=1.00 max=10000.00
https://photos.app.goo.gl/RsaYBd2muX7CegoN7

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 the current block/for-next 53fc55c817c3 ("Merge branch 'for-5.4/block' into for-next") and 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-alloc_time_ns.patch 0008-blkcg-implement-blk-iocost.patch 0009-blkcg-add-tools-cgroup-iocost_monitor.py.patch 0010-blkcg-add-tools-cgroup-iocost_coef_gen.py.patch

0001-0007 are prep patches.
0008 implements blk-iocost.
0009 adds monitoring script.
0010 adds linear cost model coefficient generation script.

The patchset is also available in the following git branch.

git://git.kernel.org/pub/scm/linux/kernel/git/tj/cgroup.git review-iow-v2

diffstat follows, Thanks.

 Documentation/admin-guide/cgroup-v2.rst |   97 +
 block/Kconfig                           |   13 
 block/Makefile                          |    1 
 block/bfq-cgroup.c                      |    5 
 block/blk-cgroup.c                      |   71 
 block/blk-core.c                        |    4 
 block/blk-iocost.c                      | 2395 ++++++++++++++++++++++++++++++++
 block/blk-iolatency.c                   |    8 
 block/blk-mq.c                          |   13 
 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 
 include/linux/blk-cgroup.h              |    4 
 include/linux/blk_types.h               |    3 
 include/linux/blkdev.h                  |   13 
 include/trace/events/iocost.h           |  174 ++
 tools/cgroup/iocost_coef_gen.py         |  178 ++
 tools/cgroup/iocost_monitor.py          |  270 +++
 21 files changed, 3272 insertions(+), 53 deletions(-)

--
tejun

[1] http://lkml.kernel.org/r/[email protected]
[2] http://lkml.kernel.org/r/[email protected]

author maintainer
#1 lore raw

PATCH 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
index 0f6cd688924f..e6fb537b4bfc 100644
@@ -501,11 +501,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
index 55a7dc227dfb..6a82ca3fb5cf 100644
@@ -175,7 +175,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;
 
@@ -1346,7 +1346,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;
@@ -1362,7 +1362,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
index 0fff7b56df0e..46fa6449f4bb 100644
@@ -934,11 +934,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
index 8ab6c8153223..0445c998c377 100644
@@ -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
index 0bb79d858a13..261248e88eb1 100644
@@ -149,7 +149,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
author maintainer
#2 lore raw

PATCH 2/10 blkcg: make ->cpd_init_fn() optional

In reply to Tejun Heo

For 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
index 6a82ca3fb5cf..78ccbdcfe723 100644
@@ -1475,7 +1475,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
author maintainer
#3 lore raw

PATCH 3/10 blkcg: separate blkcg_conf_get_disk() out of blkg_conf_prep()

In reply to Tejun Heo

Separate 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
index 78ccbdcfe723..0e2619c1a422 100644
@@ -753,6 +753,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
@@ -772,25 +810,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;
 
@@ -856,7 +880,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
index 261248e88eb1..bed9e43f9426 100644
@@ -234,6 +234,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
author maintainer
#4 lore raw

PATCH 4/10 block/rq_qos: add rq_qos_merge()

In reply to Tejun Heo

Add 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
index 77807a5d7f9e..875e8d105067 100644
@@ -604,6 +604,7 @@ bool bio_attempt_back_merge(struct request *req, struct bio *bio,
 		return false;
 
 	trace_block_bio_backmerge(req->q, req, bio);
+	rq_qos_merge(req->q, req, bio);
 
 	if ((req->cmd_flags & REQ_FAILFAST_MASK) != ff)
 		blk_rq_set_mixed_merge(req);
@@ -625,6 +626,7 @@ bool bio_attempt_front_merge(struct request *req, struct bio *bio,
 		return false;
 
 	trace_block_bio_frontmerge(req->q, req, bio);
+	rq_qos_merge(req->q, req, bio);
 
 	if ((req->cmd_flags & REQ_FAILFAST_MASK) != ff)
 		blk_rq_set_mixed_merge(req);
@@ -650,6 +652,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
index 3954c0dc1443..f4eea78f5cc1 100644
@@ -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
index 2300e038b9fa..8e426a8505b6 100644
@@ -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
author maintainer
#5 lore raw

PATCH 5/10 block/rq_qos: implement rq_qos_ops->queue_depth_changed()

In reply to Tejun Heo

wbt 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
index f4eea78f5cc1..61b635bc2a31 100644
@@ -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
index 8e426a8505b6..e15b6907b76d 100644
@@ -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
index 2c1831207a8f..a058997b9cce 100644
@@ -805,7 +805,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
index c4d3089e47f7..8af553a0ba00 100644
@@ -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
index f47218d5b3b2..8e4e37660971 100644
@@ -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
author maintainer
#6 lore raw

PATCH 6/10 blkcg: s/RQ_QOS_CGROUP/RQ_QOS_LATENCY/

In reply to Tejun Heo

io.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
index 46fa6449f4bb..c128d50cb410 100644
@@ -725,7 +725,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
index e15b6907b76d..5f8b75826a98 100644
@@ -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
author maintainer
#7 lore raw

PATCH 7/10 blk-mq: add optional request->alloc_time_ns

In reply to Tejun Heo

There 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->alloc_time_ns which records when the request allocation attempt started. As it isn't used for the usual stats, make it optional behind CONFIG_BLK_RQ_ALLOC_TIME and QUEUE_FLAG_RQ_ALLOC_TIME so that it can be compiled out when there are no users and it's active only on queues which need it even when compiled in.

v2: s/pre_start_time/alloc_time/ and add CONFIG_BLK_RQ_ALLOC_TIME
gating as suggested by Jens.

---
 block/Kconfig          |  3 +++
 block/blk-mq.c         | 13 +++++++++++--
 include/linux/blkdev.h | 13 ++++++++++++-
 3 files changed, 26 insertions(+), 3 deletions(-)
block/Kconfig +3 -0
index 8b5f8e560eb4..1b62ad6d0e12 100644
@@ -26,6 +26,9 @@ menuconfig BLOCK
 
 if BLOCK
 
+config BLK_RQ_ALLOC_TIME
+	bool
+
 config BLK_SCSI_REQUEST
 	bool
 
block/blk-mq.c +11 -2
index f6620a30752e..b622029b19ea 100644
@@ -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 alloc_time_ns)
 {
 	struct blk_mq_tags *tags = blk_mq_tags_from_data(data);
 	struct request *rq = tags->static_rqs[tag];
@@ -325,6 +325,9 @@ 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;
+#ifdef CONFIG_BLK_RQ_ALLOC_TIME
+	rq->alloc_time_ns = alloc_time_ns;
+#endif
 	if (blk_mq_need_time_stamp(rq))
 		rq->start_time_ns = ktime_get_ns();
 	else
@@ -356,8 +359,14 @@ static struct request *blk_mq_get_request(struct request_queue *q,
 	struct request *rq;
 	unsigned int tag;
 	bool clear_ctx_on_error = false;
+	u64 alloc_time_ns = 0;
 
 	blk_queue_enter_live(q);
+
+	/* alloc_time includes depth and tag waits */
+	if (blk_queue_rq_alloc_time(q))
+		alloc_time_ns = ktime_get_ns();
+
 	data->q = q;
 	if (likely(!data->ctx)) {
 		data->ctx = blk_mq_get_ctx(q);
@@ -393,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, alloc_time_ns);
 	if (!op_is_flush(data->cmd_flags)) {
 		rq->elv.icq = NULL;
 		if (e && e->type->ops.prepare_request) {
include/linux/blkdev.h +12 -1
index 1ac790178787..d0ad21e4771b 100644
@@ -194,7 +194,11 @@ struct request {
 
 	struct gendisk *rq_disk;
 	struct hd_struct *part;
-	/* Time that I/O was submitted to the kernel. */
+#ifdef CONFIG_BLK_RQ_ALLOC_TIME
+	/* Time that the first bio started allocating this request. */
+	u64 alloc_time_ns;
+#endif
+	/* 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;
@@ -609,6 +613,7 @@ struct request_queue {
 #define QUEUE_FLAG_QUIESCED	24	/* queue has been quiesced */
 #define QUEUE_FLAG_PCI_P2PDMA	25	/* device supports PCI p2p requests */
 #define QUEUE_FLAG_ZONE_RESETALL 26	/* supports Zone Reset All */
+#define QUEUE_FLAG_RQ_ALLOC_TIME 27	/* record rq->alloc_time_ns */
 
 #define QUEUE_FLAG_MQ_DEFAULT	((1 << QUEUE_FLAG_IO_STAT) |		\
 				 (1 << QUEUE_FLAG_SAME_COMP))
@@ -637,6 +642,12 @@ 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)
+#ifdef CONFIG_BLK_RQ_ALLOC_TIME
+#define blk_queue_rq_alloc_time(q)	\
+	test_bit(QUEUE_FLAG_RQ_ALLOC_TIME, &(q)->queue_flags)
+#else
+#define blk_queue_rq_alloc_time(q)	false
+#endif
 
 #define blk_noretry_request(rq) \
 	((rq)->cmd_flags & (REQ_FAILFAST_DEV|REQ_FAILFAST_TRANSPORT| \
Signature · 1 line
2.17.1
author maintainer
#8 lore raw

PATCH 8/10 blkcg: implement blk-iocost

In reply to 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.

Please see the top comment in blk-iocost.c and documentation for more details.

v2: Rebased on top of RQ_ALLOC_TIME changes and folded in Rik's fix
for a divide-by-zero bug in current_hweight() triggered by zero inuse_sum.

Cc Andy Newell <[email protected]>
Cc Josef Bacik <[email protected]>
Cc Rik van Riel <[email protected]>
---
 Documentation/admin-guide/cgroup-v2.rst |   94 +
 block/Kconfig                           |   10 +
 block/Makefile                          |    1 +
 block/blk-iocost.c                      | 2371 +++++++++++++++++++++++
 block/blk-rq-qos.h                      |    3 +
 include/linux/blk_types.h               |    3 +
 include/trace/events/iocost.h           |  174 ++
 7 files changed, 2656 insertions(+)
 create mode 100644 block/blk-iocost.c
 create mode 100644 include/trace/events/iocost.h
Documentation/admin-guide/cgroup-v2.rst +94 -0
index 3b29005aa981..1521c7e554f5 100644
@@ -1435,6 +1435,100 @@ 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.cost.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 controller (CONFIG_BLK_CGROUP_IOCOST) which
+	currently implements "io.weight" proportional control.  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.cost.qos" or "io.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.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
+	controller (CONFIG_BLK_CGROUP_IOCOST) which currently
+	implements "io.weight" proportional control.  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.cost.qos" or "io.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 +10 -0
index 1b62ad6d0e12..41c0917ce622 100644
@@ -135,6 +135,16 @@ config BLK_CGROUP_IOLATENCY
 
 	Note, this is an experimental interface and could be changed someday.
 
+config BLK_CGROUP_IOCOST
+	bool "Enable support for cost model based cgroup IO controller"
+	depends on BLK_CGROUP=y
+	select BLK_RQ_ALLOC_TIME
+	---help---
+	Enabling this option enables the .weight interface for cost
+	model based proportional IO control.  The IO controller
+	distributes IO capacity between different groups based on
+	their share of the overall weight distribution.
+
 config BLK_WBT_MQ
 	bool "Multiqueue writeback throttling"
 	default y
block/Makefile +1 -0
index eee1b4ceecf9..9ef57ace90d4 100644
@@ -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_IOCOST)	+= blk-iocost.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-iocost.c new file +2371 -0

2,371 lines not on this page · raw message

block/blk-rq-qos.h +3 -0
index 5f8b75826a98..08a09dbe0f4b 100644
@@ -15,6 +15,7 @@ struct blk_mq_debugfs_attr;
 enum rq_qos_id {
 	RQ_QOS_WBT,
 	RQ_QOS_LATENCY,
+	RQ_QOS_COST,
 };
 
 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_COST:
+		return "cost";
 	}
 	return "unknown";
 }
include/linux/blk_types.h +3 -0
index 75059c1d4244..6f7a8647cefb 100644
@@ -169,6 +169,9 @@ struct bio {
 	 */
 	struct blkcg_gq		*bi_blkg;
 	struct bio_issue	bi_issue;
+#ifdef CONFIG_BLK_CGROUP_IOCOST
+	u64			bi_iocost_cost;
+#endif
 #endif
 	union {
 #if defined(CONFIG_BLK_DEV_INTEGRITY)
include/trace/events/iocost.h new file +174 -0

174 lines not on this page · raw message

Signature · 1 line
2.17.1
author maintainer
#9 lore raw

PATCH 1/1 blkcg: fix missing free on error path of blk_iocost_init()

blk_iocost_init() forgot to free its percpu stat on the error path. Fix it.

---
 block/blk-iocost.c |    1 +
 1 file changed, 1 insertion(+)
block/blk-iocost.c +1 -0
index f04a4ed1cb45..9c8046ac5925 100644
@@ -1876,6 +1876,7 @@ static int blk_iocost_init(struct request_queue *q)
 	ret = blkcg_activate_policy(q, &blkcg_policy_iocost);
 	if (ret) {
 		rq_qos_del(q, rqos);
+		free_percpu(ioc->pcpu_stat);
 		kfree(ioc);
 		return ret;
 	}
maintainer
#10 lore raw

Re: [PATCH 08/10] blkcg: implement blk-iocost

In reply to Tejun Heo

Hello.

block/blk-iocost.c line 2331

Quoted 5 lines · Tejun Heo
block/blk-iocost.c +2 -0
[...]
+static struct cftype ioc_files[] = {
+		.name = "weight",
[...]

This adds the generic io.weight attribute. How will this compose with the weight from IO schedulers? (AFAIK, only BFQ allows proportional control as of now. +CC Paolo.)

I see this attributes are effectively per-cgroup per-device. Apparently, one device should have only one weight across hierarchy. Would it make sense to have io.bfq.weight and io.cost.weight with disjunctive devices?

(Alas, I have no idea how to make the users of io.weight happy, when proportionality control mechanism seems orthogonal to the weight. (Vector weights?))

block/blk-iocost.c line 2344

Quoted 5 lines
block/blk-iocost.c +4 -0
+		.name = "cost.qos",
+		.flags = CFTYPE_ONLY_ON_ROOT,
[...]
+		.name = "cost.model",
+		.flags = CFTYPE_ONLY_ON_ROOT,

I'm concerned that these aren't true cgroup attributes. The root cgroup would act as container for global configuration options. Wouldn't these values better fit as (configurable) attributes of the respective devices?

Secondly, how is CFTYPE_ONLY_ON_ROOT supposed to be presented in cgroup namespaces?

Thanks,
Michal

author maintainer
#11 lore raw

Re: [PATCH 08/10] blkcg: implement blk-iocost

Hello, Michal.

Quoted 3 lines · Michal Koutný

This adds the generic io.weight attribute. How will this compose with the weight from IO schedulers? (AFAIK, only BFQ allows proportional control as of now. +CC Paolo.)

The two being enabled at the same time doesn't make sense, so we can just switch over to bfq when bfq is selected as the iosched. I asked what Paolo wanted to do in terms of interface a couple times now but didn't get an answer and he posted a patch which makes the two controllers conflict, so.... Paolo, so it looks like you want to rename all bfq files to drop the bfq prefix, right? I can implement the switching if so.

Quoted 3 lines

I see this attributes are effectively per-cgroup per-device. Apparently, one device should have only one weight across hierarchy. Would it make sense to have io.bfq.weight and io.cost.weight with disjunctive devices?

It never makes sense to have both enabled, so I don't think that interface makes sense.

Quoted 9 lines

block/blk-iocost.c line 2344

Quoted 5 lines
block/blk-iocost.c new file +4 -0
+		.name = "cost.qos",
+		.flags = CFTYPE_ONLY_ON_ROOT,
[...]
+		.name = "cost.model",
+		.flags = CFTYPE_ONLY_ON_ROOT,

I'm concerned that these aren't true cgroup attributes. The root cgroup would act as container for global configuration options. Wouldn't these values better fit as (configurable) attributes of the respective devices?

Initially, I put them under block device sysfs but it was too clumsy with different config file formats and all. I think it's better to have global controller configs at the root cgroup.

Quoted 2 lines

Secondly, how is CFTYPE_ONLY_ON_ROOT supposed to be presented in cgroup namespaces?

Not at all. These are system-wide configs. cgroup namespaces shouldn't have anything which aren't in non-root cgroups.

Thanks.

Signature · 1 line
tejun
#12 lore raw

Re: [PATCH 08/10] blkcg: implement blk-iocost

Quoted 11 lines

Il giorno 10 set 2019, alle ore 18:08, Tejun Heo <[email protected]> ha scritto:

Hello, Michal.

Quoted 3 lines · Michal Koutný

This adds the generic io.weight attribute. How will this compose with the weight from IO schedulers? (AFAIK, only BFQ allows proportional control as of now. +CC Paolo.)

Quoted 6 lines

The two being enabled at the same time doesn't make sense, so we can just switch over to bfq when bfq is selected as the iosched. I asked what Paolo wanted to do in terms of interface a couple times now but didn't get an answer and he posted a patch which makes the two controllers conflict, so.... Paolo, so it looks like you want to rename all bfq files to drop the bfq prefix, right?

Yep, mainly because ... this is the solution you voted and you yourself proposed [1] :)

[1] https://patchwork.kernel.org/patch/10988261/

Quoted 3 lines

I can implement
the switching if so.

That would be perfect.

Thanks,
Paolo

Quoted 31 lines
Quoted 3 lines

I see this attributes are effectively per-cgroup per-device. Apparently, one device should have only one weight across hierarchy. Would it make sense to have io.bfq.weight and io.cost.weight with disjunctive devices?

It never makes sense to have both enabled, so I don't think that interface makes sense.

Quoted 9 lines

block/blk-iocost.c line 2344

Quoted 5 lines
block/blk-iocost.c new file +4 -0
+		.name = "cost.qos",
+		.flags = CFTYPE_ONLY_ON_ROOT,
[...]
+		.name = "cost.model",
+		.flags = CFTYPE_ONLY_ON_ROOT,

I'm concerned that these aren't true cgroup attributes. The root cgroup would act as container for global configuration options. Wouldn't these values better fit as (configurable) attributes of the respective devices?

Initially, I put them under block device sysfs but it was too clumsy with different config file formats and all. I think it's better to have global controller configs at the root cgroup.

Quoted 2 lines

Secondly, how is CFTYPE_ONLY_ON_ROOT supposed to be presented in cgroup namespaces?

Not at all. These are system-wide configs. cgroup namespaces shouldn't have anything which aren't in non-root cgroups.

Thanks.

Signature · 1 line
tejun
author maintainer
#13 lore raw

Re: [PATCH 08/10] blkcg: implement blk-iocost

Hello,

Quoted 11 lines · Paolo Valente
Quoted 6 lines

The two being enabled at the same time doesn't make sense, so we can just switch over to bfq when bfq is selected as the iosched. I asked what Paolo wanted to do in terms of interface a couple times now but didn't get an answer and he posted a patch which makes the two controllers conflict, so.... Paolo, so it looks like you want to rename all bfq files to drop the bfq prefix, right?

Yep, mainly because ... this is the solution you voted and you yourself proposed [1] :)

[1] https://patchwork.kernel.org/patch/10988261/

So, that was then. Since then the interface change has been published and userspace, at least some of them, already had to adjust. Now, I don't have any opinion on the matter and flipping again will cause inconveniences to some subset of users. It's your call.

Quoted 4 lines
Quoted 2 lines

I can implement
the switching if so.

That would be perfect.

Whichever way it gets decided, this is easy enough. I'll prep a patch.

Thanks.

Signature · 1 line
tejun
author maintainer
#14 lore raw

Re: [PATCH 08/10] blkcg: implement blk-iocost

Hey,

Quoted 7 lines · Tejun Heo
Quoted 4 lines
Quoted 2 lines

I can implement
the switching if so.

That would be perfect.

Whichever way it gets decided, this is easy enough. I'll prep a patch.

Here's the patch.

* It disables iocost when bfq iosched is selected. iocost is only re-enabled when bfq module is unloaded. While it can easily be made to flip when there's no bfq queue left, I think minimizing the number of switches is likely is better.

* It looks like building bfq as module has been broken for some time and I added symbol exports to make it work. They should be separated into a separate patch.

* It doesn't actually rename any of the bfq interface files. It just gets rid of potential conflict from iocost.

Please feel free to use / modify the patch however you see fit.

Thanks.

---

block/bfq-cgroup.c +2 -0
index 86a607cf19a1..decda96770f4 100644
@@ -1194,7 +1194,9 @@ struct bfq_group *bfq_create_group_hierarchy(struct bfq_data *bfqd, int node)
 }
 
 struct blkcg_policy blkcg_policy_bfq = {
+#ifndef CONFIG_BLK_CGROUP_IOCOST
 	.dfl_cftypes		= bfq_blkg_files,
+#endif
 	.legacy_cftypes		= bfq_blkcg_legacy_files,
 
 	.cpd_alloc_fn		= bfq_cpd_alloc,
block/bfq-iosched.c +32 -0
index b33be928d164..b4aaeef1fb87 100644
@@ -6365,6 +6365,36 @@ static void bfq_init_root_group(struct bfq_group *root_group,
 	root_group->sched_data.bfq_class_idle_last_service = jiffies;
 }
 
+#if defined(CONFIG_BFQ_GROUP_IOSCHED) && defined(CONFIG_BLK_CGROUP_IOCOST)
+static bool bfq_enabled = false;
+
+static void bfq_enable(void)
+{
+	static DEFINE_MUTEX(bfq_enable_mutex);
+
+	mutex_lock(&bfq_enable_mutex);
+	if (!bfq_enabled) {
+		pr_info("bfq-iosched: Overriding iocost\n");
+		blkcg_policy_unregister(&blkcg_policy_iocost);
+		cgroup_add_dfl_cftypes(&io_cgrp_subsys, bfq_blkg_files);
+		bfq_enabled = true;
+	}
+	mutex_unlock(&bfq_enable_mutex);
+}
+
+static void __exit bfq_disable(void)
+{
+	if (bfq_enabled) {
+		pr_info("bfq-iosched: Restoring iocost\n");
+		cgroup_rm_cftypes(bfq_blkg_files);
+		blkcg_policy_register(&blkcg_policy_iocost);
+	}
+}
+#else
+static void bfq_enable(void) {}
+static void __exit bfq_disable(void) {}
+#endif
+
 static int bfq_init_queue(struct request_queue *q, struct elevator_type *e)
 {
 	struct bfq_data *bfqd;
@@ -6489,6 +6519,7 @@ static int bfq_init_queue(struct request_queue *q, struct elevator_type *e)
 	bfq_init_entity(&bfqd->oom_bfqq.entity, bfqd->root_group);
 
 	wbt_disable_default(q);
+	bfq_enable();
 	return 0;
 
 out_free:
@@ -6806,6 +6837,7 @@ static void __exit bfq_exit(void)
 	blkcg_policy_unregister(&blkcg_policy_bfq);
 #endif
 	bfq_slab_kill();
+	bfq_disable();
 }
 
 module_init(bfq_init);
block/blk-cgroup.c +2 -0
index 0e2619c1a422..b6f20be0fc78 100644
@@ -900,6 +900,7 @@ int blkg_conf_prep(struct blkcg *blkcg, const struct blkcg_policy *pol,
 	}
 	return ret;
 }
+EXPORT_SYMBOL_GPL(blkg_conf_prep);
 
 /**
  * blkg_conf_finish - finish up per-blkg config update
@@ -915,6 +916,7 @@ void blkg_conf_finish(struct blkg_conf_ctx *ctx)
 	rcu_read_unlock();
 	put_disk_and_module(ctx->disk);
 }
+EXPORT_SYMBOL_GPL(blkg_conf_finish);
 
 static int blkcg_print_stat(struct seq_file *sf, void *v)
 {
block/blk-iocost.c +2 -3
index 3b39deb8b9f8..1ef5b443c09a 100644
@@ -605,8 +605,6 @@ static u32 vrate_adj_pct[] =
 	  2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
 	  4, 4, 4, 4, 4, 4, 4, 4, 8, 8, 8, 8, 8, 8, 8, 8, 16 };
 
-static struct blkcg_policy blkcg_policy_iocost;
-
 /* accessors and helpers */
 static struct ioc *rqos_to_ioc(struct rq_qos *rqos)
 {
@@ -2434,7 +2432,7 @@ static struct cftype ioc_files[] = {
 	{}
 };
 
-static struct blkcg_policy blkcg_policy_iocost = {
+struct blkcg_policy blkcg_policy_iocost = {
 	.dfl_cftypes	= ioc_files,
 	.cpd_alloc_fn	= ioc_cpd_alloc,
 	.cpd_free_fn	= ioc_cpd_free,
@@ -2442,6 +2440,7 @@ static struct blkcg_policy blkcg_policy_iocost = {
 	.pd_init_fn	= ioc_pd_init,
 	.pd_free_fn	= ioc_pd_free,
 };
+EXPORT_SYMBOL_GPL(blkcg_policy_iocost);
 
 static int __init ioc_init(void)
 {
include/linux/blk-cgroup.h +5 -0
index bed9e43f9426..5669e3cfa1bc 100644
@@ -815,6 +815,11 @@ static inline void blkcg_clear_delay(struct blkcg_gq *blkg)
 void blkcg_add_delay(struct blkcg_gq *blkg, u64 now, u64 delta);
 void blkcg_schedule_throttle(struct request_queue *q, bool use_memdelay);
 void blkcg_maybe_throttle_current(void);
+
+#ifdef CONFIG_BLK_CGROUP_IOCOST
+extern struct blkcg_policy blkcg_policy_iocost;
+#endif
+
 #else	/* CONFIG_BLK_CGROUP */
 
 struct blkcg {
kernel/cgroup/cgroup.c +2 -0
index 753afbca549f..ced23229f359 100644
@@ -4059,6 +4059,7 @@ int cgroup_rm_cftypes(struct cftype *cfts)
 	mutex_unlock(&cgroup_mutex);
 	return ret;
 }
+EXPORT_SYMBOL_GPL(cgroup_rm_cftypes);
 
 /**
  * cgroup_add_cftypes - add an array of cftypes to a subsystem
@@ -4115,6 +4116,7 @@ int cgroup_add_dfl_cftypes(struct cgroup_subsys *ss, struct cftype *cfts)
 		cft->flags |= __CFTYPE_ONLY_ON_DFL;
 	return cgroup_add_cftypes(ss, cfts);
 }
+EXPORT_SYMBOL_GPL(cgroup_add_dfl_cftypes);
 
 /**
  * cgroup_add_legacy_cftypes - add an array of cftypes for legacy hierarchies
#15 lore raw

Re: [PATCH 08/10] blkcg: implement blk-iocost

In reply to Tejun Heo
Quoted 17 lines

Il giorno 11 set 2019, alle ore 16:16, Tejun Heo <[email protected]> ha scritto:

Hello,

Quoted 10 lines · Paolo Valente
Quoted 6 lines

The two being enabled at the same time doesn't make sense, so we can just switch over to bfq when bfq is selected as the iosched. I asked what Paolo wanted to do in terms of interface a couple times now but didn't get an answer and he posted a patch which makes the two controllers conflict, so.... Paolo, so it looks like you want to rename all bfq files to drop the bfq prefix, right?

Yep, mainly because ... this is the solution you voted and you yourself proposed [1] :)

Quoted 7 lines
Quoted 1 line

[1] https://patchwork.kernel.org/patch/10988261/

So, that was then. Since then the interface change has been published and userspace, at least some of them, already had to adjust. Now, I don't have any opinion on the matter and flipping again will cause inconveniences to some subset of users. It's your call.

Ok, then let's go for removing bfq prefix, as expected, e.g., by systemd community [1]. A few days ago I reposted a patch removing the prefix from all involved parameters [2], it should make all legacy software work again.

[1] https://github.com/systemd/systemd/issues/7057
[2] https://lkml.org/lkml/2019/9/9/47

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

I can implement
the switching if so.

That would be perfect.

Whichever way it gets decided, this is easy enough. I'll prep a patch.

Thank you for that too,
Paolo

Quoted 4 lines

Thanks.

Signature · 1 line
tejun
maintainer
#16 lore raw

Re: [PATCH 08/10] blkcg: implement blk-iocost

In reply to Tejun Heo

Hi (and apology for relatively late reply).

Quoted 1 line · Tejun Heo

I can implement the switching if so.

I see the "conflict" is solved by the switching.

Quoted 2 lines

Initially, I put them under block device sysfs but it was too clumsy with different config file formats and all.

Do you have any more details on that? In the end, it all boils down to a daemon/setup utility writing into the control files and it can use whatever config files it decides, can't it?

Quoted 2 lines

I think it's better to have global controller configs at the root cgroup.

I agree with the "global controller" configs, however, does it also hold for "global controller per-device" configs? They seem closer to the device than the controller. Potentially, the parameters could be used by some other consumers in the future. (I'm not opposing the current form, I just want to explore the space before an API is fixed.)

Quoted 2 lines

Not at all. These are system-wide configs. cgroup namespaces shouldn't have anything which aren't in non-root cgroups.

Thanks, I understand the cgroup namespaces are not meant to be transparent to their members.

Michal

author maintainer
#17 lore raw

Re: [PATCH 08/10] blkcg: implement blk-iocost

Hello,

Quoted 5 lines · Michal Koutný
Quoted 2 lines

Initially, I put them under block device sysfs but it was too clumsy with different config file formats and all.

Do you have any more details on that? In the end, it all boils down to a daemon/setup utility writing into the control files and it can use whatever config files it decides, can't it?

Yeah, I mean, we can make any interface work. So, there are two global knobs io.cost.model and io.cost.qos. Of the tw, io.cost.model is okay to move under block device but the qos file gets weird because the content of the file is more resource control policies than device properties.

Thanks.

Signature · 1 line
tejun
maintainer
#18 lore raw

Re: [PATCH 08/10] blkcg: implement blk-iocost

Quoted 2 lines · Tejun Heo

[...] but the qos file gets weird because the content of the file is more resource control policies than device properties.

I see two facets on this -- the semantics of the QoS controls and storing controller parameters generally.

Because I'm not fully convinced using the root cgroup for the latter is a good idea and I don't have a better one (what about /sys/kernel/cgroup/?), I'd like to question the former to potentially postpone finding the place for its parameters :-)

Quoted 3 lines · Tejun Heo

[...]
Please see the top comment in blk-iocost.c and documentation for more details.

I admit I did't grasp the explanations in the cgroup-v2.rst, perhaps some of the explanations from blk-iocost.c would be useful there as well.

IIUC, the controls are supposed to be abstracted and generic to express high-level ideas and be independent of particular details. Here a bunch of parameters is introduced whose tuning may become a complex optimization task.

What is the metric that is the QoS controller striving to guarantee? How does it differ from the io.latency policy?

Quoted 7 lines

[...]
+ * 2-2. Vrate Adjustment
+ * [...] When this delay becomes noticeable, it's a clear
+ * indication that the device is saturated and we lower the vrate. This
+ * saturation signal is fairly conservative as it only triggers when both
+ * hardware and software queues are filled up, and is used as the default
+ * busy signal.

(The following paragraph is based only on naïve understanding of the block layer.) So the device's vrate is lowered, causing its vtime growing slower, i.e. postponing issuing an IO later for all cgroups accessing the device. But what's the purpose of this? If the queues fill up, wouldn't be all naturally pushed back by the longer queue time anyway? And wouldn't slowing down the device's vtime just cause queueing elsewhere?

Thanks,
Michal

author maintainer
#19 lore raw

Re: [PATCH 08/10] blkcg: implement blk-iocost

Hello,

Quoted 4 lines · Michal Koutný

Because I'm not fully convinced using the root cgroup for the latter is a good idea and I don't have a better one (what about /sys/kernel/cgroup/?), I'd like to question the former to potentially postpone finding the place for its parameters :-)

Yeah, I mean, I don't know. If these params were useful outside iocost controller itself, under /sys/block would be a better place but it's kind tightly tied to vrate. We likely can talk on the subject for a really long time probalby because there's no clearly technically better choice here, so...

Quoted 8 lines · Tejun Heo
Quoted 3 lines

[...]
Please see the top comment in blk-iocost.c and documentation for more details.

I admit I did't grasp the explanations in the cgroup-v2.rst, perhaps some of the explanations from blk-iocost.c would be useful there as well.

Quoted 7 lines

IIUC, the controls are supposed to be abstracted and generic to express high-level ideas and be independent of particular details. Here a bunch of parameters is introduced whose tuning may become a complex optimization task.

What is the metric that is the QoS controller striving to guarantee? How does it differ from the io.latency policy?

Yeah, it's kinda unfortunate that it requires this many parameters but at least my opinion is that that's reflecting the inherent complexities of the underlying devices and how workloads interact with them. Andy knows and can explain this a lot better than me but here's what's we're working on:

For the cost model, the plan is to build a database of model-specific model parameters which are loaded during boot. The cost model parameters are pretty straight forward to determine, so hopefully this won't be too difficult.

For QoS parameters, Andy is currently working on a method to determine the set of parametesr which are at the edge of total work cliff - ie. the point where tighetning QoS params further starts reducing the total amount of work the device can do significantly. This would be the neutral parameters to use for a given device unless there are overriding latency requirements, so it's likely that this can be part of the model-specific parameter set.

We're currently deploying the controller to a lot of machines and gathering data to verify model accuracies and controller behaviors. It's working pretty well already and once the methods become more mature, we'll upstream them (whichever projects they end up belonging).

Quoted 7 lines
Quoted 7 lines

[...]
+ * 2-2. Vrate Adjustment
+ * [...] When this delay becomes noticeable, it's a clear
+ * indication that the device is saturated and we lower the vrate. This
+ * saturation signal is fairly conservative as it only triggers when both
+ * hardware and software queues are filled up, and is used as the default
+ * busy signal.

Quoted 7 lines

(The following paragraph is based only on naïve understanding of the block layer.) So the device's vrate is lowered, causing its vtime growing slower, i.e. postponing issuing an IO later for all cgroups accessing the device. But what's the purpose of this? If the queues fill up, wouldn't be all naturally pushed back by the longer queue time anyway? And wouldn't slowing down the device's vtime just cause queueing elsewhere?

Nothing can issue IOs indefinitely without some of them completing and the total amount of work a workload can do is conjoined with the completion latencies. Most IO devices have queue depth which is at some level reasonable given the performance characteritics of the device; otherwise, the device would develop a really fat pipe in it which can frustrate various use cases. On top, block layer adds some limited amount of queueing to avoid command bubbles (2x qd, usually), so, while definitely not stringent in any way, the queueing is already regulated so that things don't get too crazy.

Regulating based on qd may not be enough for latency sensitive synchronous workloads; however, for a lot of workloads such as reading file contents or copying them which have in-kernel windowing mechanisms, it can provide a reasonable level of protection to keep the effectiveness of the windowing mechanisms without sacrificing noticeable level of total work.

Thanks.

Signature · 1 line
tejun
maintainer
#20 lore raw

Re: [PATCH 08/10] blkcg: implement blk-iocost

Hello

(I realize it's likely late for the remark but I'd like to bring it up anyway.)

Quoted 3 lines · Tejun Heo

We likely can talk on the subject
for a really long time probalby because there's no clearly technically better choice here, so...

I agree with you that functionally the two options are equal and also from configuration POV they seem both sensible.

I checked where BFQ stores its per-device parameters and its under the sysfs directory of given device's iosched directory. So from the user perspective it'd be more consistent if all similar tunables resided under that location.

(OTOH, I admit I'm not that familiar with block layer internals to identify the overlap between IO scheduler and IO controller.)

Quoted 4 lines

Yeah, it's kinda unfortunate that it requires this many parameters but at least my opinion is that that's reflecting the inherent complexities of the underlying devices and how workloads interact with them.

After I learnt about the existence of BFQ tunables, I'm no longer concerned by the complexity of the parameter space.

Thanks for the explanations of QoS purpose.

Quoted 4 lines

For QoS parameters, Andy is currently working on a method to determine the set of parametesr which are at the edge of total work cliff - ie. the point where tighetning QoS params further starts reducing the total amount of work the device can do significantly.

The QoS description in the Documentation/ describes the interpretation of the individual parameters, however, this purpose and how it works was not clear to be from that. I think the QoS policy would deserve similar description in the Documentation/.

Quoted 3 lines

Nothing can issue IOs indefinitely without some of them completing and the total amount of work a workload can do is conjoined with the completion latencies. [...]

I may reply to this point later. However, if that provably works, I'm likely missing something in my understanding, so that'd be irrelevant.

Cheers,
Michal

#21 lore raw

Re: [PATCH 08/10] blkcg: implement blk-iocost

Quoted 6 lines

Il giorno 1 nov 2019, alle ore 17:15, Michal Koutný <[email protected]> ha scritto:

Hello

Hi Michal,

Quoted 10 lines

(I realize it's likely late for the remark but I'd like to bring it up anyway.)

Quoted 3 lines · Tejun Heo

We likely can talk on the subject
for a really long time probalby because there's no clearly technically better choice here, so...

I agree with you that functionally the two options are equal and also from configuration POV they seem both sensible.

Quoted 8 lines

I checked where BFQ stores its per-device parameters and its under the sysfs directory of given device's iosched directory. So from the user perspective it'd be more consistent if all similar tunables resided under that location.

(OTOH, I admit I'm not that familiar with block layer internals to identify the overlap between IO scheduler and IO controller.)

If useful for you to know, BFQ parameters are not meant to changed (apart from the low_latency tunable, if one wants full control on weights). Parameters are a testing aid, to use in case of an anomaly. After solving the anomaly, default values should be used again.

Thanks,
Paolo

Quoted 26 lines
Quoted 4 lines

Yeah, it's kinda unfortunate that it requires this many parameters but at least my opinion is that that's reflecting the inherent complexities of the underlying devices and how workloads interact with them.

After I learnt about the existence of BFQ tunables, I'm no longer concerned by the complexity of the parameter space.

Thanks for the explanations of QoS purpose.

Quoted 4 lines

For QoS parameters, Andy is currently working on a method to determine the set of parametesr which are at the edge of total work cliff - ie. the point where tighetning QoS params further starts reducing the total amount of work the device can do significantly.

The QoS description in the Documentation/ describes the interpretation of the individual parameters, however, this purpose and how it works was not clear to be from that. I think the QoS policy would deserve similar description in the Documentation/.

Quoted 3 lines

Nothing can issue IOs indefinitely without some of them completing and the total amount of work a workload can do is conjoined with the completion latencies. [...]

I may reply to this point later. However, if that provably works, I'm likely missing something in my understanding, so that'd be irrelevant.

Cheers,
Michal

author maintainer
#22 lore raw

PATCH 9/10 blkcg: add tools/cgroup/iocost_monitor.py

In reply to Tejun Heo

Instead of mucking with debugfs and ->pd_stat(), add drgn based monitoring script.

Cc Omar Sandoval <[email protected]>
---
 block/blk-iocost.c             |  21 +++
 tools/cgroup/iocost_monitor.py | 270 +++++++++++++++++++++++++++++++++
 2 files changed, 291 insertions(+)
 create mode 100644 tools/cgroup/iocost_monitor.py
block/blk-iocost.c +21 -0
index 680815620095..3208d2fdc55e 100644
@@ -149,6 +149,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/iocost_monitor.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/iocost_monitor.py new file +270 -0

270 lines not on this page · raw message

Signature · 1 line
2.17.1
author maintainer
#23 lore raw

PATCH 10/10 blkcg: add tools/cgroup/iocost_coef_gen.py

In reply to Tejun Heo

Add a script which can be used to generate device-specific iocost linear model coefficients.

---
 Documentation/admin-guide/cgroup-v2.rst |   3 +
 block/blk-iocost.c                      |   3 +
 tools/cgroup/iocost_coef_gen.py         | 178 ++++++++++++++++++++++++
 3 files changed, 184 insertions(+)
 create mode 100644 tools/cgroup/iocost_coef_gen.py
Documentation/admin-guide/cgroup-v2.rst +3 -0
index 1521c7e554f5..3deacdc5e6d2 100644
@@ -1529,6 +1529,9 @@ IO Interface Files
 	The IO cost model isn't expected to be accurate in absolute
 	sense and is scaled to the device behavior dynamically.
 
+	If needed, tools/cgroup/iocost_coef_gen.py can be used to
+	generate device-specific coefficients.
+
   io.weight
 	A read-write flat-keyed file which exists on non-root cgroups.
 	The default is "default 100".
block/blk-iocost.c +3 -0
index 3208d2fdc55e..f04a4ed1cb45 100644
@@ -46,6 +46,9 @@
  * If needed, tools/cgroup/iocost_coef_gen.py can be used to generate
  * device-specific coefficients.
  *
+ * If needed, tools/cgroup/iocost_coef_gen.py can be used to generate
+ * device-specific coefficients.
+ *
  * 2. Control Strategy
  *
  * The device virtual time (vtime) is used as the primary control metric.
tools/cgroup/iocost_coef_gen.py new file +178 -0

178 lines not on this page · raw message

Signature · 1 line
2.17.1
maintainer
#24 lore raw
In reply to Tejun Heo
Quoted 6 lines · Tejun Heo

Changes from v2[2]:

* Fixed a divide-by-zero bug in current_hweight().

* pre_start_time and friends renamed to alloc_time and now has its own CONFIG option which is selected by IOCOST.

This looks fine to me now, I've queued it up for 5.4.

Signature · 1 line
Jens Axboe

A message that is not in the archive (sent off-list or not yet received): [email protected]

author maintainer
#26 lore raw

Re: [PATCH 07/10] blk-mq: add optional request->alloc_time_ns

Hello,

Quoted 15 lines · Hillf Danton

Review static struct request *blk_mq_rq_ctx_init(struct blk_mq_alloc_data *data, · line 328

Quoted 11 lines

static struct request *blk_mq_rq_ctx_init(struct blk_mq_alloc_data *data,

(quoted diff) +2 -1
-		unsigned int tag, unsigned int op)
+		unsigned int tag, unsigned int op, u64 alloc_time_ns)
 {
 	struct blk_mq_tags *tags = blk_mq_tags_from_data(data);
 	struct request *rq = tags->static_rqs[tag];
@@ -325,6 +325,9 @@ 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;
+#ifdef CONFIG_BLK_RQ_ALLOC_TIME

Not only matches start_time, but everal hunks may collapse into one if checking alloc_time is lifted up.

Quoted 4 lines
	if (blk_queue_rq_alloc_time(rq->q))
		rq->alloc_time_ns = ktime_get_ns();
	else
		rq->alloc_time_ns = 0;

Can you please elaborate? Lifted up where?

Thanks.

Signature · 1 line
tejun

A message that is not in the archive (sent off-list or not yet received): [email protected]

author maintainer
#28 lore raw

Re: [PATCH 08/10] blkcg: implement blk-iocost

Hello,

Quoted 6 lines · Hillf Danton

Review

Quoted 3 lines
(quoted diff) +3 -0
+	on_q_ns = ktime_get_ns() - rq->alloc_time_ns;
+	rq_wait_ns = rq->start_time_ns - rq->alloc_time_ns;
+

ehm... alloc_time makes no sense wrt start_time if this is their only use. What are you trying to measure with the two stamps if they are meaningfully apart?

Queue depth depletion.

Quoted 6 lines

Review

Quoted 4 lines
(quoted diff) +4 -0
+	rq_qos_add(q, rqos);
+	ret = blkcg_activate_policy(q, &blkcg_policy_iocost);
+	if (ret) {
+		rq_qos_del(q, rqos);
		free_percpu(ioc->pcpu_stat);

Good catch. Will send a follow up patch.

Thanks.

Signature · 1 line
tejun
#29 lore raw
In reply to Tejun Heo

Hi,
I see an important interface problem. Userspace has been waiting for io.weight to become eventually the file name for setting the weight for the proportional-share policy [1,2]. If you use that name, how will we solve this?

Thanks,
Paolo

[1] https://github.com/systemd/systemd/issues/7057#issuecomment-522747575
[2] https://github.com/systemd/systemd/pull/13335#issuecomment-523035303

Quoted 214 lines

Il giorno 29 ago 2019, alle ore 00:05, Tejun Heo <[email protected]> ha scritto:

Changes from v2[2]:

* Fixed a divide-by-zero bug in current_hweight().

* pre_start_time and friends renamed to alloc_time and now has its own CONFIG option which is selected by IOCOST.

Changes from v1[1]:

* Prerequisite patchsets had cosmetic changes and merged. Refreshed on top.

* Renamed from ioweight to iocost. All source code and tools are updated accordingly. Control knobs io.weight.qos and io.weight.cost_model are renamed to io.cost.qos and io.cost.model respectively. This is a more fitting name which won't become a misnomer when, for example, cost based io.max is added.

* Various bug fixes and improvements. A few bugs were discovered while testing against high-iops nvme device. Auto parameter selection improved and verified across different classes of SSDs.

* Dropped bpf iocost support for now.

* Added coef generation script.

* Verified on high-iops nvme device. Result is included below.

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-iocost.c and Documentation/admin-guide/cgroup-v2.rst changes in the "blkcg: implement blk-iocost" 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
* iocost, QoS: None
https://photos.app.goo.gl/MLNQGxCtBQ8wAmjm7
* iocost, 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
* iocost, QoS: None
https://photos.app.goo.gl/T2HedKD2sywQgj7R9
* iocost, 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
* iocost, QoS: None
https://photos.app.goo.gl/iyQBsky7bmM54Xiq7
* iocost, QoS: rpct=95.00 rlat=10000 wpct=95.00 wlat=20000 min=50.00 max=400.00
https://photos.app.goo.gl/q1a6URLDxPLMrnHy5
* NVME SSD (ran with 8 concurrent fio jobs to achieve saturation)
* No IO control
https://photos.app.goo.gl/S6xjEVTJzcfb3w1j7
* iocost, QoS: None
https://photos.app.goo.gl/SjQUUotJBAGr7vqz7
* iocost, QoS: rpct=95.00 rlat=5000 wpct=95.00 wlat=5000 min=1.00 max=10000.00
https://photos.app.goo.gl/RsaYBd2muX7CegoN7

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 the current block/for-next 53fc55c817c3 ("Merge branch 'for-5.4/block' into for-next") and 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-alloc_time_ns.patch 0008-blkcg-implement-blk-iocost.patch 0009-blkcg-add-tools-cgroup-iocost_monitor.py.patch 0010-blkcg-add-tools-cgroup-iocost_coef_gen.py.patch

0001-0007 are prep patches.
0008 implements blk-iocost.
0009 adds monitoring script.
0010 adds linear cost model coefficient generation script.

The patchset is also available in the following git branch.

git://git.kernel.org/pub/scm/linux/kernel/git/tj/cgroup.git review-iow-v2

diffstat follows, Thanks.

Documentation/admin-guide/cgroup-v2.rst |   97 +
block/Kconfig                           |   13 
block/Makefile                          |    1 
block/bfq-cgroup.c                      |    5 
block/blk-cgroup.c                      |   71 
block/blk-core.c                        |    4 
block/blk-iocost.c                      | 2395 ++++++++++++++++++++++++++++++++
block/blk-iolatency.c                   |    8 
block/blk-mq.c                          |   13 
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 
include/linux/blk-cgroup.h              |    4 
include/linux/blk_types.h               |    3 
include/linux/blkdev.h                  |   13 
include/trace/events/iocost.h           |  174 ++
tools/cgroup/iocost_coef_gen.py         |  178 ++
tools/cgroup/iocost_monitor.py          |  270 +++
21 files changed, 3272 insertions(+), 53 deletions(-)

--
tejun

[1] http://lkml.kernel.org/r/[email protected]
[2] http://lkml.kernel.org/r/[email protected]

author maintainer
#30 lore raw
Quoted 4 lines · Paolo Valente

I see an important interface problem. Userspace has been waiting for io.weight to become eventually the file name for setting the weight for the proportional-share policy [1,2]. If you use that name, how will we solve this?

So, my plan is just disabling iocost if bfq is selected as the io scheduler. It makes no sense to use them together anyway. What do you wanna do about the existing interface files prefixed with bfq? Just rename them?

Thanks.

Signature · 1 line
tejun