Skip to content

Commit db18a53

Browse files
Christoph Hellwigaxboe
authored andcommitted
blk-cgroup: remove blkcg_bio_issue_check
blkcg_bio_issue_check is a giant inline function that does three entirely different things. Factor out the blk-cgroup related bio initalization into a new helper, and the open code the sequence in the only caller, relying on the fact that all the actual functionality is stubbed out for non-cgroup builds. Acked-by: Tejun Heo <tj@kernel.org> Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 93b8063 commit db18a53

5 files changed

Lines changed: 47 additions & 57 deletions

File tree

‎block/blk-cgroup.c‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1813,6 +1813,40 @@ void bio_clone_blkg_association(struct bio *dst, struct bio *src)
18131813
}
18141814
EXPORT_SYMBOL_GPL(bio_clone_blkg_association);
18151815

1816+
static int blk_cgroup_io_type(struct bio *bio)
1817+
{
1818+
if (op_is_discard(bio->bi_opf))
1819+
return BLKG_IOSTAT_DISCARD;
1820+
if (op_is_write(bio->bi_opf))
1821+
return BLKG_IOSTAT_WRITE;
1822+
return BLKG_IOSTAT_READ;
1823+
}
1824+
1825+
void blk_cgroup_bio_start(struct bio *bio)
1826+
{
1827+
int rwd = blk_cgroup_io_type(bio), cpu;
1828+
struct blkg_iostat_set *bis;
1829+
1830+
cpu = get_cpu();
1831+
bis = per_cpu_ptr(bio->bi_blkg->iostat_cpu, cpu);
1832+
u64_stats_update_begin(&bis->sync);
1833+
1834+
/*
1835+
* If the bio is flagged with BIO_CGROUP_ACCT it means this is a split
1836+
* bio and we would have already accounted for the size of the bio.
1837+
*/
1838+
if (!bio_flagged(bio, BIO_CGROUP_ACCT)) {
1839+
bio_set_flag(bio, BIO_CGROUP_ACCT);
1840+
bis->cur.bytes[rwd] += bio->bi_iter.bi_size;
1841+
}
1842+
bis->cur.ios[rwd]++;
1843+
1844+
u64_stats_update_end(&bis->sync);
1845+
if (cgroup_subsys_on_dfl(io_cgrp_subsys))
1846+
cgroup_rstat_updated(bio->bi_blkg->blkcg->css.cgroup, cpu);
1847+
put_cpu();
1848+
}
1849+
18161850
static int __init blkcg_init(void)
18171851
{
18181852
blkcg_punt_bio_wq = alloc_workqueue("blkcg_punt_bio",

‎block/blk-core.c‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1073,8 +1073,13 @@ generic_make_request_checks(struct bio *bio)
10731073
if (unlikely(!current->io_context))
10741074
create_task_io_context(current, GFP_ATOMIC, q->node);
10751075

1076-
if (!blkcg_bio_issue_check(q, bio))
1076+
if (blk_throtl_bio(bio)) {
1077+
blkcg_bio_issue_init(bio);
10771078
return false;
1079+
}
1080+
1081+
blk_cgroup_bio_start(bio);
1082+
blkcg_bio_issue_init(bio);
10781083

10791084
if (!bio_flagged(bio, BIO_TRACE_COMPLETION)) {
10801085
trace_block_bio_queue(q, bio);

‎block/blk-throttle.c‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2158,9 +2158,10 @@ static inline void throtl_update_latency_buckets(struct throtl_data *td)
21582158
}
21592159
#endif
21602160

2161-
bool blk_throtl_bio(struct request_queue *q, struct blkcg_gq *blkg,
2162-
struct bio *bio)
2161+
bool blk_throtl_bio(struct bio *bio)
21632162
{
2163+
struct request_queue *q = bio->bi_disk->queue;
2164+
struct blkcg_gq *blkg = bio->bi_blkg;
21642165
struct throtl_qnode *qn = NULL;
21652166
struct throtl_grp *tg = blkg_to_tg(blkg ?: q->root_blkg);
21662167
struct throtl_service_queue *sq;

‎block/blk.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,10 +288,12 @@ int create_task_io_context(struct task_struct *task, gfp_t gfp_mask, int node);
288288
extern int blk_throtl_init(struct request_queue *q);
289289
extern void blk_throtl_exit(struct request_queue *q);
290290
extern void blk_throtl_register_queue(struct request_queue *q);
291+
bool blk_throtl_bio(struct bio *bio);
291292
#else /* CONFIG_BLK_DEV_THROTTLING */
292293
static inline int blk_throtl_init(struct request_queue *q) { return 0; }
293294
static inline void blk_throtl_exit(struct request_queue *q) { }
294295
static inline void blk_throtl_register_queue(struct request_queue *q) { }
296+
static inline bool blk_throtl_bio(struct bio *bio) { return false; }
295297
#endif /* CONFIG_BLK_DEV_THROTTLING */
296298
#ifdef CONFIG_BLK_DEV_THROTTLING_LOW
297299
extern ssize_t blk_throtl_sample_time_show(struct request_queue *q, char *page);

‎include/linux/blk-cgroup.h‎

Lines changed: 2 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -517,14 +517,6 @@ static inline void blkg_put(struct blkcg_gq *blkg)
517517
if (((d_blkg) = __blkg_lookup(css_to_blkcg(pos_css), \
518518
(p_blkg)->q, false)))
519519

520-
#ifdef CONFIG_BLK_DEV_THROTTLING
521-
extern bool blk_throtl_bio(struct request_queue *q, struct blkcg_gq *blkg,
522-
struct bio *bio);
523-
#else
524-
static inline bool blk_throtl_bio(struct request_queue *q, struct blkcg_gq *blkg,
525-
struct bio *bio) { return false; }
526-
#endif
527-
528520
bool __blkcg_punt_bio_submit(struct bio *bio);
529521

530522
static inline bool blkcg_punt_bio_submit(struct bio *bio)
@@ -540,50 +532,6 @@ static inline void blkcg_bio_issue_init(struct bio *bio)
540532
bio_issue_init(&bio->bi_issue, bio_sectors(bio));
541533
}
542534

543-
static inline bool blkcg_bio_issue_check(struct request_queue *q,
544-
struct bio *bio)
545-
{
546-
struct blkcg_gq *blkg = bio->bi_blkg;
547-
bool throtl = false;
548-
549-
throtl = blk_throtl_bio(q, blkg, bio);
550-
if (!throtl) {
551-
struct blkg_iostat_set *bis;
552-
int rwd, cpu;
553-
554-
if (op_is_discard(bio->bi_opf))
555-
rwd = BLKG_IOSTAT_DISCARD;
556-
else if (op_is_write(bio->bi_opf))
557-
rwd = BLKG_IOSTAT_WRITE;
558-
else
559-
rwd = BLKG_IOSTAT_READ;
560-
561-
cpu = get_cpu();
562-
bis = per_cpu_ptr(blkg->iostat_cpu, cpu);
563-
u64_stats_update_begin(&bis->sync);
564-
565-
/*
566-
* If the bio is flagged with BIO_CGROUP_ACCT it means this is a
567-
* split bio and we would have already accounted for the size of
568-
* the bio.
569-
*/
570-
if (!bio_flagged(bio, BIO_CGROUP_ACCT)) {
571-
bio_set_flag(bio, BIO_CGROUP_ACCT);
572-
bis->cur.bytes[rwd] += bio->bi_iter.bi_size;
573-
}
574-
bis->cur.ios[rwd]++;
575-
576-
u64_stats_update_end(&bis->sync);
577-
if (cgroup_subsys_on_dfl(io_cgrp_subsys))
578-
cgroup_rstat_updated(blkg->blkcg->css.cgroup, cpu);
579-
put_cpu();
580-
}
581-
582-
blkcg_bio_issue_init(bio);
583-
584-
return !throtl;
585-
}
586-
587535
static inline void blkcg_use_delay(struct blkcg_gq *blkg)
588536
{
589537
if (WARN_ON_ONCE(atomic_read(&blkg->use_delay) < 0))
@@ -657,6 +605,7 @@ static inline void blkcg_clear_delay(struct blkcg_gq *blkg)
657605
atomic_dec(&blkg->blkcg->css.cgroup->congestion_count);
658606
}
659607

608+
void blk_cgroup_bio_start(struct bio *bio);
660609
void blkcg_add_delay(struct blkcg_gq *blkg, u64 now, u64 delta);
661610
void blkcg_schedule_throttle(struct request_queue *q, bool use_memdelay);
662611
void blkcg_maybe_throttle_current(void);
@@ -710,8 +659,7 @@ static inline void blkg_put(struct blkcg_gq *blkg) { }
710659

711660
static inline bool blkcg_punt_bio_submit(struct bio *bio) { return false; }
712661
static inline void blkcg_bio_issue_init(struct bio *bio) { }
713-
static inline bool blkcg_bio_issue_check(struct request_queue *q,
714-
struct bio *bio) { return true; }
662+
static inline void blk_cgroup_bio_start(struct bio *bio) { }
715663

716664
#define blk_queue_for_each_rl(rl, q) \
717665
for ((rl) = &(q)->root_rl; (rl); (rl) = NULL)

0 commit comments

Comments
 (0)