Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp152470imm; Thu, 30 Aug 2018 18:56:55 -0700 (PDT) X-Google-Smtp-Source: ANB0VdY+3gRjhU9IHh5paKiqzQALxmOZjndHRlpcOMZx4ivgYE+ui5Hk6SR/c0836Up4rQ+LqNrc X-Received: by 2002:a63:3e8b:: with SMTP id l133-v6mr11997865pga.355.1535680615911; Thu, 30 Aug 2018 18:56:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535680615; cv=none; d=google.com; s=arc-20160816; b=T7ZRpu9Yw9p7tK5lGuGo/j6IW88sMuCOaTWNLD9QufIRCqhx1kcANXtJ5gy9IZbhPL rbBMwBwwIlkCs8FVCcC/9Qk7BVbrzgXXHFTdh8DFE1GiRDi9J7ZZCgCTv2e0/sNIpXCI u3Yk060O6WDt4kuCqIBAp66vU/IzNXtcj2J/du7vKRgdI0CBDMTBI7yaKCKc3G8NtkdW HuHadTj/9H5EQ4xygn2IUQYgsfG05/MzzI3YDW0/jMl5E9zA/B6lpEzMpl9lE/RyxRAm V6rIfFVX6bUJYDKNnXl0C9F/KNSq0Kh2+flwWk+EYaQkDdaggMkrghWN5CjgNsCeYiqm HTOA== 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:arc-authentication-results; bh=Mj25J0UoslyA5YmwNy0OqZFtdVfhQZOp37ROGcHR3Fc=; b=s10e/JO7t6QEpeO+6UEdrozKoaneSQxpjQlf9fQCX1UPcVMCx4Ou9TX+3i3xdxfgxD +xgLa9P4H9wxM/HA10vHSeUI0AccEQ61j5SPbaFtDgNyV/yKMN/hrLrK5XAQ/jFo7uwN gwnltm+5hOJUhNh9Z4z5aUgNE6Ore8pSDiUds4nRLhSGcDfaIRcqIzTgTi8ptGKRSNqw JHR3+/jI6SmNBdUaS9xBKssKqJb/iiKJDtCVg6xmRbLGgSTpqmwUo3VNBAOYviGTtiUE nz+6NWYtZuhYKbLljWVBY6j1K0yiS2U3TE+f1qdb/NRJryFwB/wHiYeHx550mWD66NoX g8Ww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=QEXfyhc5; 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 s1-v6si8552663pfi.369.2018.08.30.18.56.41; Thu, 30 Aug 2018 18:56:55 -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=QEXfyhc5; 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 S1727575AbeHaF7Y (ORCPT + 99 others); Fri, 31 Aug 2018 01:59:24 -0400 Received: from mail-yb1-f175.google.com ([209.85.219.175]:41043 "EHLO mail-yb1-f175.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726727AbeHaF7X (ORCPT ); Fri, 31 Aug 2018 01:59:23 -0400 Received: by mail-yb1-f175.google.com with SMTP id q18-v6so330267ybg.8; Thu, 30 Aug 2018 18:54:21 -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=Mj25J0UoslyA5YmwNy0OqZFtdVfhQZOp37ROGcHR3Fc=; b=QEXfyhc5/2+9jk5xLBPys7D34HzM2ObH4YFt7r0EnTI0aeKtvb9LXYDRQF1lpMBMak zbi8UQMIqu4nbcPSomeVaG7vwWOJN3aT9xnL5gacaY0t6uRfuQTnR7zJAyXYSP/x4Jxi SkL9XTyOlWBeFFL1BYuikzyoZJPRCzRGwFvAc8wBFA3Zl80lMibBkqaM9AP7lQhddUwV LKzURAPrN2AXwiBjecsqqYILKRG22PoFln2HIRIhhhZKdIhwk4rNQGdnM6waZ7oa8rXE QOLelyydMejuQSOHBb4xqMC+QF8tW35E1IOcP80Ul21wmuDjap1pcLc95zEwAWRWUYtN bNvQ== 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=Mj25J0UoslyA5YmwNy0OqZFtdVfhQZOp37ROGcHR3Fc=; b=AB+MMcZR8+o1EtyLLwbggpqrf2ATyxiaNsoH7vDtP4Ex/GITN35jbqXHcbDZXpiLyI N9mQ0irgSvEkADijPviovxrehKf986gIFZXntyS1vtBNejXxHKkvaDuns4j9NTkZlJdo TqYSuIh+mCfoTdmWDgcs/h1SHKdh7OUt/Zz4fFe5kcHo7mJNLW4HTkVYad0FE0fQFbo/ g0jo4GpvyectP09i41SB1vLoG05pfmqg1j4e6YQMId3Gp3g5/9D3kXSTBa8ED0GlGO4w StHyjRzRdHTEDEOHc7HbheThauD6Cs0KWo5b+TmCM+SSQYz1XfusSBCLH/mieLD/dHMw JnXA== X-Gm-Message-State: APzg51B371J4UaF3u8TbWtvHjHZaUIvQkvS1n8Be1xCC87t7IOCT0JpN wulYrR961pJ02kSqiqv6KTY= X-Received: by 2002:a25:7904:: with SMTP id u4-v6mr7634178ybc.365.1535680460964; Thu, 30 Aug 2018 18:54:20 -0700 (PDT) Received: from dennisz-mbp.thefacebook.com ([199.201.65.129]) by smtp.gmail.com with ESMTPSA id j70-v6sm3274084ywb.69.2018.08.30.18.54.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 30 Aug 2018 18:54:20 -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 06/15] blkcg: always associate a bio with a blkg Date: Thu, 30 Aug 2018 21:53:47 -0400 Message-Id: <20180831015356.69796-7-dennisszhou@gmail.com> X-Mailer: git-send-email 2.13.5 In-Reply-To: <20180831015356.69796-1-dennisszhou@gmail.com> References: <20180831015356.69796-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)" Previously, blkg's were only assigned as needed by blk-iolatency and blk-throttle. bio->css was also always being associated while blkg was being looked up and then thrown away in blkcg_bio_issue_check. This patch beings the cleanup of bio->css and bio->bi_blkg by always associating a blkg in blkcg_bio_issue_check. This tries to create the blkg, but if it is not possible, falls back to using the root_blkg of the request_queue. Therefore, a bio will always be associated with a blkg. A missing definition for bio_associate_blkg is also added for parity in bio.h. Signed-off-by: Dennis Zhou --- block/bio.c | 41 ++++++++++++++++++++++++++++++++++++++ include/linux/bio.h | 5 +++++ include/linux/blk-cgroup.h | 19 ++---------------- 3 files changed, 48 insertions(+), 17 deletions(-) diff --git a/block/bio.c b/block/bio.c index 09a31e4d46bb..e937f9681188 100644 --- a/block/bio.c +++ b/block/bio.c @@ -1999,6 +1999,44 @@ int bio_associate_blkg(struct bio *bio, struct blkcg_gq *blkg) return 0; } +/** + * bio_associate_create_blkg - associate a bio with a blkg from q + * @q: request_queue where bio is going + * @bio: target bio + * + * Associate @bio with the blkg found from the bio's css and the request_queue. + * If one is not found, bio_lookup_blkg creates the blkg. + */ +int bio_associate_create_blkg(struct request_queue *q, struct bio *bio) +{ + struct blkcg *blkcg; + struct blkcg_gq *blkg; + int ret = 0; + + /* someone has already associated this bio with a blkg */ + if (bio->bi_blkg) + return ret; + + rcu_read_lock(); + + bio_associate_blkcg(bio, NULL); + blkcg = bio_blkcg(bio); + + if (!blkcg->css.parent) { + ret = bio_associate_blkg(bio, q->root_blkg); + goto assoc_out; + } + + blkg = blkg_lookup_create(blkcg, q); + if (IS_ERR(blkg)) + blkg = q->root_blkg; + + ret = bio_associate_blkg(bio, blkg); +assoc_out: + rcu_read_unlock(); + return ret; +} + /** * bio_disassociate_task - undo bio_associate_current() * @bio: target bio @@ -2028,6 +2066,9 @@ void bio_clone_blkcg_association(struct bio *dst, struct bio *src) { if (src->bi_css) WARN_ON(bio_associate_blkcg(dst, src->bi_css)); + + if (src->bi_blkg) + bio_associate_blkg(dst, src->bi_blkg); } EXPORT_SYMBOL_GPL(bio_clone_blkcg_association); #endif /* CONFIG_BLK_CGROUP */ diff --git a/include/linux/bio.h b/include/linux/bio.h index 51371740d2a8..d4626108b9d7 100644 --- a/include/linux/bio.h +++ b/include/linux/bio.h @@ -556,11 +556,16 @@ static inline int bio_associate_blkcg_from_page(struct bio *bio, #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_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); #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(struct bio *bio, + struct blkcg_gq *blkg) { 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) { } diff --git a/include/linux/blk-cgroup.h b/include/linux/blk-cgroup.h index ea2dd6e6baf2..9931ec2f4e9e 100644 --- a/include/linux/blk-cgroup.h +++ b/include/linux/blk-cgroup.h @@ -824,29 +824,15 @@ static inline bool blk_throtl_bio(struct request_queue *q, struct blkcg_gq *blkg static inline bool blkcg_bio_issue_check(struct request_queue *q, struct bio *bio) { - struct blkcg *blkcg; struct blkcg_gq *blkg; bool throtl = false; - rcu_read_lock(); - - /* associate blkcg if bio hasn't attached one */ - bio_associate_blkcg(bio, NULL); - blkcg = bio_blkcg(bio); - - blkg = blkg_lookup(blkcg, q); - if (unlikely(!blkg)) { - spin_lock_irq(q->queue_lock); - blkg = __blkg_lookup_create(blkcg, q); - if (IS_ERR(blkg)) - blkg = NULL; - spin_unlock_irq(q->queue_lock); - } + bio_associate_create_blkg(q, bio); + blkg = bio->bi_blkg; throtl = blk_throtl_bio(q, blkg, bio); if (!throtl) { - blkg = blkg ?: q->root_blkg; /* * If the bio is flagged with BIO_QUEUE_ENTERED it means this * is a split bio and we would have already accounted for the @@ -858,7 +844,6 @@ static inline bool blkcg_bio_issue_check(struct request_queue *q, blkg_rwstat_add(&blkg->stat_ios, bio->bi_opf, 1); } - rcu_read_unlock(); return !throtl; } -- 2.17.1