Skip to content

Commit c839e7a

Browse files
dennisszhouaxboe
authored andcommitted
blkcg: remove bio->bi_css and instead use bio->bi_blkg
Prior patches ensured that all bios are now associated with some blkg. This now makes bio->bi_css unnecessary as blkg maintains a reference to the blkcg already. This patch removes the field bi_css and transfers corresponding uses to access via bi_blkg. Signed-off-by: Dennis Zhou <dennisszhou@gmail.com> Reviewed-by: Josef Bacik <josef@toxicpanda.com> Acked-by: Tejun Heo <tj@kernel.org> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent bdc2491 commit c839e7a

File tree

8 files changed

+25
-62
lines changed

8 files changed

+25
-62
lines changed

block/bio.c

Lines changed: 11 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,7 @@ void __bio_clone_fast(struct bio *bio, struct bio *bio_src)
609609
bio->bi_iter = bio_src->bi_iter;
610610
bio->bi_io_vec = bio_src->bi_io_vec;
611611

612-
bio_clone_blkcg_association(bio, bio_src);
612+
bio_clone_blkg_association(bio, bio_src);
613613

614614
blkcg_bio_issue_init(bio);
615615
}
@@ -1956,34 +1956,6 @@ EXPORT_SYMBOL(bioset_init_from_src);
19561956

19571957
#ifdef CONFIG_BLK_CGROUP
19581958

1959-
/**
1960-
* bio_associate_blkcg - associate a bio with the specified blkcg
1961-
* @bio: target bio
1962-
* @blkcg_css: css of the blkcg to associate
1963-
*
1964-
* Associate @bio with the blkcg specified by @blkcg_css. Block layer will
1965-
* treat @bio as if it were issued by a task which belongs to the blkcg.
1966-
*
1967-
* This function takes an extra reference of @blkcg_css which will be put
1968-
* when @bio is released. The caller must own @bio and is responsible for
1969-
* synchronizing calls to this function. If @blkcg_css is NULL, a call to
1970-
* blkcg_get_css finds the current css from the kthread or task.
1971-
*/
1972-
int bio_associate_blkcg(struct bio *bio, struct cgroup_subsys_state *blkcg_css)
1973-
{
1974-
if (unlikely(bio->bi_css))
1975-
return -EBUSY;
1976-
1977-
if (blkcg_css)
1978-
css_get(blkcg_css);
1979-
else
1980-
blkcg_css = blkcg_get_css();
1981-
1982-
bio->bi_css = blkcg_css;
1983-
return 0;
1984-
}
1985-
EXPORT_SYMBOL_GPL(bio_associate_blkcg);
1986-
19871959
/**
19881960
* bio_associate_blkg - associate a bio with the a blkg
19891961
* @bio: target bio
@@ -2033,7 +2005,6 @@ int bio_associate_blkg_from_css(struct bio *bio,
20332005
struct cgroup_subsys_state *css)
20342006
{
20352007
css_get(css);
2036-
bio->bi_css = css;
20372008
return __bio_associate_blkg_from_css(bio, css);
20382009
}
20392010
EXPORT_SYMBOL_GPL(bio_associate_blkg_from_css);
@@ -2054,12 +2025,11 @@ int bio_associate_blkg_from_page(struct bio *bio, struct page *page)
20542025
{
20552026
struct cgroup_subsys_state *css;
20562027

2057-
if (unlikely(bio->bi_css))
2028+
if (unlikely(bio->bi_blkg))
20582029
return -EBUSY;
20592030
if (!page->mem_cgroup)
20602031
return 0;
20612032
css = cgroup_get_e_css(page->mem_cgroup->css.cgroup, &io_cgrp_subsys);
2062-
bio->bi_css = css;
20632033

20642034
return __bio_associate_blkg_from_css(bio, css);
20652035
}
@@ -2085,8 +2055,7 @@ int bio_associate_create_blkg(struct request_queue *q, struct bio *bio)
20852055

20862056
rcu_read_lock();
20872057

2088-
bio_associate_blkcg(bio, NULL);
2089-
blkcg = bio_blkcg(bio);
2058+
blkcg = css_to_blkcg(blkcg_get_css());
20902059

20912060
if (!blkcg->css.parent) {
20922061
ret = bio_associate_blkg(bio, q->root_blkg);
@@ -2110,30 +2079,27 @@ void bio_disassociate_task(struct bio *bio)
21102079
put_io_context(bio->bi_ioc);
21112080
bio->bi_ioc = NULL;
21122081
}
2113-
if (bio->bi_css) {
2114-
css_put(bio->bi_css);
2115-
bio->bi_css = NULL;
2116-
}
21172082
if (bio->bi_blkg) {
2083+
/* a ref is always taken on css */
2084+
css_put(&bio_blkcg(bio)->css);
21182085
blkg_put(bio->bi_blkg);
21192086
bio->bi_blkg = NULL;
21202087
}
21212088
}
21222089

21232090
/**
2124-
* bio_clone_blkcg_association - clone blkcg association from src to dst bio
2091+
* bio_clone_blkg_association - clone blkg association from src to dst bio
21252092
* @dst: destination bio
21262093
* @src: source bio
21272094
*/
2128-
void bio_clone_blkcg_association(struct bio *dst, struct bio *src)
2095+
void bio_clone_blkg_association(struct bio *dst, struct bio *src)
21292096
{
2130-
if (src->bi_css)
2131-
WARN_ON(bio_associate_blkcg(dst, src->bi_css));
2132-
2133-
if (src->bi_blkg)
2097+
if (src->bi_blkg) {
2098+
css_get(&bio_blkcg(src)->css);
21342099
bio_associate_blkg(dst, src->bi_blkg);
2100+
}
21352101
}
2136-
EXPORT_SYMBOL_GPL(bio_clone_blkcg_association);
2102+
EXPORT_SYMBOL_GPL(bio_clone_blkg_association);
21372103
#endif /* CONFIG_BLK_CGROUP */
21382104

21392105
static void __init biovec_init_slabs(void)

block/bounce.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ static struct bio *bounce_clone_bio(struct bio *bio_src, gfp_t gfp_mask,
257257
}
258258
}
259259

260-
bio_clone_blkcg_association(bio, bio_src);
260+
bio_clone_blkg_association(bio, bio_src);
261261

262262
blkcg_bio_issue_init(bio);
263263

drivers/block/loop.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
#include <linux/falloc.h>
7878
#include <linux/uio.h>
7979
#include <linux/ioprio.h>
80+
#include <linux/blk-cgroup.h>
8081

8182
#include "loop.h"
8283

@@ -1760,8 +1761,8 @@ static blk_status_t loop_queue_rq(struct blk_mq_hw_ctx *hctx,
17601761

17611762
/* always use the first bio's css */
17621763
#ifdef CONFIG_BLK_CGROUP
1763-
if (cmd->use_aio && rq->bio && rq->bio->bi_css) {
1764-
cmd->css = rq->bio->bi_css;
1764+
if (cmd->use_aio && rq->bio && rq->bio->bi_blkg) {
1765+
cmd->css = &bio_blkcg(rq->bio)->css;
17651766
css_get(cmd->css);
17661767
} else
17671768
#endif

drivers/md/raid0.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,7 @@ static void raid0_handle_discard(struct mddev *mddev, struct bio *bio)
542542
!discard_bio)
543543
continue;
544544
bio_chain(discard_bio, bio);
545-
bio_clone_blkcg_association(discard_bio, bio);
545+
bio_clone_blkg_association(discard_bio, bio);
546546
if (mddev->gendisk)
547547
trace_block_bio_remap(bdev_get_queue(rdev->bdev),
548548
discard_bio, disk_devt(mddev->gendisk),

include/linux/bio.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -540,24 +540,21 @@ static inline int bio_associate_blkg_from_page(struct bio *bio,
540540
#endif
541541

542542
#ifdef CONFIG_BLK_CGROUP
543-
int bio_associate_blkcg(struct bio *bio, struct cgroup_subsys_state *blkcg_css);
544543
int bio_associate_blkg(struct bio *bio, struct blkcg_gq *blkg);
545544
int bio_associate_blkg_from_css(struct bio *bio,
546545
struct cgroup_subsys_state *css);
547546
int bio_associate_create_blkg(struct request_queue *q, struct bio *bio);
548547
void bio_disassociate_task(struct bio *bio);
549-
void bio_clone_blkcg_association(struct bio *dst, struct bio *src);
548+
void bio_clone_blkg_association(struct bio *dst, struct bio *src);
550549
#else /* CONFIG_BLK_CGROUP */
551-
static inline int bio_associate_blkcg(struct bio *bio,
552-
struct cgroup_subsys_state *blkcg_css) { return 0; }
553550
static inline int bio_associate_blkg_from_css(struct bio *bio,
554551
struct cgroup_subsys_state *css)
555552
{ return 0; }
556553
static inline int bio_associate_create_blkg(struct request_queue *q,
557554
struct bio *bio) { return 0; }
558555
static inline void bio_disassociate_task(struct bio *bio) { }
559-
static inline void bio_clone_blkcg_association(struct bio *dst,
560-
struct bio *src) { }
556+
static inline void bio_clone_blkg_association(struct bio *dst,
557+
struct bio *src) { }
561558
#endif /* CONFIG_BLK_CGROUP */
562559

563560
#ifdef CONFIG_HIGHMEM

include/linux/blk-cgroup.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -308,8 +308,8 @@ static inline struct blkcg *css_to_blkcg(struct cgroup_subsys_state *css)
308308
*/
309309
static inline struct blkcg *__bio_blkcg(struct bio *bio)
310310
{
311-
if (bio && bio->bi_css)
312-
return css_to_blkcg(bio->bi_css);
311+
if (bio && bio->bi_blkg)
312+
return bio->bi_blkg->blkcg;
313313
return css_to_blkcg(blkcg_css());
314314
}
315315

@@ -323,8 +323,8 @@ static inline struct blkcg *__bio_blkcg(struct bio *bio)
323323
*/
324324
static inline struct blkcg *bio_blkcg(struct bio *bio)
325325
{
326-
if (bio && bio->bi_css)
327-
return css_to_blkcg(bio->bi_css);
326+
if (bio && bio->bi_blkg)
327+
return bio->bi_blkg->blkcg;
328328
return NULL;
329329
}
330330

include/linux/blk_types.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,6 @@ struct bio {
178178
* release. Read comment on top of bio_associate_current().
179179
*/
180180
struct io_context *bi_ioc;
181-
struct cgroup_subsys_state *bi_css;
182181
struct blkcg_gq *bi_blkg;
183182
struct bio_issue bi_issue;
184183
#endif

kernel/trace/blktrace.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -764,9 +764,9 @@ blk_trace_bio_get_cgid(struct request_queue *q, struct bio *bio)
764764
if (!bt || !(blk_tracer_flags.val & TRACE_BLK_OPT_CGROUP))
765765
return NULL;
766766

767-
if (!bio->bi_css)
767+
if (!bio->bi_blkg)
768768
return NULL;
769-
return cgroup_get_kernfs_id(bio->bi_css->cgroup);
769+
return cgroup_get_kernfs_id(bio_blkcg(bio)->css.cgroup);
770770
}
771771
#else
772772
static union kernfs_node_id *

0 commit comments

Comments
 (0)