Skip to content

Commit 2badf06

Browse files
Christoph Hellwigaxboe
authored andcommitted
block: merge __bio_associate_blkg into bio_associate_blkg_from_css
Merge __bio_associate_blkg into the only caller, which allows to slightly reduce the RCU crticial section and better explain the code flow. Acked-by: Tejun Heo <tj@kernel.org> Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com> Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent d92c370 commit 2badf06

1 file changed

Lines changed: 13 additions & 32 deletions

File tree

‎block/bio.c‎

Lines changed: 13 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1628,52 +1628,33 @@ int bioset_init_from_src(struct bio_set *bs, struct bio_set *src)
16281628
EXPORT_SYMBOL(bioset_init_from_src);
16291629

16301630
#ifdef CONFIG_BLK_CGROUP
1631-
1632-
/**
1633-
* __bio_associate_blkg - associate a bio with the a blkg
1634-
* @bio: target bio
1635-
* @blkg: the blkg to associate
1636-
*
1637-
* This tries to associate @bio with the specified @blkg. Association failure
1638-
* is handled by walking up the blkg tree. Therefore, the blkg associated can
1639-
* be anything between @blkg and the root_blkg. This situation only happens
1640-
* when a cgroup is dying and then the remaining bios will spill to the closest
1641-
* alive blkg.
1642-
*
1643-
* A reference will be taken on the @blkg and will be released when @bio is
1644-
* freed.
1645-
*/
1646-
static void __bio_associate_blkg(struct bio *bio, struct blkcg_gq *blkg)
1647-
{
1648-
if (bio->bi_blkg)
1649-
blkg_put(bio->bi_blkg);
1650-
bio->bi_blkg = blkg_tryget_closest(blkg);
1651-
}
1652-
16531631
/**
16541632
* bio_associate_blkg_from_css - associate a bio with a specified css
16551633
* @bio: target bio
16561634
* @css: target css
16571635
*
16581636
* Associate @bio with the blkg found by combining the css's blkg and the
1659-
* request_queue of the @bio. This falls back to the queue's root_blkg if
1660-
* the association fails with the css.
1637+
* request_queue of the @bio. An association failure is handled by walking up
1638+
* the blkg tree. Therefore, the blkg associated can be anything between @blkg
1639+
* and q->root_blkg. This situation only happens when a cgroup is dying and
1640+
* then the remaining bios will spill to the closest alive blkg.
1641+
*
1642+
* A reference will be taken on the blkg and will be released when @bio is
1643+
* freed.
16611644
*/
16621645
void bio_associate_blkg_from_css(struct bio *bio,
16631646
struct cgroup_subsys_state *css)
16641647
{
16651648
struct request_queue *q = bio->bi_disk->queue;
1666-
struct blkcg_gq *blkg;
1649+
struct blkcg_gq *blkg = q->root_blkg;
16671650

1668-
rcu_read_lock();
1651+
if (bio->bi_blkg)
1652+
blkg_put(bio->bi_blkg);
16691653

1670-
if (!css || !css->parent)
1671-
blkg = q->root_blkg;
1672-
else
1654+
rcu_read_lock();
1655+
if (css && css->parent)
16731656
blkg = blkg_lookup_create(css_to_blkcg(css), q);
1674-
1675-
__bio_associate_blkg(bio, blkg);
1676-
1657+
bio->bi_blkg = blkg_tryget_closest(blkg);
16771658
rcu_read_unlock();
16781659
}
16791660
EXPORT_SYMBOL_GPL(bio_associate_blkg_from_css);

0 commit comments

Comments
 (0)