From patchwork Tue Oct 10 16:43:26 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tejun Heo X-Patchwork-Id: 9996703 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 A071960216 for ; Tue, 10 Oct 2017 16:43:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 91F81286C1 for ; Tue, 10 Oct 2017 16:43:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 86D55286C5; Tue, 10 Oct 2017 16:43:43 +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 2B6DD286C1 for ; Tue, 10 Oct 2017 16:43:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932416AbdJJQnb (ORCPT ); Tue, 10 Oct 2017 12:43:31 -0400 Received: from mail-qt0-f193.google.com ([209.85.216.193]:44382 "EHLO mail-qt0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932075AbdJJQna (ORCPT ); Tue, 10 Oct 2017 12:43:30 -0400 Received: by mail-qt0-f193.google.com with SMTP id 8so7380642qtv.1; Tue, 10 Oct 2017 09:43:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=Gr9JDr11ZMBlhChAzdLK56ekpdpFIrrj2y0zQt4eFsU=; b=HdeCINselFPZZF40OKa271fuf/35/wSbH8JbFEw/CEMKEAiQvd07JU+Lniaj6xyRfv 2p2V9dufWnXkYvnmV0eCxHSdMNKV+O9UGtcd0B4fmQkv+hulHtnThPQH571WCvValHkx wk26z7gH3LQe6Lf5dlixqpXW+2K4SsS8qyba8nY0wnsRK+odgaC7SxaiWPA+06Ob2e4C ocJ4bw5rVxT4BER8Cn/KCMRL8AWYqk/lX6YKuvzI8Ez/KKk8Bq1eG0FpA0disFnOGylS 7CB1T1ZFeJI7PkchprUK8HpyOGZ6Zg0SbQfeFTIBNHmiKaNbUjDO3BmRNYFRaH93VqFz 0bwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:from:to:cc:subject:message-id :references:mime-version:content-disposition:in-reply-to:user-agent; bh=Gr9JDr11ZMBlhChAzdLK56ekpdpFIrrj2y0zQt4eFsU=; b=EGQPxigNavCHxfJEDDhvaEHWXTw9uQz6kBWXZ3qgq+zCwETjaM3VLVlS53rWaTDGQh LRas3hpNuR4NG0Qf2SEMSYFxsEALnVLsrdrhGbcCzxbEflIFM+xKsxpDdx3gfyVvZq6I kEFGEnhHYH2LE/lypBkK7c4CK/XVCxSReg3b1OmVCwPFmdPRGoomF1Qw9H3rmvEul6qF vrXC32xth2J3dvb5J2L4tj2KA7Oq+Fdwk0kWsu/aILtNhwin74qWk5uYAUnTTZATDLy0 wJeMkwKSN+jbOvmf/i8V0gpae+BfkpWrwePBmvnvRympLip0Fgx2vb0jTFl2TYyPLWMs mUow== X-Gm-Message-State: AMCzsaUtitgqrVLKJ33bPUX8TkGiU2rb+h1ZVDyOiBJtKUUZ2TKWEGIq 0Wb4cRMGALQqY6TJC/YgEng= X-Google-Smtp-Source: AOwi7QADDxPAaVmtenMPT98i2aQAzWMDlvfBCRgc4bMzDyl8HX7myqGLMczRNaZwyx/oeBZXvPzysg== X-Received: by 10.200.46.22 with SMTP id r22mr19347550qta.63.1507653809185; Tue, 10 Oct 2017 09:43:29 -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 o70sm6649615qki.35.2017.10.10.09.43.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 10 Oct 2017 09:43:28 -0700 (PDT) Date: Tue, 10 Oct 2017 09:43:26 -0700 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 Subject: [PATCH v2 5/5] btrfs: ensure that metadata and flush are issued from the root cgroup Message-ID: <20171010164325.GN3301751@devbig577.frc2.facebook.com> References: <20171010155441.753966-1-tj@kernel.org> <20171010155441.753966-6-tj@kernel.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20171010155441.753966-6-tj@kernel.org> User-Agent: Mutt/1.5.21 (2010-09-15) 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 From 3bbed8c7747739cda48f592f165e8839da076a3a Mon Sep 17 00:00:00 2001 Issuing metdata or otherwise shared IOs from !root cgroup can lead to priority inversion. This patch ensures that those IOs are always issued from the root cgroup. This patch updates btrfs_update_iflags() to not set S_CGROUPWB on btree_inodes. This isn't strictly necessary as those inodes don't call the function during init; however, this serves as documentation and prevents possible future mistakes. If this isn't desirable, please feel free to drop the section. v2: Fixed missing @bh in submit_bh_blkcg_css() call. Signed-off-by: Tejun Heo Cc: Chris Mason Cc: Josef Bacik Reviewed-by: Liu Bo --- fs/btrfs/check-integrity.c | 2 +- fs/btrfs/disk-io.c | 4 ++++ fs/btrfs/ioctl.c | 4 +++- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/check-integrity.c b/fs/btrfs/check-integrity.c index 7d5a9b5..d66774e 100644 --- a/fs/btrfs/check-integrity.c +++ b/fs/btrfs/check-integrity.c @@ -2741,7 +2741,7 @@ int btrfsic_submit_bh(int op, int op_flags, struct buffer_head *bh) struct btrfsic_dev_state *dev_state; if (!btrfsic_is_initialized) - return submit_bh(op, op_flags, bh); + return submit_bh_blkcg_css(op, op_flags, bh, blkcg_root_css); mutex_lock(&btrfsic_mutex); /* since btrfsic_submit_bh() might also be called before diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index dfdab84..fe8bbe1 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -1025,6 +1025,8 @@ static blk_status_t btree_submit_bio_hook(void *private_data, struct bio *bio, int async = check_async_write(bio_flags); blk_status_t ret; + bio_associate_blkcg(bio, blkcg_root_css); + if (bio_op(bio) != REQ_OP_WRITE) { /* * called for a read, do the setup so that checksum validation @@ -3512,6 +3514,8 @@ static void write_dev_flush(struct btrfs_device *device) return; bio_reset(bio); + bio_associate_blkcg(bio, blkcg_root_css); + bio->bi_end_io = btrfs_end_empty_barrier; bio_set_dev(bio, device->bdev); bio->bi_opf = REQ_OP_WRITE | REQ_SYNC | REQ_PREFLUSH; diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index 117cc63..8a7db6c 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c @@ -150,7 +150,9 @@ void btrfs_update_iflags(struct inode *inode) new_fl |= S_NOATIME; if (ip->flags & BTRFS_INODE_DIRSYNC) new_fl |= S_DIRSYNC; - new_fl |= S_CGROUPWB; + /* btree_inodes are always in the root cgroup */ + if (btrfs_ino(ip) != BTRFS_BTREE_INODE_OBJECTID) + new_fl |= S_CGROUPWB; set_mask_bits(&inode->i_flags, S_SYNC | S_APPEND | S_IMMUTABLE | S_NOATIME | S_DIRSYNC |