blkcg: Improve blkg config helpers and make iolatency init lazy
Subsystems (3)
Tejun Heo
maintainerPATCH v2 1/1 blkcg: Improve blkg config helpers and make iolatency init lazy
Hello,
v2 fixes the build failure caused by v1[1] forgetting to update bfq.
This patchset:
* Improves blkg config helpers so that they can be used consistently for all the existing use cases. This also allows keeps using the same bdev open instance across lazy init of rq_qos policies.
* Updates iolatency so that it initializes lazily when a latency target is set for the first time. This avoids registering the rq_qos policy when iolatency is not used which removes unnecessary calls into iolat from IO hot paths.
and contains the following four patches:
0001-blkcg-Drop-unnecessary-RCU-read-un-locks-from-blkg_c.patch 0002-blkcg-Restructure-blkg_conf_prep-and-friends.patch 0003-blk-iolatency-s-blkcg_rq_qos-iolat_rq_qos.patch 0004-blk-iolatency-Make-initialization-lazy.patch
and is also available in the following git branch.
git://git.kernel.org/pub/scm/linux/kernel/git/tj/misc.git iolat-lazy-init-v2
diffstat follows. Thanks.
block/bfq-cgroup.c | 8 +++-- block/blk-cgroup.c | 120 ++++++++++++++++++++++++++++++++++++++++++---------------------------------- block/blk-cgroup.h | 10 +++--- block/blk-iocost.c | 58 +++++++++++++++++++++--------------- block/blk-iolatency.c | 39 +++++++++++++++++++++--- block/blk-rq-qos.h | 2 - block/blk-throttle.c | 16 ++++++---- block/blk.h | 6 --- 8 files changed, 157 insertions(+), 102 deletions(-)
[1] https://lkml.kernel.org/r/[email protected]
--
tejun
Tejun Heo
maintainerPATCH 1/4 blkcg: Drop unnecessary RCU read [un]locks from blkg_conf_prep/finish()
Holding the queue lock now implies RCU read lock, so no need to use rcu_read_[un]lock() explicitly. This shouldn't cause any behavior changes.
While at it, drop __acquires() annotation on the queue lock too. The __acquires() part was already out of sync and it doesn't catch anything that lockdep can't.
--- block/blk-cgroup.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-)
block/blk-cgroup.c +2 -9
@@ -672,12 +672,11 @@ struct block_device *blkcg_conf_open_bdev(char **inputp)* * Parse per-blkg config update from @input and initialize @ctx with the * result. @ctx->blkg points to the blkg to be updated and @ctx->body the -* part of @input following MAJ:MIN. This function returns with RCU read -* lock and queue lock held and must be paired with blkg_conf_finish(). +* part of @input following MAJ:MIN. This function returns with queue lock +* held and must be paired with blkg_conf_finish(). */ int blkg_conf_prep (struct blkcg *blkcg,const struct blkcg_policy *pol,char *input,struct blkg_conf_ctx *ctx) - __acquires(rcu) __acquires(&bdev->bd_queue->queue_lock) {struct block_device *bdev;struct gendisk *disk;
@@ -699,7 +698,6 @@ int blkg_conf_prep(struct blkcg *blkcg, const struct blkcg_policy *pol,if (ret) goto fail; -rcu_read_lock ();spin_lock_irq (&q->queue_lock);if (!blkcg_policy_enabled (q, pol)) {
@@ -728,7 +726,6 @@ int blkg_conf_prep(struct blkcg *blkcg, const struct blkcg_policy *pol,/* Drop locks to do new blkg allocation with GFP_KERNEL. */ spin_unlock_irq (&q->queue_lock); -rcu_read_unlock (); new_blkg =blkg_alloc (pos, disk,GFP_KERNEL );if (unlikely (!new_blkg)) {
@@ -742,7 +739,6 @@ int blkg_conf_prep(struct blkcg *blkcg, const struct blkcg_policy *pol, goto fail_exit_queue; } -rcu_read_lock ();spin_lock_irq (&q->queue_lock);if (!blkcg_policy_enabled (q, pol)) {
@@ -778,7 +774,6 @@ int blkg_conf_prep(struct blkcg *blkcg, const struct blkcg_policy *pol,radix_tree_preload_end (); fail_unlock:spin_unlock_irq (&q->queue_lock); -rcu_read_unlock (); fail_exit_queue:blk_queue_exit (q); fail:
@@ -805,10 +800,8 @@ EXPORT_SYMBOL_GPL(blkg_conf_prep);* with blkg_conf_prep(). */ void blkg_conf_finish (struct blkg_conf_ctx *ctx) - __releases(&ctx->bdev->bd_queue->queue_lock) __releases(rcu) {spin_unlock_irq (&bdev_get_queue (ctx->bdev)->queue_lock); -rcu_read_unlock ();blkdev_put_no_open (ctx->bdev); }EXPORT_SYMBOL_GPL (blkg_conf_finish);
Signature · 1 line
2.39.0
Re: [PATCH 1/4] blkcg: Drop unnecessary RCU read [un]locks from blkg_conf_prep/finish()
Quoted 2 lines · Tejun Heo
Holding the queue lock now implies RCU read lock, so no need to use rcu_read_[un]lock() explicitly. This shouldn't cause any behavior changes.
How so?
Quoted 3 lines
While at it, drop
__acquires()annotation on the queue lock too. The__acquires()part was already out of sync and it doesn't catch anything that lockdep can't.
This makes sparse even more unhappy than it was before. For now please keep the annotation.
Tejun Heo
maintainerRe: [PATCH 1/4] blkcg: Drop unnecessary RCU read [un]locks from blkg_conf_prep/finish()
Hello, Christoph.
Quoted 5 lines · Christoph Hellwig
Quoted 2 lines · Tejun Heo
Holding the queue lock now implies RCU read lock, so no need to use rcu_read_[un]lock() explicitly. This shouldn't cause any behavior changes.
How so?
Now that all RCU flavors have been combined, holding a spin lock, disabling irq, disabling preemption all imply RCU read lock.
Quoted 6 lines
Quoted 3 lines
While at it, drop
__acquires()annotation on the queue lock too. The__acquires()part was already out of sync and it doesn't catch anything that lockdep can't.This makes sparse even more unhappy than it was before. For now please keep the annotation.
I can drop the changes but this actually bothers me. The annotation has been broken for a *long* time and nobody noticed. Furthermore, I can't remember a time when __acquires/__releases notation caught anything that lockdep couldn't trivially and can't even think of a way how it could. AFAICS, these annotations don't contribute anything other than preservation of themselves. I don't see why we would want to keep them.
Thanks.
Signature · 1 line
tejun
Re: [PATCH 1/4] blkcg: Drop unnecessary RCU read [un]locks from blkg_conf_prep/finish()
Quoted 2 lines · Tejun Heo
Now that all RCU flavors have been combined, holding a spin lock, disabling irq, disabling preemption all imply RCU read lock.
Can you write it like this in the commit log, please?
Quoted 6 lines
I can drop the changes but this actually bothers me. The annotation has been broken for a *long* time and nobody noticed. Furthermore, I can't remember a time when __acquires/__releases notation caught anything that lockdep couldn't trivially and can't even think of a way how it could. AFAICS, these annotations don't contribute anything other than preservation of themselves. I don't see why we would want to keep them.
People have noticed it. It just hasn't been a priority as there are lots of even more problematic things.
Tejun Heo
maintainerRe: [PATCH 1/4] blkcg: Drop unnecessary RCU read [un]locks from blkg_conf_prep/finish()
Hello,
Quoted 5 lines · Christoph Hellwig
Quoted 2 lines · Tejun Heo
Now that all RCU flavors have been combined, holding a spin lock, disabling irq, disabling preemption all imply RCU read lock.
Can you write it like this in the commit log, please?
Sure, will do.
Quoted 9 lines
Quoted 6 lines
I can drop the changes but this actually bothers me. The annotation has been broken for a *long* time and nobody noticed. Furthermore, I can't remember a time when __acquires/__releases notation caught anything that lockdep couldn't trivially and can't even think of a way how it could. AFAICS, these annotations don't contribute anything other than preservation of themselves. I don't see why we would want to keep them.
People have noticed it. It just hasn't been a priority as there are lots of even more problematic things.
That doesn't really shed a positive light on them, does it? I'll drop this part but can you think of actual reasons to keep these around other than to keep sparse happy? I'm genuninely curious and have asked several people. Nobody had a good answer.
Thanks.
Signature · 1 line
tejun
Tejun Heo
maintainerPATCH 2/4 blkcg: Restructure blkg_conf_prep() and friends
In reply to Tejun HeoWe want to support lazy init of rq-qos policies so that iolatency is enabled lazily on configuration instead of gendisk initialization. The way blkg config helpers are structured now is a bit awkward for that. Let's restructure:
* blkcg_conf_open_bdev() is renamed to blkg_conf_open_bdev(). The blkcg_ prefix was used because the bdev opening step is blkg-independent. However, the distinction is too subtle and confuses more than helps. Let's switch to blkg prefix so that it's consistent with the type and other helper names.
* struct blkg_conf_ctx now remembers the original input string and is always initialized by the new blkg_conf_init().
* blkg_conf_open_bdev() is updated to take a pointer to blkg_conf_ctx like blkg_conf_prep() and can be called multiple times safely. Instead of modifying the double pointer to input string directly, blkg_conf_open_bdev() now sets blkg_conf_ctx->body.
* blkg_conf_finish() is renamed to blkg_conf_exit() for symmetry and now must be called on all blkg_conf_ctx's which were initialized with blkg_conf_init().
Combined, this allows the users to either open the bdev first or do it altogether with blkg_conf_prep() which will help implementing lazy init of rq-qos policies.
Users are updated accordingly. No behavior change is intended by this patch.
v2: bfq wasn't updated in v1 causing a build error. Fixed.
--- block/bfq-cgroup.c | 8 ++-- block/blk-cgroup.c | 105 +++++++++++++++++++++++++++--------------- block/blk-cgroup.h | 10 ++-- block/blk-iocost.c | 58 +++++++++++++---------- block/blk-iolatency.c | 8 ++-- block/blk-throttle.c | 16 ++++--- 6 files changed, 127 insertions(+), 78 deletions(-)
block/bfq-cgroup.c +5 -3
@@ -1115,9 +1115,11 @@ static ssize_t bfq_io_set_device_weight(struct kernfs_open_file *of,struct bfq_group *bfqg;u64 v; - ret =blkg_conf_prep (blkcg, &blkcg_policy_bfq, buf, &ctx); +blkg_conf_init (&ctx, buf); + + ret =blkg_conf_prep (blkcg, &blkcg_policy_bfq, &ctx);if (ret) -return ret; + goto out;if (sscanf (ctx.body,"%llu" , &v) ==1 ) {/* require "default" on dfl */
@@ -1139,7 +1141,7 @@ static ssize_t bfq_io_set_device_weight(struct kernfs_open_file *of, ret =0 ; } out: -blkg_conf_finish (&ctx); +blkg_conf_exit (&ctx);return ret ?: nbytes; }
block/blk-cgroup.c +67 -38
169 lines not on this page · raw message
block/blk-cgroup.h +6 -4
@@ -208,15 +208,17 @@ void blkcg_print_blkgs(struct seq_file *sf, struct blkcg *blkcg,u64 __blkg_prfill_u64 (struct seq_file *sf,struct blkg_policy_data *pd,u64 v);struct blkg_conf_ctx { +char *input; +char *body;struct block_device *bdev;struct blkcg_gq *blkg; -char *body; }; -struct block_device *blkcg_conf_open_bdev (char **inputp); +void blkg_conf_init (struct blkg_conf_ctx *ctx,char *input); +int blkg_conf_open_bdev (struct blkg_conf_ctx *ctx);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); +struct blkg_conf_ctx *ctx); +void blkg_conf_exit (struct blkg_conf_ctx *ctx);/** * bio_issue_as_root_blkg - see if this bio needs to be issued as root blkg
block/blk-iocost.c +34 -24
138 lines not on this page · raw message
block/blk-iolatency.c +5 -3
@@ -842,9 +842,11 @@ static ssize_t iolatency_set_limit(struct kernfs_open_file *of, char *buf,u64 oldval;int ret; - ret =blkg_conf_prep (blkcg, &blkcg_policy_iolatency, buf, &ctx); +blkg_conf_init (&ctx, buf); + + ret =blkg_conf_prep (blkcg, &blkcg_policy_iolatency, &ctx);if (ret) -return ret; + goto out; iolat =blkg_to_lat (ctx.blkg); p = ctx.body;
@@ -880,7 +882,7 @@ static ssize_t iolatency_set_limit(struct kernfs_open_file *of, char *buf,iolatency_clear_scaling (blkg); ret =0 ; out: -blkg_conf_finish (&ctx); +blkg_conf_exit (&ctx);return ret ?: nbytes; }
block/blk-throttle.c +10 -6
@@ -1369,9 +1369,11 @@ static ssize_t tg_set_conf(struct kernfs_open_file *of,int ret;u64 v; - ret =blkg_conf_prep (blkcg, &blkcg_policy_throtl, buf, &ctx); +blkg_conf_init (&ctx, buf); + + ret =blkg_conf_prep (blkcg, &blkcg_policy_throtl, &ctx);if (ret) -return ret; + goto out_finish; ret = -EINVAL ;if (sscanf (ctx.body,"%llu" , &v) !=1 )
@@ -1390,7 +1392,7 @@ static ssize_t tg_set_conf(struct kernfs_open_file *of,tg_conf_updated (tg, false); ret =0 ; out_finish: -blkg_conf_finish (&ctx); +blkg_conf_exit (&ctx);return ret ?: nbytes; }
@@ -1562,9 +1564,11 @@ static ssize_t tg_set_limit(struct kernfs_open_file *of,int ret;int index =of_cft (of)->private; - ret =blkg_conf_prep (blkcg, &blkcg_policy_throtl, buf, &ctx); +blkg_conf_init (&ctx, buf); + + ret =blkg_conf_prep (blkcg, &blkcg_policy_throtl, &ctx);if (ret) -return ret; + goto out_finish; tg =blkg_to_tg (ctx.blkg);tg_update_carryover (tg);
@@ -1663,7 +1667,7 @@ static ssize_t tg_set_limit(struct kernfs_open_file *of, tg->td->limit_valid[LIMIT_LOW]); ret =0 ; out_finish: -blkg_conf_finish (&ctx); +blkg_conf_exit (&ctx);return ret ?: nbytes; }
Signature · 1 line
2.39.0
Re: [PATCH 2/4] blkcg: Restructure blkg_conf_prep() and friends
Quoted 4 lines · Tejun Heo
*
blkg_conf_open_bdev()is updated to take a pointer toblkg_conf_ctxlikeblkg_conf_prep()and can be called multiple times safely. Instead of modifying the double pointer to input string directly,blkg_conf_open_bdev()now setsblkg_conf_ctx->body.
This looks pretty awkward for the externals callers of blkcg_conf_open_bdev in blk-iocost. I'd either keep the calling conventions as they are at the moment, or just open code blkcg_conf_open_bdev in blk-iocost.
Tejun Heo
maintainerRe: [PATCH 2/4] blkcg: Restructure blkg_conf_prep() and friends
Quoted 9 lines · Christoph Hellwig
Quoted 4 lines · Tejun Heo
*
blkg_conf_open_bdev()is updated to take a pointer toblkg_conf_ctxlikeblkg_conf_prep()and can be called multiple times safely. Instead of modifying the double pointer to input string directly,blkg_conf_open_bdev()now setsblkg_conf_ctx->body.This looks pretty awkward for the externals callers of
blkcg_conf_open_bdevin blk-iocost. I'd either keep the calling conventions as they are at the moment, or just open codeblkcg_conf_open_bdevin blk-iocost.
Because we're coming in from cgroupfs, we aren't synchronizing properly against blkdevs going away. For all config attempt coming in from cgroup side, we'll need to synchronize explicitly and these config helper blocks look like a good place to do so. Please take a look at the thread with Yu Kuai. Imma update the comment to include that but yeah let's keep it this way for that.
Thanks.
Signature · 1 line
tejun
Tejun Heo
maintainerPATCH 3/4 blk-iolatency: s/blkcg_rq_qos/iolat_rq_qos/
In reply to Tejun HeoThe name was too generic given that there are multiple blkcg rq-qos policies.
--- block/blk-iolatency.c | 2 +- block/blk-rq-qos.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
block/blk-iolatency.c +1 -1
@@ -976,7 +976,7 @@ static void iolatency_pd_init(struct blkg_policy_data *pd) {struct iolatency_grp *iolat =pd_to_lat (pd);struct blkcg_gq *blkg =lat_to_blkg (iolat); -struct rq_qos *rqos =blkcg_rq_qos (blkg->q); +struct rq_qos *rqos =iolat_rq_qos (blkg->q);struct blk_iolatency *blkiolat =BLKIOLATENCY (rqos);u64 now =ktime_to_ns (ktime_get ());int cpu;
block/blk-rq-qos.h +1 -1
@@ -74,7 +74,7 @@ static inline struct rq_qos *wbt_rq_qos(struct request_queue *q)return rq_qos_id (q,RQ_QOS_WBT ); } -static inline struct rq_qos *blkcg_rq_qos (struct request_queue *q) +static inline struct rq_qos *iolat_rq_qos (struct request_queue *q) {return rq_qos_id (q,RQ_QOS_LATENCY ); }
Signature · 1 line
2.39.0
Re: [PATCH 3/4] blk-iolatency: s/blkcg_rq_qos/iolat_rq_qos/
Looks good:
Tejun Heo
maintainerPATCH 4/4 blk-iolatency: Make initialization lazy
In reply to Tejun HeoOther rq_qos policies such as wbt and iocost are lazy-initialized when they are configured for the first time for the device but iolatency is initialized unconditionally from blkcg_init_disk() during gendisk init. Lazy init is beneficial because rq_qos policies add runtime overhead when initialized as every IO has to walk all registered rq_qos callbacks.
This patch switches iolatency to lazy initialization too so that it only registered its rq_qos policy when it is first configured.
Note that there is a known race condition between blkcg config file writes and del_gendisk() and this patch makes iolatency susceptible to it by exposing the init path to race against the deletion path. However, that problem already exists in iocost and is being worked on.
--- block/blk-cgroup.c | 8 -------- block/blk-iolatency.c | 29 ++++++++++++++++++++++++++++- block/blk.h | 6 ------ 3 files changed, 28 insertions(+), 15 deletions(-)
block/blk-cgroup.c +0 -8
@@ -33,7 +33,6 @@#include "blk-cgroup.h" #include "blk-ioprio.h" #include "blk-throttle.h" -#include "blk-rq-qos.h" /* * blkcg_pol_mutex protects blkcg_policy[] and policy [de]activation.
@@ -1322,14 +1321,8 @@ int blkcg_init_disk(struct gendisk *disk)if (ret) goto err_ioprio_exit; - ret =blk_iolatency_init (disk); -if (ret) - goto err_throtl_exit; -return 0 ; -err_throtl_exit: -blk_throtl_exit (disk); err_ioprio_exit:blk_ioprio_exit (disk); err_destroy_all:
@@ -1345,7 +1338,6 @@ int blkcg_init_disk(struct gendisk *disk)void blkcg_exit_disk (struct gendisk *disk) {blkg_destroy_all (disk); -rq_qos_exit (disk->queue);blk_throtl_exit (disk); }
block/blk-iolatency.c +28 -1
@@ -755,7 +755,7 @@ static void blkiolatency_enable_work_fn(struct work_struct *work) } } -int blk_iolatency_init (struct gendisk *disk) +static int blk_iolatency_init (struct gendisk *disk) {struct request_queue *q = disk->queue;struct blk_iolatency *blkiolat;
@@ -830,6 +830,29 @@ static void iolatency_clear_scaling(struct blkcg_gq *blkg) } } +static int blk_iolatency_try_init (struct blkg_conf_ctx *ctx) +{ +static DEFINE_MUTEX (init_mutex); +int ret; + + ret =blkg_conf_open_bdev (ctx); +if (ret) +return ret; + +/* +* blk_iolatency_init() may fail after rq_qos_add() succeeds which can +* confuse iolat_rq_qos() test. Make the test and init atomic. +*/ +mutex_lock (&init_mutex); + +if (!iolat_rq_qos (ctx->bdev->bd_queue)) + ret =blk_iolatency_init (ctx->bdev->bd_disk); + +mutex_unlock (&init_mutex); + +return ret; +} +static ssize_t iolatency_set_limit (struct kernfs_open_file *of,char *buf,size_t nbytes,loff_t off) {
@@ -844,6 +867,10 @@ static ssize_t iolatency_set_limit(struct kernfs_open_file *of, char *buf,blkg_conf_init (&ctx, buf); + ret =blk_iolatency_try_init (&ctx); +if (ret) + goto out; + ret =blkg_conf_prep (blkcg, &blkcg_policy_iolatency, &ctx);if (ret) goto out;
block/blk.h +0 -6
@@ -392,12 +392,6 @@ static inline struct bio *blk_queue_bounce(struct bio *bio,return bio; } -#ifdef CONFIG_BLK_CGROUP_IOLATENCY -int blk_iolatency_init (struct gendisk *disk); -#else -static inline int blk_iolatency_init (struct gendisk *disk) {return 0 ; }; -#endif -#ifdef CONFIG_BLK_DEV_ZONED void disk_free_zone_bitmaps (struct gendisk *disk);void disk_clear_zone_settings (struct gendisk *disk);
Signature · 1 line
2.39.0
Re: [PATCH 4/4] blk-iolatency: Make initialization lazy
Looks good: