]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/commitdiff
blkcg: remove bio->bi_css and instead use bio->bi_blkg
authorDennis Zhou (Facebook) <dennisszhou@gmail.com>
Tue, 11 Sep 2018 18:41:33 +0000 (14:41 -0400)
committerJens Axboe <axboe@kernel.dk>
Sat, 22 Sep 2018 02:29:13 +0000 (20:29 -0600)
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>
block/bio.c
block/bounce.c
drivers/block/loop.c
drivers/md/raid0.c
include/linux/bio.h
include/linux/blk-cgroup.h
include/linux/blk_types.h
kernel/trace/blktrace.c

index 387480de699285ee484b5e8cdac5e4dcc77b1775..71cfe3720ea73ec248fdd1759a740f6438085b76 100644 (file)
@@ -609,7 +609,7 @@ void __bio_clone_fast(struct bio *bio, struct bio *bio_src)
        bio->bi_iter = bio_src->bi_iter;
        bio->bi_io_vec = bio_src->bi_io_vec;
 
-       bio_clone_blkcg_association(bio, bio_src);
+       bio_clone_blkg_association(bio, bio_src);
 
        blkcg_bio_issue_init(bio);
 }
@@ -1956,34 +1956,6 @@ EXPORT_SYMBOL(bioset_init_from_src);
 
 #ifdef CONFIG_BLK_CGROUP
 
-/**
- * bio_associate_blkcg - associate a bio with the specified blkcg
- * @bio: target bio
- * @blkcg_css: css of the blkcg to associate
- *
- * Associate @bio with the blkcg specified by @blkcg_css.  Block layer will
- * treat @bio as if it were issued by a task which belongs to the blkcg.
- *
- * This function takes an extra reference of @blkcg_css which will be put
- * when @bio is released.  The caller must own @bio and is responsible for
- * synchronizing calls to this function.  If @blkcg_css is NULL, a call to
- * blkcg_get_css finds the current css from the kthread or task.
- */
-int bio_associate_blkcg(struct bio *bio, struct cgroup_subsys_state *blkcg_css)
-{
-       if (unlikely(bio->bi_css))
-               return -EBUSY;
-
-       if (blkcg_css)
-               css_get(blkcg_css);
-       else
-               blkcg_css = blkcg_get_css();
-
-       bio->bi_css = blkcg_css;
-       return 0;
-}
-EXPORT_SYMBOL_GPL(bio_associate_blkcg);
-
 /**
  * bio_associate_blkg - associate a bio with the a blkg
  * @bio: target bio
@@ -2033,7 +2005,6 @@ int bio_associate_blkg_from_css(struct bio *bio,
                                struct cgroup_subsys_state *css)
 {
        css_get(css);
-       bio->bi_css = css;
        return __bio_associate_blkg_from_css(bio, css);
 }
 EXPORT_SYMBOL_GPL(bio_associate_blkg_from_css);
@@ -2054,12 +2025,11 @@ int bio_associate_blkg_from_page(struct bio *bio, struct page *page)
 {
        struct cgroup_subsys_state *css;
 
-       if (unlikely(bio->bi_css))
+       if (unlikely(bio->bi_blkg))
                return -EBUSY;
        if (!page->mem_cgroup)
                return 0;
        css = cgroup_get_e_css(page->mem_cgroup->css.cgroup, &io_cgrp_subsys);
-       bio->bi_css = css;
 
        return __bio_associate_blkg_from_css(bio, css);
 }
@@ -2085,8 +2055,7 @@ int bio_associate_create_blkg(struct request_queue *q, struct bio *bio)
 
        rcu_read_lock();
 
-       bio_associate_blkcg(bio, NULL);
-       blkcg = bio_blkcg(bio);
+       blkcg = css_to_blkcg(blkcg_get_css());
 
        if (!blkcg->css.parent) {
                ret = bio_associate_blkg(bio, q->root_blkg);
@@ -2110,30 +2079,27 @@ void bio_disassociate_task(struct bio *bio)
                put_io_context(bio->bi_ioc);
                bio->bi_ioc = NULL;
        }
-       if (bio->bi_css) {
-               css_put(bio->bi_css);
-               bio->bi_css = NULL;
-       }
        if (bio->bi_blkg) {
+               /* a ref is always taken on css */
+               css_put(&bio_blkcg(bio)->css);
                blkg_put(bio->bi_blkg);
                bio->bi_blkg = NULL;
        }
 }
 
 /**
- * bio_clone_blkcg_association - clone blkcg association from src to dst bio
+ * bio_clone_blkg_association - clone blkg association from src to dst bio
  * @dst: destination bio
  * @src: source bio
  */
-void bio_clone_blkcg_association(struct bio *dst, struct bio *src)
+void bio_clone_blkg_association(struct bio *dst, struct bio *src)
 {
-       if (src->bi_css)
-               WARN_ON(bio_associate_blkcg(dst, src->bi_css));
-
-       if (src->bi_blkg)
+       if (src->bi_blkg) {
+               css_get(&bio_blkcg(src)->css);
                bio_associate_blkg(dst, src->bi_blkg);
+       }
 }
-EXPORT_SYMBOL_GPL(bio_clone_blkcg_association);
+EXPORT_SYMBOL_GPL(bio_clone_blkg_association);
 #endif /* CONFIG_BLK_CGROUP */
 
 static void __init biovec_init_slabs(void)
index 7a08703b12045686e397a88f8f40ddb1eb4b8f52..b30071ac4ec60e1110ba50303c94c18a77b73c70 100644 (file)
@@ -257,7 +257,7 @@ static struct bio *bounce_clone_bio(struct bio *bio_src, gfp_t gfp_mask,
                }
        }
 
-       bio_clone_blkcg_association(bio, bio_src);
+       bio_clone_blkg_association(bio, bio_src);
 
        blkcg_bio_issue_init(bio);
 
index ea9debf59b225c19d815e7ff1fd8aa950f5dcb1b..abad6d15f956343ff86ad45d0f40ff4c7faae50b 100644 (file)
@@ -77,6 +77,7 @@
 #include <linux/falloc.h>
 #include <linux/uio.h>
 #include <linux/ioprio.h>
+#include <linux/blk-cgroup.h>
 
 #include "loop.h"
 
@@ -1760,8 +1761,8 @@ static blk_status_t loop_queue_rq(struct blk_mq_hw_ctx *hctx,
 
        /* always use the first bio's css */
 #ifdef CONFIG_BLK_CGROUP
-       if (cmd->use_aio && rq->bio && rq->bio->bi_css) {
-               cmd->css = rq->bio->bi_css;
+       if (cmd->use_aio && rq->bio && rq->bio->bi_blkg) {
+               cmd->css = &bio_blkcg(rq->bio)->css;
                css_get(cmd->css);
        } else
 #endif
index ac1cffd2a09b05f5f5217e579c9e87ea80efce84..f3fb5bb8c82a1cfe861aef1af22b581709815817 100644 (file)
@@ -542,7 +542,7 @@ static void raid0_handle_discard(struct mddev *mddev, struct bio *bio)
                    !discard_bio)
                        continue;
                bio_chain(discard_bio, bio);
-               bio_clone_blkcg_association(discard_bio, bio);
+               bio_clone_blkg_association(discard_bio, bio);
                if (mddev->gendisk)
                        trace_block_bio_remap(bdev_get_queue(rdev->bdev),
                                discard_bio, disk_devt(mddev->gendisk),
index c73a870ebc0e5fc181827eee8cdb33ecd3c8f00b..e973876625a82684e30a4f290107550b677d9d9d 100644 (file)
@@ -540,24 +540,21 @@ static inline int bio_associate_blkg_from_page(struct bio *bio,
 #endif
 
 #ifdef CONFIG_BLK_CGROUP
-int bio_associate_blkcg(struct bio *bio, struct cgroup_subsys_state *blkcg_css);
 int bio_associate_blkg(struct bio *bio, struct blkcg_gq *blkg);
 int bio_associate_blkg_from_css(struct bio *bio,
                                struct cgroup_subsys_state *css);
 int bio_associate_create_blkg(struct request_queue *q, struct bio *bio);
 void bio_disassociate_task(struct bio *bio);
-void bio_clone_blkcg_association(struct bio *dst, struct bio *src);
+void bio_clone_blkg_association(struct bio *dst, struct bio *src);
 #else  /* CONFIG_BLK_CGROUP */
-static inline int bio_associate_blkcg(struct bio *bio,
-                       struct cgroup_subsys_state *blkcg_css) { return 0; }
 static inline int bio_associate_blkg_from_css(struct bio *bio,
                                              struct cgroup_subsys_state *css)
 { return 0; }
 static inline int bio_associate_create_blkg(struct request_queue *q,
                                            struct bio *bio) { return 0; }
 static inline void bio_disassociate_task(struct bio *bio) { }
-static inline void bio_clone_blkcg_association(struct bio *dst,
-                       struct bio *src) { }
+static inline void bio_clone_blkg_association(struct bio *dst,
+                                             struct bio *src) { }
 #endif /* CONFIG_BLK_CGROUP */
 
 #ifdef CONFIG_HIGHMEM
index a6b6e741a75ecc1a710da87098ee4062cbd2277e..c41cfcc2b4d886c880a5ed0041b9d3e835110c4b 100644 (file)
@@ -308,8 +308,8 @@ static inline struct blkcg *css_to_blkcg(struct cgroup_subsys_state *css)
  */
 static inline struct blkcg *__bio_blkcg(struct bio *bio)
 {
-       if (bio && bio->bi_css)
-               return css_to_blkcg(bio->bi_css);
+       if (bio && bio->bi_blkg)
+               return bio->bi_blkg->blkcg;
        return css_to_blkcg(blkcg_css());
 }
 
@@ -323,8 +323,8 @@ static inline struct blkcg *__bio_blkcg(struct bio *bio)
  */
 static inline struct blkcg *bio_blkcg(struct bio *bio)
 {
-       if (bio && bio->bi_css)
-               return css_to_blkcg(bio->bi_css);
+       if (bio && bio->bi_blkg)
+               return bio->bi_blkg->blkcg;
        return NULL;
 }
 
index f6dfb30737d8d32d95479c1d95d37246b4cba4d7..9578c7ab1eb6d4ed6a8e8fcb31452f90692a5afa 100644 (file)
@@ -178,7 +178,6 @@ struct bio {
         * release.  Read comment on top of bio_associate_current().
         */
        struct io_context       *bi_ioc;
-       struct cgroup_subsys_state *bi_css;
        struct blkcg_gq         *bi_blkg;
        struct bio_issue        bi_issue;
 #endif
index 2868d85f1fb1d3286984c4727f0519957ac069a9..fac0ddf8a8e22505749be3064e6b964ba12d4930 100644 (file)
@@ -764,9 +764,9 @@ blk_trace_bio_get_cgid(struct request_queue *q, struct bio *bio)
        if (!bt || !(blk_tracer_flags.val & TRACE_BLK_OPT_CGROUP))
                return NULL;
 
-       if (!bio->bi_css)
+       if (!bio->bi_blkg)
                return NULL;
-       return cgroup_get_kernfs_id(bio->bi_css->cgroup);
+       return cgroup_get_kernfs_id(bio_blkcg(bio)->css.cgroup);
 }
 #else
 static union kernfs_node_id *