From: Christoph Hellwig <hch@lst.de>
To: Tejun Heo <tj@kernel.org>, Jens Axboe <axboe@kernel.dk>
Cc: linux-block@vger.kernel.org
Subject: [PATCH 04/17] blk-cgroup: cleanup the blkg_lookup family of functions
Date: Wed, 21 Sep 2022 20:04:48 +0200 [thread overview]
Message-ID: <20220921180501.1539876-5-hch@lst.de> (raw)
In-Reply-To: <20220921180501.1539876-1-hch@lst.de>
Add a fully inlined blkg_lookup as the extra two checks aren't going
to generated a lot more code vs the call to the slowpath routine, and
open code the hint update in the two callers that care.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
block/blk-cgroup.c | 38 +++++++++++++++-----------------------
block/blk-cgroup.h | 39 ++++++++++++---------------------------
2 files changed, 27 insertions(+), 50 deletions(-)
diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c
index b9a1dcee5a244..d1216760d0255 100644
--- a/block/blk-cgroup.c
+++ b/block/blk-cgroup.c
@@ -263,29 +263,13 @@ static struct blkcg_gq *blkg_alloc(struct blkcg *blkcg, struct request_queue *q,
return NULL;
}
-struct blkcg_gq *blkg_lookup_slowpath(struct blkcg *blkcg,
- struct request_queue *q, bool update_hint)
+static void blkg_update_hint(struct blkcg *blkcg, struct blkcg_gq *blkg)
{
- struct blkcg_gq *blkg;
-
- /*
- * Hint didn't match. Look up from the radix tree. Note that the
- * hint can only be updated under queue_lock as otherwise @blkg
- * could have already been removed from blkg_tree. The caller is
- * responsible for grabbing queue_lock if @update_hint.
- */
- blkg = radix_tree_lookup(&blkcg->blkg_tree, q->id);
- if (blkg && blkg->q == q) {
- if (update_hint) {
- lockdep_assert_held(&q->queue_lock);
- rcu_assign_pointer(blkcg->blkg_hint, blkg);
- }
- return blkg;
- }
+ lockdep_assert_held(&blkg->q->queue_lock);
- return NULL;
+ if (blkcg != &blkcg_root && blkg != rcu_dereference(blkcg->blkg_hint))
+ rcu_assign_pointer(blkcg->blkg_hint, blkg);
}
-EXPORT_SYMBOL_GPL(blkg_lookup_slowpath);
/*
* If @new_blkg is %NULL, this function tries to allocate a new one as
@@ -397,9 +381,11 @@ static struct blkcg_gq *blkg_lookup_create(struct blkcg *blkcg,
return blkg;
spin_lock_irqsave(&q->queue_lock, flags);
- blkg = __blkg_lookup(blkcg, q, true);
- if (blkg)
+ blkg = blkg_lookup(blkcg, q);
+ if (blkg) {
+ blkg_update_hint(blkcg, blkg);
goto found;
+ }
/*
* Create blkgs walking down from blkcg_root to @blkcg, so that all
@@ -621,12 +607,18 @@ static struct blkcg_gq *blkg_lookup_check(struct blkcg *blkcg,
const struct blkcg_policy *pol,
struct request_queue *q)
{
+ struct blkcg_gq *blkg;
+
WARN_ON_ONCE(!rcu_read_lock_held());
lockdep_assert_held(&q->queue_lock);
if (!blkcg_policy_enabled(q, pol))
return ERR_PTR(-EOPNOTSUPP);
- return __blkg_lookup(blkcg, q, true /* update_hint */);
+
+ blkg = blkg_lookup(blkcg, q);
+ if (blkg)
+ blkg_update_hint(blkcg, blkg);
+ return blkg;
}
/**
diff --git a/block/blk-cgroup.h b/block/blk-cgroup.h
index 30396cad50e9a..91b7ae0773be6 100644
--- a/block/blk-cgroup.h
+++ b/block/blk-cgroup.h
@@ -178,8 +178,6 @@ struct blkcg_policy {
extern struct blkcg blkcg_root;
extern bool blkcg_debug_stats;
-struct blkcg_gq *blkg_lookup_slowpath(struct blkcg *blkcg,
- struct request_queue *q, bool update_hint);
int blkcg_init_queue(struct request_queue *q);
void blkcg_exit_queue(struct request_queue *q);
@@ -227,22 +225,21 @@ static inline bool bio_issue_as_root_blkg(struct bio *bio)
}
/**
- * __blkg_lookup - internal version of blkg_lookup()
+ * blkg_lookup - lookup blkg for the specified blkcg - q pair
* @blkcg: blkcg of interest
* @q: request_queue of interest
- * @update_hint: whether to update lookup hint with the result or not
*
- * This is internal version and shouldn't be used by policy
- * implementations. Looks up blkgs for the @blkcg - @q pair regardless of
- * @q's bypass state. If @update_hint is %true, the caller should be
- * holding @q->queue_lock and lookup hint is updated on success.
+ * Lookup blkg for the @blkcg - @q pair.
+
+ * Must be called in a RCU critical section.
*/
-static inline struct blkcg_gq *__blkg_lookup(struct blkcg *blkcg,
- struct request_queue *q,
- bool update_hint)
+static inline struct blkcg_gq *blkg_lookup(struct blkcg *blkcg,
+ struct request_queue *q)
{
struct blkcg_gq *blkg;
+ WARN_ON_ONCE(!rcu_read_lock_held());
+
if (blkcg == &blkcg_root)
return q->root_blkg;
@@ -250,22 +247,10 @@ static inline struct blkcg_gq *__blkg_lookup(struct blkcg *blkcg,
if (blkg && blkg->q == q)
return blkg;
- return blkg_lookup_slowpath(blkcg, q, update_hint);
-}
-
-/**
- * blkg_lookup - lookup blkg for the specified blkcg - q pair
- * @blkcg: blkcg of interest
- * @q: request_queue of interest
- *
- * Lookup blkg for the @blkcg - @q pair. This function should be called
- * under RCU read lock.
- */
-static inline struct blkcg_gq *blkg_lookup(struct blkcg *blkcg,
- struct request_queue *q)
-{
- WARN_ON_ONCE(!rcu_read_lock_held());
- return __blkg_lookup(blkcg, q, false);
+ blkg = radix_tree_lookup(&blkcg->blkg_tree, q->id);
+ if (blkg && blkg->q != q)
+ blkg = NULL;
+ return blkg;
}
/**
--
2.30.2
next prev parent reply other threads:[~2022-09-21 18:05 UTC|newest]
Thread overview: 41+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-21 18:04 blk-cgroup cleanups Christoph Hellwig
2022-09-21 18:04 ` [PATCH 01/17] blk-cgroup: fix error unwinding in blkcg_init_queue Christoph Hellwig
2022-09-22 13:00 ` Andreas Herrmann
2022-09-21 18:04 ` [PATCH 02/17] blk-cgroup: remove blk_queue_root_blkg Christoph Hellwig
2022-09-22 13:03 ` Andreas Herrmann
2022-09-21 18:04 ` [PATCH 03/17] blk-cgroup: remove open coded blkg_lookup instances Christoph Hellwig
2022-09-22 13:17 ` Andreas Herrmann
2022-09-26 20:56 ` Tejun Heo
2022-09-21 18:04 ` Christoph Hellwig [this message]
2022-09-22 14:15 ` [PATCH 04/17] blk-cgroup: cleanup the blkg_lookup family of functions Andreas Herrmann
2022-09-26 20:58 ` Tejun Heo
2022-09-21 18:04 ` [PATCH 05/17] blk-cgroup: remove blkg_lookup_check Christoph Hellwig
2022-09-22 14:16 ` Andreas Herrmann
2022-09-26 21:18 ` Tejun Heo
2022-09-21 18:04 ` [PATCH 06/17] blk-cgroup: pass a gendisk to blkcg_init_queue and blkcg_exit_queue Christoph Hellwig
2022-09-22 13:34 ` Andreas Herrmann
2022-09-21 18:04 ` [PATCH 07/17] blk-ioprio: pass a gendisk to blk_ioprio_init and blk_ioprio_exit Christoph Hellwig
2022-09-22 13:38 ` Andreas Herrmann
2022-09-21 18:04 ` [PATCH 08/17] blk-iolatency: pass a gendisk to blk_iolatency_init Christoph Hellwig
2022-09-22 13:40 ` Andreas Herrmann
2022-09-27 1:19 ` Jens Axboe
2022-09-21 18:04 ` [PATCH 09/17] blk-iocost: simplify ioc_name Christoph Hellwig
2022-09-22 12:10 ` Andreas Herrmann
2022-09-21 18:04 ` [PATCH 10/17] blk-iocost: pass a gendisk to blk_iocost_init Christoph Hellwig
2022-09-22 12:11 ` Andreas Herrmann
2022-09-21 18:04 ` [PATCH 11/17] blk-iocost: cleanup ioc_qos_write Christoph Hellwig
2022-09-22 12:11 ` Andreas Herrmann
2022-09-21 18:04 ` [PATCH 12/17] blk-throttle: pass a gendisk to blk_throtl_init and blk_throtl_exit Christoph Hellwig
2022-09-23 6:38 ` Andreas Herrmann
2022-09-21 18:04 ` [PATCH 13/17] blk-throttle: pass a gendisk to blk_throtl_register_queue Christoph Hellwig
2022-09-23 6:39 ` Andreas Herrmann
2022-09-21 18:04 ` [PATCH 14/17] blk-throttle: pass a gendisk to blk_throtl_cancel_bios Christoph Hellwig
2022-09-23 6:42 ` Andreas Herrmann
2022-09-21 18:04 ` [PATCH 15/17] blk-cgroup: pass a gendisk to blkg_destroy_all Christoph Hellwig
2022-09-22 13:42 ` Andreas Herrmann
2022-09-21 18:05 ` [PATCH 16/17] blk-cgroup: pass a gendisk to blkcg_schedule_throttle Christoph Hellwig
2022-09-22 14:21 ` Andreas Herrmann
2022-09-21 18:05 ` [PATCH 17/17] blk-cgroup: pass a gendisk to the blkg allocation helpers Christoph Hellwig
2022-09-23 7:03 ` Andreas Herrmann
2022-09-26 21:26 ` blk-cgroup cleanups Tejun Heo
2022-09-27 1:19 ` Jens Axboe
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220921180501.1539876-5-hch@lst.de \
--to=hch@lst.de \
--cc=axboe@kernel.dk \
--cc=linux-block@vger.kernel.org \
--cc=tj@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).