Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Documentation/admin-guide/cgroup-v2.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3257,7 +3257,7 @@ the configuration, the bio may be executed at a lower priority and if
the writeback session is holding shared resources, e.g. a journal
entry, may lead to priority inversion. There is no one easy solution
for the problem. Filesystems can try to work around specific problem
cases by skipping wbc_init_bio() and using bio_associate_blkg()
cases by skipping wbc_init_bio() and using bio_associate_blkcg()
directly.


Expand Down
16 changes: 10 additions & 6 deletions block/bfq-cgroup.c
Original file line number Diff line number Diff line change
Expand Up @@ -363,11 +363,13 @@ void bfqg_and_blkg_put(struct bfq_group *bfqg)

void bfqg_stats_update_legacy_io(struct request_queue *q, struct request *rq)
{
struct bfq_group *bfqg = blkg_to_bfqg(rq->bio->bi_blkg);
struct blkcg_gq *blkg = bio_blkg_lookup(rq->bio);
struct bfq_group *bfqg;

if (!bfqg)
if (!blkg)
return;

bfqg = blkg_to_bfqg(blkg);
blkg_rwstat_add(&bfqg->stats.bytes, rq->cmd_flags, blk_rq_bytes(rq));
blkg_rwstat_add(&bfqg->stats.ios, rq->cmd_flags, 1);
}
Expand Down Expand Up @@ -606,23 +608,25 @@ static void bfq_link_bfqg(struct bfq_data *bfqd, struct bfq_group *bfqg)

struct bfq_group *bfq_bio_bfqg(struct bfq_data *bfqd, struct bio *bio)
{
struct blkcg_gq *blkg = bio->bi_blkg;
struct blkcg_gq *blkg = bio_blkg_lookup(bio);
struct bfq_group *bfqg;

while (blkg) {
if (!blkg->online) {
blkg = blkg->parent;
continue;
}

bfqg = blkg_to_bfqg(blkg);
if (bfqg->pd.online) {
bio_associate_blkg_from_css(bio, &blkg->blkcg->css);
bio_associate_blkcg_from_css(bio, &blkg->blkcg->css);
return bfqg;
}
blkg = blkg->parent;
}
bio_associate_blkg_from_css(bio,
&bfqg_to_blkg(bfqd->root_group)->blkcg->css);

blkg = bfqg_to_blkg(bfqd->root_group);
bio_associate_blkcg_from_css(bio, &blkg->blkcg->css);
return bfqd->root_group;
}

Expand Down
19 changes: 14 additions & 5 deletions block/bfq-iosched.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@

#include "elevator.h"
#include "blk.h"
#include "blk-cgroup.h"
#include "blk-mq.h"
#include "blk-mq-sched.h"
#include "bfq-iosched.h"
Expand Down Expand Up @@ -2452,15 +2453,16 @@ static bool bfq_bio_merge(struct request_queue *q, struct bio *bio,
struct request *free = NULL;
bool ret;

#ifdef CONFIG_BFQ_GROUP_IOSCHED
/* blkg creation takes q->queue_lock, so do it before bfqd->lock. */
if (bic)
bio_blkg(bio);
#endif

spin_lock_irq(&bfqd->lock);

if (bic) {
/*
* Make sure cgroup info is uptodate for current process before
* considering the merge.
*/
bfq_bic_update_cgroup(bic, bio);

bfqd->bio_bfqq = bic_to_bfqq(bic, op_is_sync(bio->bi_opf),
bfq_actuator_index(bfqd, bio));
} else {
Expand Down Expand Up @@ -6245,6 +6247,13 @@ static void bfq_insert_request(struct blk_mq_hw_ctx *hctx, struct request *rq,
LIST_HEAD(free);

#ifdef CONFIG_BFQ_GROUP_IOSCHED
/*
* Pin the blkg used to look up bfqg. If this is the first IO for
* the blkcg on this queue, create the bfqg before holding bfqd->lock.
*/
if (rq->bio && !bio_flagged(rq->bio, BIO_BLKG_REF))
bio_blkg(rq->bio);

if (!cgroup_subsys_on_dfl(io_cgrp_subsys) && rq->bio)
bfqg_stats_update_legacy_io(q, rq);
#endif
Expand Down
22 changes: 6 additions & 16 deletions block/bio.c
Original file line number Diff line number Diff line change
Expand Up @@ -179,12 +179,7 @@ static inline gfp_t try_alloc_gfp(gfp_t gfp)

void bio_uninit(struct bio *bio)
{
#ifdef CONFIG_BLK_CGROUP
if (bio->bi_blkg) {
blkg_put(bio->bi_blkg);
bio->bi_blkg = NULL;
}
#endif
bio_clear_blkcg(bio);
if (bio_integrity(bio))
bio_integrity_free(bio);

Expand Down Expand Up @@ -233,10 +228,10 @@ void bio_init(struct bio *bio, struct block_device *bdev, struct bio_vec *table,
bio->bi_end_io = NULL;
bio->bi_private = NULL;
#ifdef CONFIG_BLK_CGROUP
bio->bi_blkg = NULL;
bio->bi_blkcg = NULL;
bio->issue_time_ns = 0;
if (bdev)
bio_associate_blkg(bio);
bio_associate_blkcg(bio);
#ifdef CONFIG_BLK_CGROUP_IOCOST
bio->bi_iocost_cost = 0;
#endif
Expand Down Expand Up @@ -281,7 +276,7 @@ void bio_reset(struct bio *bio, struct block_device *bdev, blk_opf_t opf)
bio->bi_io_vec = bv;
bio->bi_bdev = bdev;
if (bio->bi_bdev)
bio_associate_blkg(bio);
bio_associate_blkcg(bio);
bio->bi_opf = opf;
}
EXPORT_SYMBOL(bio_reset);
Expand Down Expand Up @@ -865,7 +860,7 @@ static int __bio_clone(struct bio *bio, struct bio *bio_src, gfp_t gfp)
if (bio->bi_bdev == bio_src->bi_bdev &&
bio_flagged(bio_src, BIO_REMAPPED))
bio_set_flag(bio, BIO_REMAPPED);
bio_clone_blkg_association(bio, bio_src);
bio_clone_blkcg_association(bio, bio_src);
}

if (bio_crypt_clone(bio, bio_src, gfp) < 0)
Expand Down Expand Up @@ -1803,17 +1798,12 @@ void bio_endio(struct bio *bio)
goto again;
}

#ifdef CONFIG_BLK_CGROUP
/*
* Release cgroup info. We shouldn't have to do this here, but quite
* a few callers of bio_init fail to call bio_uninit, so we cover up
* for that here at least for now.
*/
if (bio->bi_blkg) {
blkg_put(bio->bi_blkg);
bio->bi_blkg = NULL;
}
#endif
bio_clear_blkcg(bio);

if (bio->bi_end_io)
bio->bi_end_io(bio);
Expand Down
10 changes: 8 additions & 2 deletions block/blk-cgroup-fc-appid.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,14 @@ EXPORT_SYMBOL_GPL(blkcg_set_fc_appid);
*/
char *blkcg_get_fc_appid(struct bio *bio)
{
if (!bio->bi_blkg || bio->bi_blkg->blkcg->fc_app_id[0] == '\0')
struct blkcg *blkcg = bio_blkcg(bio);

if (!blkcg)
return NULL;

if (blkcg->fc_app_id[0] == '\0')
return NULL;
return bio->bi_blkg->blkcg->fc_app_id;

return blkcg->fc_app_id;
}
EXPORT_SYMBOL_GPL(blkcg_get_fc_appid);
Loading