blkcg: change blkg reference counting to use percpu_ref

Every bio is now associated with a blkg putting blkg_get, blkg_try_get,
and blkg_put on the hot path. Switch over the refcnt in blkg to use
percpu_ref.

Signed-off-by: Dennis Zhou <dennis@kernel.org>
Acked-by: Tejun Heo <tj@kernel.org>
Reviewed-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
This commit is contained in:
Dennis Zhou 2018-12-05 12:10:38 -05:00 committed by Jens Axboe
parent 6f70fb6618
commit 7fcf2b033b
2 changed files with 44 additions and 12 deletions

View file

@ -124,7 +124,7 @@ struct blkcg_gq {
struct blkcg_gq *parent;
/* reference count */
atomic_t refcnt;
struct percpu_ref refcnt;
/* is this blkg online? protected by both blkcg and q locks */
bool online;
@ -487,8 +487,7 @@ static inline int blkg_path(struct blkcg_gq *blkg, char *buf, int buflen)
*/
static inline void blkg_get(struct blkcg_gq *blkg)
{
WARN_ON_ONCE(atomic_read(&blkg->refcnt) <= 0);
atomic_inc(&blkg->refcnt);
percpu_ref_get(&blkg->refcnt);
}
/**
@ -500,7 +499,7 @@ static inline void blkg_get(struct blkcg_gq *blkg)
*/
static inline struct blkcg_gq *blkg_try_get(struct blkcg_gq *blkg)
{
if (atomic_inc_not_zero(&blkg->refcnt))
if (percpu_ref_tryget(&blkg->refcnt))
return blkg;
return NULL;
}
@ -514,23 +513,19 @@ static inline struct blkcg_gq *blkg_try_get(struct blkcg_gq *blkg)
*/
static inline struct blkcg_gq *blkg_try_get_closest(struct blkcg_gq *blkg)
{
while (!atomic_inc_not_zero(&blkg->refcnt))
while (!percpu_ref_tryget(&blkg->refcnt))
blkg = blkg->parent;
return blkg;
}
void __blkg_release_rcu(struct rcu_head *rcu);
/**
* blkg_put - put a blkg reference
* @blkg: blkg to put
*/
static inline void blkg_put(struct blkcg_gq *blkg)
{
WARN_ON_ONCE(atomic_read(&blkg->refcnt) <= 0);
if (atomic_dec_and_test(&blkg->refcnt))
call_rcu(&blkg->rcu_head, __blkg_release_rcu);
percpu_ref_put(&blkg->refcnt);
}
/**