From patchwork Mon Oct 9 21:29:10 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tejun Heo X-Patchwork-Id: 9994371 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 2209360230 for ; Mon, 9 Oct 2017 21:30:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 149CB28859 for ; Mon, 9 Oct 2017 21:30:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 131522894D; Mon, 9 Oct 2017 21:30:30 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.3 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 83E6928859 for ; Mon, 9 Oct 2017 21:30:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754379AbdJIVaB (ORCPT ); Mon, 9 Oct 2017 17:30:01 -0400 Received: from mail-qt0-f194.google.com ([209.85.216.194]:55824 "EHLO mail-qt0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755152AbdJIV3Z (ORCPT ); Mon, 9 Oct 2017 17:29:25 -0400 Received: by mail-qt0-f194.google.com with SMTP id x54so45738968qth.12; Mon, 09 Oct 2017 14:29:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=8fXvlUXZjhJuecaH0mBTPmkeaNBV4m5yfcFKXcGBrYY=; b=LaVu4usbfZRB7jab6g+4enSiN+xn9BYjNKXfwV7e4Eq5knmYCvMcQKCU6QOtM3Ndku Bbv0wjpq947qRVqaPUsa3R4zEimAzOyqyD2DDkDvXZd/Qa5fD/ZfNnft6chY7C94e8bS VDcs9zzGMg++K1ZotWaoFbCpLa9Sh7Ck3h2E0eu7si7oMKlOPMT5hWHS/qoQrf7YpMRW gKPXsVGWuQozfQcBSEocWUcRfjE/SJneZ2CaO6d610+pjvrdJUpI9i3Fujruru9zksUw bphjq/pP3+UfOrOy1IctVNiOL6fUnzUTo1GMdWWBTPD4RjfT391JJkp9TZzjkchMy/yH uUrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=8fXvlUXZjhJuecaH0mBTPmkeaNBV4m5yfcFKXcGBrYY=; b=UbCSSFwZl1i94zrPOtRXDek5mH+6EuRgp8zhbdaW+C3OUI9WOk9N/sIdrt5eNtMVBI Z6K8iQYTsrqugtvXibvKjmtoDvJuHNfFkQvHUyqiYV4w9y9GvxiQo4FKWN3GccN9dD9m TUQMFE10Vbkp9K0qLVlQi6aFap4yPjHubSt5/HIp7LSg+t+wW55vc8HmFxsS1Q3JCe40 frdl/V5URky4cCLffT9qq7tvrvz8jW5sfSJUPqcPW/6edCTVq8aSJZ9K4ig1fjEVrugt fLfZxGFzVisjUuJsqvyJ0k4pqf4s1x0uYLbYlqzm0DIxXktRqKsyaV3Ms2CZAjc5180v EGrw== X-Gm-Message-State: AMCzsaUITFbRyX6uB5OZQUkVsFptJ7hs2sRHDSH8EstmaLv/i7PqwEZH U1KbyMQn92c5FH5cqQVzqtQ= X-Google-Smtp-Source: AOwi7QDLQxPxQGW/xQIKjSML7484QEhfeBpbk0TQJFlOoy9dpxJ/SYAdqKMjviDhCTbQIY/MpPNVuw== X-Received: by 10.237.32.172 with SMTP id 41mr15746767qtb.213.1507584564784; Mon, 09 Oct 2017 14:29:24 -0700 (PDT) Received: from localhost (dhcp-ec-8-6b-ed-7a-cf.cpe.echoes.net. [72.28.5.223]) by smtp.gmail.com with ESMTPSA id i12sm5578228qkh.83.2017.10.09.14.29.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 09 Oct 2017 14:29:24 -0700 (PDT) From: Tejun Heo To: jack@suse.cz, axboe@kernel.dk, clm@fb.com, jbacik@fb.com Cc: kernel-team@fb.com, linux-kernel@vger.kernel.org, linux-btrfs@vger.kernel.org, Tejun Heo Subject: [PATCH 2/3] cgroup, writeback: implement submit_bh_blkcg_css() Date: Mon, 9 Oct 2017 14:29:10 -0700 Message-Id: <20171009212911.473208-3-tj@kernel.org> X-Mailer: git-send-email 2.9.5 In-Reply-To: <20171009212911.473208-1-tj@kernel.org> References: <20171009212911.473208-1-tj@kernel.org> Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add wbc->blkcg_css so that the blkcg_css association can be specified independently and implement submit_bh_blkcg_css() using it. This will be used to override cgroup membership on specific buffer_heads. Signed-off-by: Tejun Heo Cc: Jan Kara Cc: Jens Axboe --- fs/buffer.c | 12 ++++++++++++ fs/fs-writeback.c | 1 + include/linux/buffer_head.h | 11 +++++++++++ include/linux/writeback.h | 6 ++++-- 4 files changed, 28 insertions(+), 2 deletions(-) diff --git a/fs/buffer.c b/fs/buffer.c index 170df85..fac4f9a 100644 --- a/fs/buffer.c +++ b/fs/buffer.c @@ -3143,6 +3143,18 @@ int submit_bh(int op, int op_flags, struct buffer_head *bh) } EXPORT_SYMBOL(submit_bh); +#ifdef CONFIG_CGROUP_WRITEBACK +int submit_bh_blkcg_css(int op, int op_flags, struct buffer_head *bh, + struct cgroup_subsys_state *blkcg_css) +{ + struct writeback_control wbc = { .blkcg_css = blkcg_css }; + + /* @wbc is used just to override the bio's blkcg_css */ + return submit_bh_wbc(op, op_flags, bh, 0, &wbc); +} +EXPORT_SYMBOL(submit_bh_blkcg_css); +#endif + /** * ll_rw_block: low-level access to block devices (DEPRECATED) * @op: whether to %READ or %WRITE diff --git a/fs/fs-writeback.c b/fs/fs-writeback.c index 245c430..cd882e6 100644 --- a/fs/fs-writeback.c +++ b/fs/fs-writeback.c @@ -538,6 +538,7 @@ void wbc_attach_and_unlock_inode(struct writeback_control *wbc, } wbc->wb = inode_to_wb(inode); + wbc->blkcg_css = wbc->wb->blkcg_css; wbc->inode = inode; wbc->wb_id = wbc->wb->memcg_css->id; diff --git a/include/linux/buffer_head.h b/include/linux/buffer_head.h index c8dae55..abb4dd4 100644 --- a/include/linux/buffer_head.h +++ b/include/linux/buffer_head.h @@ -13,6 +13,7 @@ #include #include #include +#include #ifdef CONFIG_BLOCK @@ -205,6 +206,16 @@ int bh_submit_read(struct buffer_head *bh); loff_t page_cache_seek_hole_data(struct inode *inode, loff_t offset, loff_t length, int whence); +#ifdef CONFIG_CGROUP_WRITEBACK +int submit_bh_blkcg(int op, int op_flags, struct buffer_head *bh, + struct cgroup_subsys_state *blkcg_css); +#else +static inline int submit_bh_blkcg(int op, int op_flags, struct buffer_head *bh, + struct cgroup_subsys_state *blkcg_css) +{ + return submit_bh(op, op_flags, bh); +} +#endif extern int buffer_heads_over_limit; /* diff --git a/include/linux/writeback.h b/include/linux/writeback.h index d581579..81e5946 100644 --- a/include/linux/writeback.h +++ b/include/linux/writeback.h @@ -91,6 +91,8 @@ struct writeback_control { unsigned for_sync:1; /* sync(2) WB_SYNC_ALL writeback */ #ifdef CONFIG_CGROUP_WRITEBACK struct bdi_writeback *wb; /* wb this writeback is issued under */ + struct cgroup_subsys_state *blkcg_css; /* usually wb->blkcg_css but + may be overridden */ struct inode *inode; /* inode being written out */ /* foreign inode detection, see wbc_detach_inode() */ @@ -277,8 +279,8 @@ static inline void wbc_init_bio(struct writeback_control *wbc, struct bio *bio) * behind a slow cgroup. Ultimately, we want pageout() to kick off * regular writeback instead of writing things out itself. */ - if (wbc->wb) - bio_associate_blkcg(bio, wbc->wb->blkcg_css); + if (wbc->blkcg_css) + bio_associate_blkcg(bio, wbc->blkcg_css); } #else /* CONFIG_CGROUP_WRITEBACK */