Skip to content

Commit 5cdf2e3

Browse files
dennisszhouaxboe
authored andcommitted
blkcg: associate blkg when associating a device
Previously, blkg association was handled by controller specific code in blk-throttle and blk-iolatency. However, because a blkg represents a relationship between a blkcg and a request_queue, it makes sense to keep the blkg->q and bio->bi_disk->queue consistent. This patch moves association into the bio_set_dev macro(). This should cover the majority of cases where the device is set/changed keeping the two pointers consistent. Fallback code is added to blkcg_bio_issue_check() to catch any missing paths. Signed-off-by: Dennis Zhou <dennis@kernel.org> Reviewed-by: Josef Bacik <josef@toxicpanda.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 892ad71 commit 5cdf2e3

File tree

5 files changed

+14
-12
lines changed

5 files changed

+14
-12
lines changed

block/bio.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2074,6 +2074,7 @@ void bio_associate_blkg(struct bio *bio)
20742074

20752075
rcu_read_unlock();
20762076
}
2077+
EXPORT_SYMBOL_GPL(bio_associate_blkg);
20772078

20782079
/**
20792080
* bio_disassociate_task - undo bio_associate_current()

block/blk-iolatency.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -472,14 +472,12 @@ static void check_scale_change(struct iolatency_grp *iolat)
472472
static void blkcg_iolatency_throttle(struct rq_qos *rqos, struct bio *bio)
473473
{
474474
struct blk_iolatency *blkiolat = BLKIOLATENCY(rqos);
475-
struct blkcg_gq *blkg;
475+
struct blkcg_gq *blkg = bio->bi_blkg;
476476
bool issue_as_root = bio_issue_as_root_blkg(bio);
477477

478478
if (!blk_iolatency_enabled(blkiolat))
479479
return;
480480

481-
bio_associate_blkg(bio);
482-
blkg = bio->bi_blkg;
483481
bio_issue_init(&bio->bi_issue, bio_sectors(bio));
484482

485483
while (blkg && blkg->parent) {

block/blk-throttle.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2118,7 +2118,6 @@ static inline void throtl_update_latency_buckets(struct throtl_data *td)
21182118
static void blk_throtl_assoc_bio(struct bio *bio)
21192119
{
21202120
#ifdef CONFIG_BLK_DEV_THROTTLING_LOW
2121-
bio_associate_blkg(bio);
21222121
bio_issue_init(&bio->bi_issue, bio_sectors(bio));
21232122
#endif
21242123
}

include/linux/bio.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,12 +491,14 @@ do { \
491491
bio_clear_flag(bio, BIO_THROTTLED);\
492492
(bio)->bi_disk = (bdev)->bd_disk; \
493493
(bio)->bi_partno = (bdev)->bd_partno; \
494+
bio_associate_blkg(bio); \
494495
} while (0)
495496

496497
#define bio_copy_dev(dst, src) \
497498
do { \
498499
(dst)->bi_disk = (src)->bi_disk; \
499500
(dst)->bi_partno = (src)->bi_partno; \
501+
bio_clone_blkcg_association(dst, src); \
500502
} while (0)
501503

502504
#define bio_dev(bio) \

include/linux/blk-cgroup.h

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <linux/blkdev.h>
2222
#include <linux/atomic.h>
2323
#include <linux/kthread.h>
24+
#include <linux/fs.h>
2425

2526
/* percpu_counter batch for blkg_[rw]stats, per-cpu drift doesn't matter */
2627
#define BLKG_STAT_CPU_BATCH (INT_MAX / 2)
@@ -802,21 +803,23 @@ static inline bool blk_throtl_bio(struct request_queue *q, struct blkcg_gq *blkg
802803
static inline bool blkcg_bio_issue_check(struct request_queue *q,
803804
struct bio *bio)
804805
{
805-
struct blkcg *blkcg;
806806
struct blkcg_gq *blkg;
807807
bool throtl = false;
808808

809-
rcu_read_lock();
809+
if (!bio->bi_blkg) {
810+
char b[BDEVNAME_SIZE];
811+
812+
WARN_ONCE(1,
813+
"no blkg associated for bio on block-device: %s\n",
814+
bio_devname(bio, b));
815+
bio_associate_blkg(bio);
816+
}
810817

811-
/* associate blkcg if bio hasn't attached one */
812-
bio_associate_blkcg(bio, NULL);
813-
blkcg = bio_blkcg(bio);
814-
blkg = blkg_lookup_create(blkcg, q);
818+
blkg = bio->bi_blkg;
815819

816820
throtl = blk_throtl_bio(q, blkg, bio);
817821

818822
if (!throtl) {
819-
blkg = blkg ?: q->root_blkg;
820823
/*
821824
* If the bio is flagged with BIO_QUEUE_ENTERED it means this
822825
* is a split bio and we would have already accounted for the
@@ -828,7 +831,6 @@ static inline bool blkcg_bio_issue_check(struct request_queue *q,
828831
blkg_rwstat_add(&blkg->stat_ios, bio->bi_opf, 1);
829832
}
830833

831-
rcu_read_unlock();
832834
return !throtl;
833835
}
834836

0 commit comments

Comments
 (0)