Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp1054913imm; Thu, 6 Sep 2018 14:39:51 -0700 (PDT) X-Google-Smtp-Source: ANB0VdbtZe2HYplDGeqDutoTgvQgU+OJr6fGG1TBrtM9caNCfpAgPUQyrW2GOwwv4hkCRZX0lt8d X-Received: by 2002:a63:a012:: with SMTP id r18-v6mr5038735pge.166.1536269991346; Thu, 06 Sep 2018 14:39:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536269991; cv=none; d=google.com; s=arc-20160816; b=XGJaUuKoKgQqTvX5zNeIKe5tvZc1sDvL/R9efKoGGjj80Cdox9Ferd78Zf2lrX7GXn /LA7Y9TGHk6sQMin6fMICk4BZhqfOwR02dPPX5z+DAPB1AUOFvOY3nya4t9q8f4/8olm H8CM3oR5lXF0KTfTQByEcxsJYn1h6qcdEqlWcyxr49OcV39BOc2JfSWEh4McE/7++xdC ViIAgI9YOYGKl48WdIHnU2fVcH8hxkCocHdy2ZZv6fMVmuDVMZUoGsMxYH7GUbOqHRiL ECdCnD7X/5xAYtDwTLwRvYhxqVMG7bqcYmbZbuJA5ry0tOrnkwGWjfwf2lIM5a3g8lib mTgA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=XPPoAdksJyW7etirRJyXBBMe8ViznfgHXg9Jq/j5I+E=; b=n/3Xaqw8O1mcrtjhWXGxq1O2LF4PIL6ii6CqIknzdcg8ZBjEoLZaoHi6fpXcjCriBZ eW7JgJW4rGbvZADILwsSZH5ljkcNYbp9R1GXuWk/YYfAlVQ5F5uXKdpVqQKIOjACKLq9 hfxaQp1ftJ9U5MwoNIcgci51RNJF3JwaTh9NirSnEFcG6GSvuNbbyaSmQbt6dtmcT+Iz VQqDH2x7b4TkJNyRuq1kR9Y8sV1Ot2dwqsBZ4G03BRf/smMIDgu77pI5sepfXUtmc1k9 XunJ9jMFXSC4fdBihR4OO7z0h0Wjy9aznplDEx0bisgHf+ikRH6nRHwSXnCyO+toWMTQ Os8Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=IaAimLr0; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g3-v6si6578001pgu.248.2018.09.06.14.39.35; Thu, 06 Sep 2018 14:39:51 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=IaAimLr0; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729370AbeIGBs1 (ORCPT + 99 others); Thu, 6 Sep 2018 21:48:27 -0400 Received: from mail-yb1-f194.google.com ([209.85.219.194]:43529 "EHLO mail-yb1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728640AbeIGBsZ (ORCPT ); Thu, 6 Sep 2018 21:48:25 -0400 Received: by mail-yb1-f194.google.com with SMTP id k5-v6so4682900ybo.10; Thu, 06 Sep 2018 14:11:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=XPPoAdksJyW7etirRJyXBBMe8ViznfgHXg9Jq/j5I+E=; b=IaAimLr0bP4/hLKrptvrlwHMhmUdSPQdDL2zHAs1PhGcZN09yY3k5rGdLHhhKekxkd MbOqhNuwaTQNogwG79vPeaurcALvgRnUO/zk7kiXCPoJFrFSvWU2PQjK/PmhuqZm5FVA AaFZhwt11enZKuWOyVgJ7c9dL46qD2d9wwal7VHbEZNUOst2Oy7MkGxneNh2EbAIbsx6 vbTM8GDC9nN+UkcwzzSfrhvaHxjNJpiunUpm0P2ENFOmZ1aGov0GUcIviEoimCb/1EPR /hh4xG+pvk7PSAxzkG52Ul0dTjY0q1jrKic4aCrHMnFqldQ8tbsgKoOzhu5gW3mCBHvo lyMQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=XPPoAdksJyW7etirRJyXBBMe8ViznfgHXg9Jq/j5I+E=; b=NRMznzH+OG2oR2z9bfVtBwLHvXR0OenaVsMKRo4PtyswP5y1JH72dJ6fZ4kCWo4wES Na3uQcML+PQXqUhVE/zvsoU5IMtGCVdgXRMNZ9p70ke4bbqHZllRCRbkp6DMdtCkNFBB oKUPQ0GwTFZVlPLayK+G3cjenQrUvidUod5Qb4HHOVVG0HOygF9LW+hr5yuyIufegAmi zkUHYJzsbw7ZrSc89Dp10qVkSb9LDy4caowNbZFrvXoMvfDoN2TJsXLxhcAP/LPcMqUk 9Q11ZyDZfTDaHW4EYTZZ7VOyJ+v0LbB3hxoVs/a/VC9ciaYqlSpRzv8YMS8gdchZDJeJ z0Kg== X-Gm-Message-State: APzg51DbjTWC8B0LMptQ0WQJrqgdMETMk1IGu3xInUh1XsXw2ngFXB1w 3qRpSs+YnIGnq6/5H1+R2+E= X-Received: by 2002:a25:8052:: with SMTP id a18-v6mr2649857ybn.25.1536268266868; Thu, 06 Sep 2018 14:11:06 -0700 (PDT) Received: from dennisz-mbp.thefacebook.com ([199.201.65.129]) by smtp.gmail.com with ESMTPSA id u67-v6sm2032802ywa.56.2018.09.06.14.11.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 06 Sep 2018 14:11:06 -0700 (PDT) From: Dennis Zhou To: Jens Axboe , Tejun Heo , Johannes Weiner , Josef Bacik Cc: kernel-team@fb.com, linux-block@vger.kernel.org, cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, "Dennis Zhou (Facebook)" Subject: [PATCH 08/12] blkcg: remove bio->bi_css and instead use bio->bi_blkg Date: Thu, 6 Sep 2018 17:10:41 -0400 Message-Id: <20180906211045.29055-9-dennisszhou@gmail.com> X-Mailer: git-send-email 2.13.5 In-Reply-To: <20180906211045.29055-1-dennisszhou@gmail.com> References: <20180906211045.29055-1-dennisszhou@gmail.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: "Dennis Zhou (Facebook)" 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 Reviewed-by: Josef Bacik Acked-by: Tejun Heo --- block/bio.c | 56 ++++++++------------------------------ block/bounce.c | 2 +- drivers/block/loop.c | 5 ++-- drivers/md/raid0.c | 2 +- include/linux/bio.h | 9 ++---- include/linux/blk-cgroup.h | 8 +++--- include/linux/blk_types.h | 1 - kernel/trace/blktrace.c | 4 +-- 8 files changed, 25 insertions(+), 62 deletions(-) diff --git a/block/bio.c b/block/bio.c index 6c69c35db8c7..eb744991d2b1 100644 --- a/block/bio.c +++ b/block/bio.c @@ -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); } @@ -1958,34 +1958,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 specified blkg * @bio: target bio @@ -2030,7 +2002,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); @@ -2051,12 +2022,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); } @@ -2082,8 +2052,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); @@ -2107,30 +2076,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) diff --git a/block/bounce.c b/block/bounce.c index 7a08703b1204..b30071ac4ec6 100644 --- a/block/bounce.c +++ b/block/bounce.c @@ -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); diff --git a/drivers/block/loop.c b/drivers/block/loop.c index ea9debf59b22..abad6d15f956 100644 --- a/drivers/block/loop.c +++ b/drivers/block/loop.c @@ -77,6 +77,7 @@ #include #include #include +#include #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 diff --git a/drivers/md/raid0.c b/drivers/md/raid0.c index ac1cffd2a09b..f3fb5bb8c82a 100644 --- a/drivers/md/raid0.c +++ b/drivers/md/raid0.c @@ -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), diff --git a/include/linux/bio.h b/include/linux/bio.h index bd8e67c01aa1..8cb818af09f7 100644 --- a/include/linux/bio.h +++ b/include/linux/bio.h @@ -554,24 +554,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 diff --git a/include/linux/blk-cgroup.h b/include/linux/blk-cgroup.h index a6b6e741a75e..c41cfcc2b4d8 100644 --- a/include/linux/blk-cgroup.h +++ b/include/linux/blk-cgroup.h @@ -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; } diff --git a/include/linux/blk_types.h b/include/linux/blk_types.h index f6dfb30737d8..9578c7ab1eb6 100644 --- a/include/linux/blk_types.h +++ b/include/linux/blk_types.h @@ -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 diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c index 2868d85f1fb1..fac0ddf8a8e2 100644 --- a/kernel/trace/blktrace.c +++ b/kernel/trace/blktrace.c @@ -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 * -- 2.17.1