From patchwork Wed Nov 21 19:03:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 10693053 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D356C5A4 for ; Wed, 21 Nov 2018 19:03:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C0AB52C622 for ; Wed, 21 Nov 2018 19:03:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B47152C625; Wed, 21 Nov 2018 19:03:20 +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=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham 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 4DA4C2C622 for ; Wed, 21 Nov 2018 19:03:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731991AbeKVFiu (ORCPT ); Thu, 22 Nov 2018 00:38:50 -0500 Received: from mail-yw1-f67.google.com ([209.85.161.67]:38546 "EHLO mail-yw1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730172AbeKVFiu (ORCPT ); Thu, 22 Nov 2018 00:38:50 -0500 Received: by mail-yw1-f67.google.com with SMTP id i20so2674384ywc.5 for ; Wed, 21 Nov 2018 11:03:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:in-reply-to:references; bh=MesUQs5u+SrETuFsSQYzz/T/gOSJTHUwBA8nUlPdLvM=; b=z0ynNR5ZZOKRecLlXBBYCGuz4NKaY41uAvfB/K3MaomEE2fCXowH0JQ7EYAISbZXO4 QQ9oNwxdddSJNn5g5Dl4yop9GKJy/OL97zzOrqU4V3/mCMQyyA4X6fJdN1LvOGxuIA5y elzKBudE+Z8zkKPA8xeYRE9pqJYym8FHgVK0NqUM0mnxLWI1bUKbasmh8cdBRg4TExir x/JzCRDSdJ4JTU9HSrbarp8IFY12+CZ0wkrbXWPBJLo8bfM5mWx83mGwaPUkany0iHI/ 6/cCMVq/DC7sfWUsvatjipBLTl6JqypsLuPVoAPLUD+s0knYctUdgHw58Cp/hgUgD/bp +G9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=MesUQs5u+SrETuFsSQYzz/T/gOSJTHUwBA8nUlPdLvM=; b=ZWtBX8tcbptDP+l3JSfDDl3C+w+VBds+Fo0VmTA9KtRe9HY39EOUsGejdMYFg5hv+c e8HiVOyo1zZiIQbdIPrNGAAOCLEdUb0zq+jY0jTVmYlmcR7tglolB+65C9astJ6gW5jl i4S655YWeeY8SgmGEYSGMfKH70Ri3C6XzBVSHblHZI7lQzNbXZUTp6zajX4tyusM0lGv 9OiGRz083EHhV/ACWo9k0/aJ/OKv7k7Aa2cyRSrhk321brfBs5jV7cfGe7oI1pXWOHVL EDL+6E2gcQxJyI5amAh5T6zicl/CKKJyz7FlXeNPRcu6doA8XTmChQuBN4KjexOgPtN7 j5yw== X-Gm-Message-State: AGRZ1gKJl9MreraoyM/qv3fZB7EJyPh6FJHpLpb31cN8Uc1SzlBWeCIe oGF+NZhb4VDgm/A0atg6BpsjZ8IVnmc= X-Google-Smtp-Source: AJdET5foPP6ifynTJVwPnaPLxYk/XqzpGCNJDj7Gjt2wSQWiAfJPiJBBMOI3UsDOdaMTZNe8CexOTg== X-Received: by 2002:a81:1417:: with SMTP id 23-v6mr7698979ywu.201.1542826997950; Wed, 21 Nov 2018 11:03:17 -0800 (PST) Received: from localhost ([107.15.81.208]) by smtp.gmail.com with ESMTPSA id i8-v6sm8916838ywa.106.2018.11.21.11.03.16 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 21 Nov 2018 11:03:17 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 1/8] btrfs: check if free bgs for commit Date: Wed, 21 Nov 2018 14:03:06 -0500 Message-Id: <20181121190313.24575-2-josef@toxicpanda.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20181121190313.24575-1-josef@toxicpanda.com> References: <20181121190313.24575-1-josef@toxicpanda.com> 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 may_commit_transaction will skip committing the transaction if we don't have enough pinned space or if we're trying to find space for a SYSTEM chunk. However if we have pending free block groups in this transaction we still want to commit as we may be able to allocate a chunk to make our reservation. So instead of just returning ENOSPC, check if we have free block groups pending, and if so commit the transaction to allow us to use that free space. Signed-off-by: Josef Bacik Reviewed-by: Omar Sandoval Reviewed-by: Nikolay Borisov --- fs/btrfs/extent-tree.c | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index 8af68b13fa27..0dca250dc02e 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -4843,10 +4843,18 @@ static int may_commit_transaction(struct btrfs_fs_info *fs_info, if (!bytes) return 0; - /* See if there is enough pinned space to make this reservation */ - if (__percpu_counter_compare(&space_info->total_bytes_pinned, - bytes, - BTRFS_TOTAL_BYTES_PINNED_BATCH) >= 0) + trans = btrfs_join_transaction(fs_info->extent_root); + if (IS_ERR(trans)) + return PTR_ERR(trans); + + /* + * See if there is enough pinned space to make this reservation, or if + * we have bg's that are going to be freed, allowing us to possibly do a + * chunk allocation the next loop through. + */ + if (test_bit(BTRFS_TRANS_HAVE_FREE_BGS, &trans->transaction->flags) || + __percpu_counter_compare(&space_info->total_bytes_pinned, bytes, + BTRFS_TOTAL_BYTES_PINNED_BATCH) >= 0) goto commit; /* @@ -4854,7 +4862,7 @@ static int may_commit_transaction(struct btrfs_fs_info *fs_info, * this reservation. */ if (space_info != delayed_rsv->space_info) - return -ENOSPC; + goto enospc; spin_lock(&delayed_rsv->lock); reclaim_bytes += delayed_rsv->reserved; @@ -4868,17 +4876,14 @@ static int may_commit_transaction(struct btrfs_fs_info *fs_info, bytes -= reclaim_bytes; if (__percpu_counter_compare(&space_info->total_bytes_pinned, - bytes, - BTRFS_TOTAL_BYTES_PINNED_BATCH) < 0) { - return -ENOSPC; - } - + bytes, + BTRFS_TOTAL_BYTES_PINNED_BATCH) < 0) + goto enospc; commit: - trans = btrfs_join_transaction(fs_info->extent_root); - if (IS_ERR(trans)) - return -ENOSPC; - return btrfs_commit_transaction(trans); +enospc: + btrfs_end_transaction(trans); + return -ENOSPC; } /* From patchwork Wed Nov 21 19:03:07 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 10693055 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A54DD5A4 for ; Wed, 21 Nov 2018 19:03:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 90C2A2C622 for ; Wed, 21 Nov 2018 19:03:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8315E2C646; Wed, 21 Nov 2018 19:03:22 +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=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham 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 3220E2C622 for ; Wed, 21 Nov 2018 19:03:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731995AbeKVFiw (ORCPT ); Thu, 22 Nov 2018 00:38:52 -0500 Received: from mail-yw1-f67.google.com ([209.85.161.67]:41922 "EHLO mail-yw1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730172AbeKVFiw (ORCPT ); Thu, 22 Nov 2018 00:38:52 -0500 Received: by mail-yw1-f67.google.com with SMTP id f65so2669462ywc.8 for ; Wed, 21 Nov 2018 11:03:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:in-reply-to:references; bh=nWzyWpJZH1mR0spxKLq9P+l8mel60lXF8fmkywvihFg=; b=K9Xq1KCH5oJC8e/BrPisCprcdPq+PVmRLKKCSL1XGlj/e/XZYDmkPR4SHplGfH+cHU 3Ub33f+pufOyH4/6QcNaQ/bdqlkANlcpqUCo/fB0FjJuWpFWbu+SKeUXdiVSsQwaSjCc bYF4c3/INsJCSqSs51RH7gxHgC5dUpUagm2nA0fcmWS4eilLOjhGzf8X7MJOUhWDXu1w PXNyHP5VfBpCmC+qVWb4GuiGAPUiYZ+9bXekhfPJkBswo2ctFW7kKG2tw4cws8OBJAkF 2/AuRUtH8ArwQ5yd82UUvt3Gx8ACO+XNz6Ijfw4uClSC7iM3EWNRgmZugV2AJRmEJ8Ch 8MgQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=nWzyWpJZH1mR0spxKLq9P+l8mel60lXF8fmkywvihFg=; b=OvGYbSIEGf4B5RatzUGTsRCER1EPXO7DDdTooIAEkQrBvou4jspSKAxcKknPpNQMgd PwyGeVwYKaojuIW5fZZFBqMJ5FdOVTUZxGuD3wMPFquk+Y+SKWrhucgz26i+Kbwf1mXH 6hQEa4IqJvRpX7eoDtEJQNK4El3jYTc/Z6ciDor3Thuqeifs1jezNjCGW5xIIcRW/jvX Pm1Vdwrq2MJoZRApBA0N6YA65wQ6sq5dOwT/UluQQHSANH9hVMt4XY+TH/chgg1OhFoH HhWD+3oVtfS9MXP7zng1G4oeiq0JIksYK8CC1Jn2z+YCR9A8E3UYS/6/IWnchFk3gIeA vc4Q== X-Gm-Message-State: AGRZ1gIvkGeeKSHavt2ij3C5SD3glujoVwpwMBnXnQ7FqCPRYKE1gEtJ 7hkwVundxYt7oeeTmejfW7aL0WJM2Jc= X-Google-Smtp-Source: AJdET5d0o4GoPZtEwSDeJ2nlSVzArNkIIf1dwd/WuWCoi+VOWeDtMgd+OqDpXiV2gcDt/WqMwnl1QA== X-Received: by 2002:a81:34d3:: with SMTP id b202mr7787335ywa.241.1542826999619; Wed, 21 Nov 2018 11:03:19 -0800 (PST) Received: from localhost ([107.15.81.208]) by smtp.gmail.com with ESMTPSA id b144sm13328352ywa.33.2018.11.21.11.03.18 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 21 Nov 2018 11:03:18 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 2/8] btrfs: dump block_rsv whe dumping space info Date: Wed, 21 Nov 2018 14:03:07 -0500 Message-Id: <20181121190313.24575-3-josef@toxicpanda.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20181121190313.24575-1-josef@toxicpanda.com> References: <20181121190313.24575-1-josef@toxicpanda.com> 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 For enospc_debug having the block rsvs is super helpful to see if we've done something wrong. Signed-off-by: Josef Bacik Reviewed-by: Omar Sandoval Reviewed-by: David Sterba --- fs/btrfs/extent-tree.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index 0dca250dc02e..7a30fbc05e5e 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -8052,6 +8052,15 @@ static noinline int find_free_extent(struct btrfs_fs_info *fs_info, return ret; } +#define DUMP_BLOCK_RSV(fs_info, rsv_name) \ +do { \ + struct btrfs_block_rsv *__rsv = &(fs_info)->rsv_name; \ + spin_lock(&__rsv->lock); \ + btrfs_info(fs_info, #rsv_name ": size %llu reserved %llu", \ + __rsv->size, __rsv->reserved); \ + spin_unlock(&__rsv->lock); \ +} while (0) + static void dump_space_info(struct btrfs_fs_info *fs_info, struct btrfs_space_info *info, u64 bytes, int dump_block_groups) @@ -8071,6 +8080,12 @@ static void dump_space_info(struct btrfs_fs_info *fs_info, info->bytes_readonly); spin_unlock(&info->lock); + DUMP_BLOCK_RSV(fs_info, global_block_rsv); + DUMP_BLOCK_RSV(fs_info, trans_block_rsv); + DUMP_BLOCK_RSV(fs_info, chunk_block_rsv); + DUMP_BLOCK_RSV(fs_info, delayed_block_rsv); + DUMP_BLOCK_RSV(fs_info, delayed_refs_rsv); + if (!dump_block_groups) return; From patchwork Wed Nov 21 19:03:08 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 10693057 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0A8225A4 for ; Wed, 21 Nov 2018 19:03:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EB9CA2C646 for ; Wed, 21 Nov 2018 19:03:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DDEC72C656; Wed, 21 Nov 2018 19:03:24 +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=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham 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 8B0DA2C646 for ; Wed, 21 Nov 2018 19:03:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732004AbeKVFiy (ORCPT ); Thu, 22 Nov 2018 00:38:54 -0500 Received: from mail-yw1-f68.google.com ([209.85.161.68]:46658 "EHLO mail-yw1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730172AbeKVFiy (ORCPT ); Thu, 22 Nov 2018 00:38:54 -0500 Received: by mail-yw1-f68.google.com with SMTP id t13so2659198ywe.13 for ; Wed, 21 Nov 2018 11:03:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:in-reply-to:references; bh=hcI+0XW5aWg125geSsnhm5i+1RsuZKsRTwalaa5gUb8=; b=DhJrG7RSQwgP3Kq4QRKhFbMH3JZkuU7rQZPZkXTwVko06W/Rsg+zqYzS3GRL77OqPW VInpxlmVP+XHJkPrxnsMGLqVxa2K/0u67YjvyEbIRGtIaNkmrcz5eC6k457V4uwzHnXV Dlkw2zS+auEx/o5/hPjr5I4w+Q1NGizzwkQr4d7EYP49BcdPAlvGiXXmiJo8SXv/AQNY xGZwA6BuN8OMQswoe6lGkk3YGfTKporLiZfNOydBkSoy0oaGR1NRuancSjVwN8qahuO7 0YdZoKXXrRmOxPC/8VomWceLC5/siCQ9Ymorbq7VMVgIVfV3hB1QTZ+tZ3mf1YXtCc2L z4VQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=hcI+0XW5aWg125geSsnhm5i+1RsuZKsRTwalaa5gUb8=; b=ghamJHh/UB2Dh2uzeKFSc6R6oDF1Cv8kCyJTKu0MT9cICE+RS5PjbpzWcDlyBdKDwl RdWUOOQpZB9p9WMvdx5XM67QbmDfal9FDw13Ri4C0bLaqyR05BRENMZgYLzeqcCmN9SO TSaDRoWpvh6iwByoeWyPc5xQj7ygXa4+XObv/XY2XcduKEACvejvVG3+HeBNB2HQLKZ7 ZHktyvJJJhCSO/TL+K0CXpbGtDfRbwLwFonI7Fvr7q6BolaJKn2hLRISrQamDSLAXuII YpIoxeKEqK3pyS0JBebf4sAsLm00kf6Wh8hDqxzqTA2pFm/RBZDVcYyfYkoMzp5zQvyr 3yYQ== X-Gm-Message-State: AGRZ1gIKx32RPX0RiR6K1dSJrVqoyfQRUdal3jq1Zk0YIxHIOFUyfmVQ oSZv92ER4yDoTFKQTOfSM/FdehUeRHY= X-Google-Smtp-Source: AJdET5egDObRuQm5P8AGd3X2kmDP01y2a5+OE8JhXJAScroGnU7fS0DG1x2FHSrcOQxB0Kff5RlLjQ== X-Received: by 2002:a0d:ff82:: with SMTP id p124-v6mr7710148ywf.336.1542827001484; Wed, 21 Nov 2018 11:03:21 -0800 (PST) Received: from localhost ([107.15.81.208]) by smtp.gmail.com with ESMTPSA id j134sm995926ywb.91.2018.11.21.11.03.20 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 21 Nov 2018 11:03:20 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 3/8] btrfs: don't use global rsv for chunk allocation Date: Wed, 21 Nov 2018 14:03:08 -0500 Message-Id: <20181121190313.24575-4-josef@toxicpanda.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20181121190313.24575-1-josef@toxicpanda.com> References: <20181121190313.24575-1-josef@toxicpanda.com> 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 We've done this forever because of the voodoo around knowing how much space we have. However we have better ways of doing this now, and on normal file systems we'll easily have a global reserve of 512MiB, and since metadata chunks are usually 1GiB that means we'll allocate metadata chunks more readily. Instead use the actual used amount when determining if we need to allocate a chunk or not. Signed-off-by: Josef Bacik --- fs/btrfs/extent-tree.c | 9 --------- 1 file changed, 9 deletions(-) diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index 7a30fbc05e5e..a91b3183dcae 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -4388,21 +4388,12 @@ static inline u64 calc_global_rsv_need_space(struct btrfs_block_rsv *global) static int should_alloc_chunk(struct btrfs_fs_info *fs_info, struct btrfs_space_info *sinfo, int force) { - struct btrfs_block_rsv *global_rsv = &fs_info->global_block_rsv; u64 bytes_used = btrfs_space_info_used(sinfo, false); u64 thresh; if (force == CHUNK_ALLOC_FORCE) return 1; - /* - * We need to take into account the global rsv because for all intents - * and purposes it's used space. Don't worry about locking the - * global_rsv, it doesn't change except when the transaction commits. - */ - if (sinfo->flags & BTRFS_BLOCK_GROUP_METADATA) - bytes_used += calc_global_rsv_need_space(global_rsv); - /* * in limited mode, we want to have some free space up to * about 1% of the FS size. From patchwork Wed Nov 21 19:03:09 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 10693059 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7E6A15A4 for ; Wed, 21 Nov 2018 19:03:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6C2782C646 for ; Wed, 21 Nov 2018 19:03:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 60BC62C656; Wed, 21 Nov 2018 19:03:26 +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=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham 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 E98962C646 for ; Wed, 21 Nov 2018 19:03:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732010AbeKVFi4 (ORCPT ); Thu, 22 Nov 2018 00:38:56 -0500 Received: from mail-yb1-f195.google.com ([209.85.219.195]:41567 "EHLO mail-yb1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730172AbeKVFi4 (ORCPT ); Thu, 22 Nov 2018 00:38:56 -0500 Received: by mail-yb1-f195.google.com with SMTP id t13-v6so2632871ybb.8 for ; Wed, 21 Nov 2018 11:03:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:in-reply-to:references; bh=0C6Y1CelPQxNMboOxlsh7yFIuIZxS7fsGHquMg4krs8=; b=GP3jVao6llel7QABb2qeNj5WObmWw0PQ7k6mDsb2y7iKJEss4Xk+SCn+V8Pc2R4en2 y9pqwVAI4gPKoRCHpyiuOZE4eRiEbbk52kyxDuR5NKMT30VBbULr1mVsEr8JO/4zU/G/ g0qK5/ETnPpwaYd7Ut9MvJ8QIQ4yHDU8A5p4JjKiroLH9wevZBxjD4IyN7iZKdopV1hm ftMOu3xqvUAAW8OmaglUhNW76R2xSYkgACb09UQ+eKzZ/XsK6Kbg7l7a9xjAk4xxY5I3 s2iSzzzfui99YqIJ5R/mfOnciuYg0czjt4SKSBd0gfjuE8OoG3EUaqrAWJ4z2WJPABpl oLrw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=0C6Y1CelPQxNMboOxlsh7yFIuIZxS7fsGHquMg4krs8=; b=Fq6Z1euO6jwdBrlaBb/N86P72zwNLwN5W7yLyDURxr4tU8RCj3ZORGWhi0CMChN3o7 soFwlnqg0IB10vR/RZmKkT1KMGinuNznTECkHbY/RdNpy9rIMDNAbWWtE4af9S0A8TWa ZK4N0+1wesYrmkfX14d1n15aENRwWLWWHhIB0g08nrSlTqctgqCAwcNXgPh8c0fuGrSm 9bEfy0PbEb8jvAajIexwX5n6SV9Fw1hBrbeGK0nRNgE6Nq0JBUcUZxgzqe201lNWfPSE xNOGcBpVbEX7OCPVY5pkEw4i5ooGlszEz524YassoMiCzZOk7f8mQGoTH3io3J+OeF0J c7Eg== X-Gm-Message-State: AA+aEWYcoJ58xXtvNDNixZguyfQJpCLCcXQJDePMA2N0gZX5fB4byN6u CyUQOIvGDPjrMJYWmZOAMIQnxd9wl6A= X-Google-Smtp-Source: AFSGD/WHMVfX0V6vCYKlA4nptWZ+joOnQNJwir0donvqOZWq2sX17a5xAArifticsTqT2I7tnyCsgQ== X-Received: by 2002:a25:bc01:: with SMTP id i1-v6mr7497321ybh.239.1542827003208; Wed, 21 Nov 2018 11:03:23 -0800 (PST) Received: from localhost ([107.15.81.208]) by smtp.gmail.com with ESMTPSA id v136-v6sm11336431ywv.19.2018.11.21.11.03.22 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 21 Nov 2018 11:03:22 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 4/8] btrfs: add ALLOC_CHUNK_FORCE to the flushing code Date: Wed, 21 Nov 2018 14:03:09 -0500 Message-Id: <20181121190313.24575-5-josef@toxicpanda.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20181121190313.24575-1-josef@toxicpanda.com> References: <20181121190313.24575-1-josef@toxicpanda.com> 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 With my change to no longer take into account the global reserve for metadata allocation chunks we have this side-effect for mixed block group fs'es where we are no longer allocating enough chunks for the data/metadata requirements. To deal with this add a ALLOC_CHUNK_FORCE step to the flushing state machine. This will only get used if we've already made a full loop through the flushing machinery and tried committing the transaction. If we have then we can try and force a chunk allocation since we likely need it to make progress. This resolves the issues I was seeing with the mixed bg tests in xfstests with my previous patch. Signed-off-by: Josef Bacik Reviewed-by: Nikolay Borisov --- fs/btrfs/ctree.h | 3 ++- fs/btrfs/extent-tree.c | 18 +++++++++++++++++- include/trace/events/btrfs.h | 1 + 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h index 0c6d589c8ce4..8ccc5019172b 100644 --- a/fs/btrfs/ctree.h +++ b/fs/btrfs/ctree.h @@ -2750,7 +2750,8 @@ enum btrfs_flush_state { FLUSH_DELALLOC = 5, FLUSH_DELALLOC_WAIT = 6, ALLOC_CHUNK = 7, - COMMIT_TRANS = 8, + ALLOC_CHUNK_FORCE = 8, + COMMIT_TRANS = 9, }; int btrfs_alloc_data_chunk_ondemand(struct btrfs_inode *inode, u64 bytes); diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index a91b3183dcae..e6bb6ce23c84 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -4927,6 +4927,7 @@ static void flush_space(struct btrfs_fs_info *fs_info, btrfs_end_transaction(trans); break; case ALLOC_CHUNK: + case ALLOC_CHUNK_FORCE: trans = btrfs_join_transaction(root); if (IS_ERR(trans)) { ret = PTR_ERR(trans); @@ -4934,7 +4935,9 @@ static void flush_space(struct btrfs_fs_info *fs_info, } ret = do_chunk_alloc(trans, btrfs_metadata_alloc_profile(fs_info), - CHUNK_ALLOC_NO_FORCE); + (state == ALLOC_CHUNK) ? + CHUNK_ALLOC_NO_FORCE : + CHUNK_ALLOC_FORCE); btrfs_end_transaction(trans); if (ret > 0 || ret == -ENOSPC) ret = 0; @@ -5070,6 +5073,19 @@ static void btrfs_async_reclaim_metadata_space(struct work_struct *work) commit_cycles--; } + /* + * We don't want to force a chunk allocation until we've tried + * pretty hard to reclaim space. Think of the case where we + * free'd up a bunch of space and so have a lot of pinned space + * to reclaim. We would rather use that than possibly create a + * underutilized metadata chunk. So if this is our first run + * through the flushing state machine skip ALLOC_CHUNK_FORCE and + * commit the transaction. If nothing has changed the next go + * around then we can force a chunk allocation. + */ + if (flush_state == ALLOC_CHUNK_FORCE && !commit_cycles) + flush_state++; + if (flush_state > COMMIT_TRANS) { commit_cycles++; if (commit_cycles > 2) { diff --git a/include/trace/events/btrfs.h b/include/trace/events/btrfs.h index 63d1f9d8b8c7..dd0e6f8d6b6e 100644 --- a/include/trace/events/btrfs.h +++ b/include/trace/events/btrfs.h @@ -1051,6 +1051,7 @@ TRACE_EVENT(btrfs_trigger_flush, { FLUSH_DELAYED_REFS_NR, "FLUSH_DELAYED_REFS_NR"}, \ { FLUSH_DELAYED_REFS, "FLUSH_ELAYED_REFS"}, \ { ALLOC_CHUNK, "ALLOC_CHUNK"}, \ + { ALLOC_CHUNK_FORCE, "ALLOC_CHUNK_FORCE"}, \ { COMMIT_TRANS, "COMMIT_TRANS"}) TRACE_EVENT(btrfs_flush_space, From patchwork Wed Nov 21 19:03:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 10693061 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AA1B513BF for ; Wed, 21 Nov 2018 19:03:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 97A2A2C646 for ; Wed, 21 Nov 2018 19:03:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8C0092C656; Wed, 21 Nov 2018 19:03:28 +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=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham 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 0230C2C646 for ; Wed, 21 Nov 2018 19:03:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732023AbeKVFi6 (ORCPT ); Thu, 22 Nov 2018 00:38:58 -0500 Received: from mail-yw1-f48.google.com ([209.85.161.48]:43291 "EHLO mail-yw1-f48.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730172AbeKVFi5 (ORCPT ); Thu, 22 Nov 2018 00:38:57 -0500 Received: by mail-yw1-f48.google.com with SMTP id l200so2670232ywe.10 for ; Wed, 21 Nov 2018 11:03:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:in-reply-to:references; bh=590qDmUnB326tQzkd/+1OymhYv+QHhCcRR/OCakP6Ok=; b=nlUJHKDkxzQc8oc19Js5/CtTCf2WOqSJp169/0rdFOdmV7PW3oru8CuQnjs4VUR6QV vVCZVLavx8PbuRkcFQZseQcXa+wyYGLdBFHldyKVcvDw9fg6xkuMR1Sbnxf6iSHGyd/o a5X/1gNq4+BPGcPPuO5JBSZde+AO9XB7w4fgcKF3AxZYY8xDtBSzeniA9YsCaXmZfuxG X8j8k6i5m6qJf+wOirM0E3y41qs3DjwVVw1GwKIck1qa8Shbnneh+jz01hLu2wKoaioY 1oZOLV2SqvRVzm5supSqTr6ezdrqX20VTcJ99RSL4dr/0f3lfcVVAIrLgsSgLmK/MDAD m2Jw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=590qDmUnB326tQzkd/+1OymhYv+QHhCcRR/OCakP6Ok=; b=iqtl39a+c6b0Es+i1/H6vR9H+3pby1Cytdl8JZpxsad1bYg/qitPKC2Pq1DeInQrsT qPwXmu7l1l4warNHxWxePX0ZAtANzOk65dq3mqrZtMf4auBCb8dSvJmHZ0i1neoYp15X bcFYV74eR+od29VFaKkOgplpfv63nFoGDLaS2KDsnMPognkCXO481AIatCGkqQP21Qs3 L2yID4FlYopd3ED+502n1AniVoWGZCfKHRilgq2+Zx4ifQCf9uVmKbx0r3kPbcZD1aHx Vwo1iF1F6G9rSdOfZ5mFCbCgvLRavk1+3OHrHskwOXi2F0wqGHHOSA9DZZltzuZN7A/a yWmA== X-Gm-Message-State: AGRZ1gL6WUGIq9J+A2yg+u7yxxrFhKkfRPAqDPkfVAICGAj2rl4/VUT1 oe9fl6iURWiCs7wPQPOVUe8UMOQsk3s= X-Google-Smtp-Source: AJdET5et3uGHpryETHJRzi7COTgcmo/haYsoIaybkDlZv9TqXafiaSRWBHVRSO3h+W+sXp84cYIm3Q== X-Received: by 2002:a81:5683:: with SMTP id k125mr7333556ywb.436.1542827004900; Wed, 21 Nov 2018 11:03:24 -0800 (PST) Received: from localhost ([107.15.81.208]) by smtp.gmail.com with ESMTPSA id d85sm2417327ywd.22.2018.11.21.11.03.23 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 21 Nov 2018 11:03:24 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 5/8] btrfs: don't enospc all tickets on flush failure Date: Wed, 21 Nov 2018 14:03:10 -0500 Message-Id: <20181121190313.24575-6-josef@toxicpanda.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20181121190313.24575-1-josef@toxicpanda.com> References: <20181121190313.24575-1-josef@toxicpanda.com> 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 With the introduction of the per-inode block_rsv it became possible to have really really large reservation requests made because of data fragmentation. Since the ticket stuff assumed that we'd always have relatively small reservation requests it just killed all tickets if we were unable to satisfy the current request. However this is generally not the case anymore. So fix this logic to instead see if we had a ticket that we were able to give some reservation to, and if we were continue the flushing loop again. Likewise we make the tickets use the space_info_add_old_bytes() method of returning what reservation they did receive in hopes that it could satisfy reservations down the line. Signed-off-by: Josef Bacik --- fs/btrfs/extent-tree.c | 45 +++++++++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index e6bb6ce23c84..983d086fa768 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -4791,6 +4791,7 @@ static void shrink_delalloc(struct btrfs_fs_info *fs_info, u64 to_reclaim, } struct reserve_ticket { + u64 orig_bytes; u64 bytes; int error; struct list_head list; @@ -5012,7 +5013,7 @@ static inline int need_do_async_reclaim(struct btrfs_fs_info *fs_info, !test_bit(BTRFS_FS_STATE_REMOUNTING, &fs_info->fs_state)); } -static void wake_all_tickets(struct list_head *head) +static bool wake_all_tickets(struct list_head *head) { struct reserve_ticket *ticket; @@ -5021,7 +5022,10 @@ static void wake_all_tickets(struct list_head *head) list_del_init(&ticket->list); ticket->error = -ENOSPC; wake_up(&ticket->wait); + if (ticket->bytes != ticket->orig_bytes) + return true; } + return false; } /* @@ -5089,8 +5093,12 @@ static void btrfs_async_reclaim_metadata_space(struct work_struct *work) if (flush_state > COMMIT_TRANS) { commit_cycles++; if (commit_cycles > 2) { - wake_all_tickets(&space_info->tickets); - space_info->flush = 0; + if (wake_all_tickets(&space_info->tickets)) { + flush_state = FLUSH_DELAYED_ITEMS_NR; + commit_cycles--; + } else { + space_info->flush = 0; + } } else { flush_state = FLUSH_DELAYED_ITEMS_NR; } @@ -5142,10 +5150,11 @@ static void priority_reclaim_metadata_space(struct btrfs_fs_info *fs_info, static int wait_reserve_ticket(struct btrfs_fs_info *fs_info, struct btrfs_space_info *space_info, - struct reserve_ticket *ticket, u64 orig_bytes) + struct reserve_ticket *ticket) { DEFINE_WAIT(wait); + u64 reclaim_bytes = 0; int ret = 0; spin_lock(&space_info->lock); @@ -5166,14 +5175,12 @@ static int wait_reserve_ticket(struct btrfs_fs_info *fs_info, ret = ticket->error; if (!list_empty(&ticket->list)) list_del_init(&ticket->list); - if (ticket->bytes && ticket->bytes < orig_bytes) { - u64 num_bytes = orig_bytes - ticket->bytes; - update_bytes_may_use(space_info, -num_bytes); - trace_btrfs_space_reservation(fs_info, "space_info", - space_info->flags, num_bytes, 0); - } + if (ticket->bytes && ticket->bytes < ticket->orig_bytes) + reclaim_bytes = ticket->orig_bytes - ticket->bytes; spin_unlock(&space_info->lock); + if (reclaim_bytes) + space_info_add_old_bytes(fs_info, space_info, reclaim_bytes); return ret; } @@ -5199,6 +5206,7 @@ static int __reserve_metadata_bytes(struct btrfs_fs_info *fs_info, { struct reserve_ticket ticket; u64 used; + u64 reclaim_bytes = 0; int ret = 0; ASSERT(orig_bytes); @@ -5234,6 +5242,7 @@ static int __reserve_metadata_bytes(struct btrfs_fs_info *fs_info, * the list and we will do our own flushing further down. */ if (ret && flush != BTRFS_RESERVE_NO_FLUSH) { + ticket.orig_bytes = orig_bytes; ticket.bytes = orig_bytes; ticket.error = 0; init_waitqueue_head(&ticket.wait); @@ -5274,25 +5283,21 @@ static int __reserve_metadata_bytes(struct btrfs_fs_info *fs_info, return ret; if (flush == BTRFS_RESERVE_FLUSH_ALL) - return wait_reserve_ticket(fs_info, space_info, &ticket, - orig_bytes); + return wait_reserve_ticket(fs_info, space_info, &ticket); ret = 0; priority_reclaim_metadata_space(fs_info, space_info, &ticket); spin_lock(&space_info->lock); if (ticket.bytes) { - if (ticket.bytes < orig_bytes) { - u64 num_bytes = orig_bytes - ticket.bytes; - update_bytes_may_use(space_info, -num_bytes); - trace_btrfs_space_reservation(fs_info, "space_info", - space_info->flags, - num_bytes, 0); - - } + if (ticket.bytes < orig_bytes) + reclaim_bytes = orig_bytes - ticket.bytes; list_del_init(&ticket.list); ret = -ENOSPC; } spin_unlock(&space_info->lock); + + if (reclaim_bytes) + space_info_add_old_bytes(fs_info, space_info, reclaim_bytes); ASSERT(list_empty(&ticket.list)); return ret; } From patchwork Wed Nov 21 19:03:11 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 10693063 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D3DE713BF for ; Wed, 21 Nov 2018 19:03:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C21842C646 for ; Wed, 21 Nov 2018 19:03:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B443D2C656; Wed, 21 Nov 2018 19:03:29 +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=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham 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 4CA6F2C646 for ; Wed, 21 Nov 2018 19:03:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732032AbeKVFi7 (ORCPT ); Thu, 22 Nov 2018 00:38:59 -0500 Received: from mail-yb1-f195.google.com ([209.85.219.195]:40091 "EHLO mail-yb1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730172AbeKVFi7 (ORCPT ); Thu, 22 Nov 2018 00:38:59 -0500 Received: by mail-yb1-f195.google.com with SMTP id g9-v6so2635213ybh.7 for ; Wed, 21 Nov 2018 11:03:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:in-reply-to:references; bh=buaPteFeVuIpD8HDkTwU+lZ4EhwxY+ANt8BGHXpmHmw=; b=G/Nph4tggca3zCWPik/PqDxA12sQTRqntGxluksrIIhqmvuiYQ5z8jam66JZfwLgCl oP/Dgn6jZvkgqxyeBozMW9XwF/Fw0RiwqJZgB86nUqOTq3AKozfCqRNBChh24Nsfwuv6 aGWmiu9DZunM35hEQKVqktZbgPMN4WUfsjrP1sSW1Q4NvUzSgsAfwx+8n1PFiFLep9fe xA+7R8xodk8lybBBE0iSAAaFO1bhHn0b6zGMRjmLkYQOozMFTKCG8vXvtXUdSRDKo0TE WjQP49EIMNKJYbdcNnJTbZmbUadHeBo5dsIDjaVyD96/qAzoEdnSOIBETI85EhzBWru6 kKvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=buaPteFeVuIpD8HDkTwU+lZ4EhwxY+ANt8BGHXpmHmw=; b=layztpmgD08uPKYqBZpWfpkdGcszQulXxvAVfGnddFSPkqpoJVhG6maoZil+JVTENG vzMezZ+XVDpiKUZZX6x6mLUam7clBeWuHaWRdrkfVckQlkKnGhHD18i+PLjq65XdO5rf 6OvXtaBFld9MjxfBhCEuSqm1gbtdw4gAQp+aG8Wd8WOJiA86+cEN6HWNaG0qpZWgWRKB uJf9f5MiY9EYZ0glkntnolYTMolqocRUNf2aUBsrU6gDQ0ouUpyjEZMPVEOSrq9ZSb9L gB1z+SfwVVfdfnTwMucudCdVSvVgLyVtr7SujW1Dw0XYTasgyLmSW6dC0e6AqHaT151c xkxw== X-Gm-Message-State: AA+aEWaJ3mC3vmrjBxI6adwJbkGUEmppgdfY3IDZzcSkRFT/78yr4esq dXtsNOYHprKzsYLT64CJX4Qh53c4g1Q= X-Google-Smtp-Source: AFSGD/U5FMf3rqiTjmBJUy44zLFKTWhvr99MNGNXu8gZ3sjHX4sFsWMHGAPq/106E5tEFjCizf0low== X-Received: by 2002:a25:ba04:: with SMTP id t4-v6mr7847872ybg.251.1542827006592; Wed, 21 Nov 2018 11:03:26 -0800 (PST) Received: from localhost ([107.15.81.208]) by smtp.gmail.com with ESMTPSA id k206sm1592652ywa.16.2018.11.21.11.03.25 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 21 Nov 2018 11:03:25 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 6/8] btrfs: loop in inode_rsv_refill Date: Wed, 21 Nov 2018 14:03:11 -0500 Message-Id: <20181121190313.24575-7-josef@toxicpanda.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20181121190313.24575-1-josef@toxicpanda.com> References: <20181121190313.24575-1-josef@toxicpanda.com> 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 With severe fragmentation we can end up with our inode rsv size being huge during writeout, which would cause us to need to make very large metadata reservations. However we may not actually need that much once writeout is complete. So instead try to make our reservation, and if we couldn't make it re-calculate our new reservation size and try again. If our reservation size doesn't change between tries then we know we are actually out of space and can error out. Signed-off-by: Josef Bacik --- fs/btrfs/extent-tree.c | 56 ++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 41 insertions(+), 15 deletions(-) diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index 983d086fa768..0e9ba77e5316 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -5776,6 +5776,21 @@ int btrfs_block_rsv_refill(struct btrfs_root *root, return ret; } +static inline void __get_refill_bytes(struct btrfs_block_rsv *block_rsv, + u64 *metadata_bytes, u64 *qgroup_bytes) +{ + *metadata_bytes = 0; + *qgroup_bytes = 0; + + spin_lock(&block_rsv->lock); + if (block_rsv->reserved < block_rsv->size) + *metadata_bytes = block_rsv->size - block_rsv->reserved; + if (block_rsv->qgroup_rsv_reserved < block_rsv->qgroup_rsv_size) + *qgroup_bytes = block_rsv->qgroup_rsv_size - + block_rsv->qgroup_rsv_reserved; + spin_unlock(&block_rsv->lock); +} + /** * btrfs_inode_rsv_refill - refill the inode block rsv. * @inode - the inode we are refilling. @@ -5791,25 +5806,37 @@ static int btrfs_inode_rsv_refill(struct btrfs_inode *inode, { struct btrfs_root *root = inode->root; struct btrfs_block_rsv *block_rsv = &inode->block_rsv; - u64 num_bytes = 0; + u64 num_bytes = 0, last = 0; u64 qgroup_num_bytes = 0; int ret = -ENOSPC; - spin_lock(&block_rsv->lock); - if (block_rsv->reserved < block_rsv->size) - num_bytes = block_rsv->size - block_rsv->reserved; - if (block_rsv->qgroup_rsv_reserved < block_rsv->qgroup_rsv_size) - qgroup_num_bytes = block_rsv->qgroup_rsv_size - - block_rsv->qgroup_rsv_reserved; - spin_unlock(&block_rsv->lock); - + __get_refill_bytes(block_rsv, &num_bytes, &qgroup_num_bytes); if (num_bytes == 0) return 0; - ret = btrfs_qgroup_reserve_meta_prealloc(root, qgroup_num_bytes, true); - if (ret) - return ret; - ret = reserve_metadata_bytes(root, block_rsv, num_bytes, flush); + do { + ret = btrfs_qgroup_reserve_meta_prealloc(root, qgroup_num_bytes, true); + if (ret) + return ret; + ret = reserve_metadata_bytes(root, block_rsv, num_bytes, flush); + if (ret) { + btrfs_qgroup_free_meta_prealloc(root, qgroup_num_bytes); + last = num_bytes; + /* + * If we are fragmented we can end up with a lot of + * outstanding extents which will make our size be much + * larger than our reserved amount. If we happen to + * try to do a reservation here that may result in us + * trying to do a pretty hefty reservation, which we may + * not need once delalloc flushing happens. If this is + * the case try and do the reserve again. + */ + if (flush == BTRFS_RESERVE_FLUSH_ALL) + __get_refill_bytes(block_rsv, &num_bytes, + &qgroup_num_bytes); + } + } while (ret && last != num_bytes); + if (!ret) { block_rsv_add_bytes(block_rsv, num_bytes, false); trace_btrfs_space_reservation(root->fs_info, "delalloc", @@ -5819,8 +5846,7 @@ static int btrfs_inode_rsv_refill(struct btrfs_inode *inode, spin_lock(&block_rsv->lock); block_rsv->qgroup_rsv_reserved += qgroup_num_bytes; spin_unlock(&block_rsv->lock); - } else - btrfs_qgroup_free_meta_prealloc(root, qgroup_num_bytes); + } return ret; } From patchwork Wed Nov 21 19:03:12 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 10693065 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 427195A4 for ; Wed, 21 Nov 2018 19:03:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2F9C32C646 for ; Wed, 21 Nov 2018 19:03:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 242F82C656; Wed, 21 Nov 2018 19:03:31 +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=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham 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 BE24F2C646 for ; Wed, 21 Nov 2018 19:03:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732044AbeKVFjB (ORCPT ); Thu, 22 Nov 2018 00:39:01 -0500 Received: from mail-yb1-f193.google.com ([209.85.219.193]:41571 "EHLO mail-yb1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730172AbeKVFjB (ORCPT ); Thu, 22 Nov 2018 00:39:01 -0500 Received: by mail-yb1-f193.google.com with SMTP id t13-v6so2632966ybb.8 for ; Wed, 21 Nov 2018 11:03:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:in-reply-to:references; bh=lp7bdEvyjbTUp1Lft+VnpzABBc7yoSsXgQSZHmgtFxc=; b=G/hpkHxmwFwUBya/CW8EQrpDsuXAWJZnYbsvMlKbBht/qaaQYc0G7YQyUlrAZ2xyxg VlZjsXCvB9ew/Ux1j5ngUet1w2OyBFvaKFDYS8CYTOhXFG4gOpcZNgyMMe+jino0KQEH het0vSVXBYYrrgvfZOE+k03yMXFRl2shGuj1PKYoUjIpTp1b9KzWw8RWchs3KJszlEb4 gF13+Ww8mgAbn0z5wK19SEPIIBmywxxgcciP577XDQn3PTtcm9UMztJC97sxLOWfPsKY ctKo/qWbInM7R+Zm8mFOrk7C/jTYUONEdxs7BnxWdW7sDTX79W+2H0L6y+D/BNrUXnF4 1IqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=lp7bdEvyjbTUp1Lft+VnpzABBc7yoSsXgQSZHmgtFxc=; b=RTdn4PW7GObVlZ5qc2T+kkM4+iJ6mdRlE5oOPbnWAKdk24MnSY4+BWBFOizVpf5fKz umUPMcakLNw/0dZk38q0clIuaXbDULXwAUSh8pn/SIA447+FyEErGwa8TjHXJViwUr4e LoiPtxB+NCngN39xGl7iQZawOhFxxZAo90FH3/vOPIRp44Uq2hWsxuFIeeTTofO1flI1 wLJYvhYkTNeeut9V43jgwxM/Mg/BySTD3xxblk0UG3q2nOmWUBtDRPNPjZLMplPVwhhb IPi+QyvnTnRsi0IJ86vK/USDDgV6g5Vf00AKdBFLtctKSZRcuIwSp/5v4dTpK8cIUQgX oZQA== X-Gm-Message-State: AA+aEWbam/7ZMH7zY1kUYewyXZlIw4iMHK2OcHqjIeYKx5MosIPWK0y0 4bYS2K2rOnjAWHwiJ6TrhFgHRKWGv2U= X-Google-Smtp-Source: AJdET5ep0tsJYgOJ8Un/zcuUsUA6aXJeiPt7paTd6w1pOCdI6rtod+YMiF18l40N+7K1ulOHMbp5SQ== X-Received: by 2002:a25:1585:: with SMTP id 127-v6mr7680558ybv.208.1542827008239; Wed, 21 Nov 2018 11:03:28 -0800 (PST) Received: from localhost ([107.15.81.208]) by smtp.gmail.com with ESMTPSA id z74sm10851178ywz.51.2018.11.21.11.03.27 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 21 Nov 2018 11:03:27 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 7/8] btrfs: be more explicit about allowed flush states Date: Wed, 21 Nov 2018 14:03:12 -0500 Message-Id: <20181121190313.24575-8-josef@toxicpanda.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20181121190313.24575-1-josef@toxicpanda.com> References: <20181121190313.24575-1-josef@toxicpanda.com> 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 For FLUSH_LIMIT flushers we really can only allocate chunks and flush delayed inode items, everything else is problematic. I added a bunch of new states and it lead to weirdness in the FLUSH_LIMIT case because I forgot about how it worked. So instead explicitly declare the states that are ok for flushing with FLUSH_LIMIT and use that for our state machine. Then as we add new things that are safe we can just add them to this list. Signed-off-by: Josef Bacik --- fs/btrfs/extent-tree.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index 0e9ba77e5316..e31980d451c2 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -5112,12 +5112,18 @@ void btrfs_init_async_reclaim_work(struct work_struct *work) INIT_WORK(work, btrfs_async_reclaim_metadata_space); } +static const enum btrfs_flush_state priority_flush_states[] = { + FLUSH_DELAYED_ITEMS_NR, + FLUSH_DELAYED_ITEMS, + ALLOC_CHUNK, +}; + static void priority_reclaim_metadata_space(struct btrfs_fs_info *fs_info, struct btrfs_space_info *space_info, struct reserve_ticket *ticket) { u64 to_reclaim; - int flush_state = FLUSH_DELAYED_ITEMS_NR; + int flush_state = 0; spin_lock(&space_info->lock); to_reclaim = btrfs_calc_reclaim_metadata_size(fs_info, space_info, @@ -5129,7 +5135,8 @@ static void priority_reclaim_metadata_space(struct btrfs_fs_info *fs_info, spin_unlock(&space_info->lock); do { - flush_space(fs_info, space_info, to_reclaim, flush_state); + flush_space(fs_info, space_info, to_reclaim, + priority_flush_states[flush_state]); flush_state++; spin_lock(&space_info->lock); if (ticket->bytes == 0) { @@ -5137,15 +5144,7 @@ static void priority_reclaim_metadata_space(struct btrfs_fs_info *fs_info, return; } spin_unlock(&space_info->lock); - - /* - * Priority flushers can't wait on delalloc without - * deadlocking. - */ - if (flush_state == FLUSH_DELALLOC || - flush_state == FLUSH_DELALLOC_WAIT) - flush_state = ALLOC_CHUNK; - } while (flush_state < COMMIT_TRANS); + } while (flush_state < ARRAY_SIZE(priority_flush_states)); } static int wait_reserve_ticket(struct btrfs_fs_info *fs_info, From patchwork Wed Nov 21 19:03:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 10693067 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2662413BF for ; Wed, 21 Nov 2018 19:03:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 111DD2B625 for ; Wed, 21 Nov 2018 19:03:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 027EE288B8; Wed, 21 Nov 2018 19:03:32 +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=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham 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 7AF73288B8 for ; Wed, 21 Nov 2018 19:03:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732050AbeKVFjD (ORCPT ); Thu, 22 Nov 2018 00:39:03 -0500 Received: from mail-yb1-f193.google.com ([209.85.219.193]:33358 "EHLO mail-yb1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730172AbeKVFjC (ORCPT ); Thu, 22 Nov 2018 00:39:02 -0500 Received: by mail-yb1-f193.google.com with SMTP id i78-v6so2649917ybg.0 for ; Wed, 21 Nov 2018 11:03:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:in-reply-to:references; bh=yu2JCWkP7NYdrcPQZD2JAvRccQo2pQnedGA9JoGG3ao=; b=jtn15UxtHkJpj3Vt36CUpr0boxQRTEiE7HMcpfj5g1lS3S/0n3gz7rYbM5h6hwCBg5 O2uv010D+NBNf1vzIpPBndLjqtHJASjoZCiUWeEJWM+1Hr1eICpJyIqVnFeEZ7lsmUax BHGu0SCTD6jbPwDtWcnCt2BoUySHBUNmd9ko0YvLJRpKJjHULlXIEo1e+J1cnu46L8K/ LhEWTdArAwciP7ghDxROkN9CrMIppowtPIO53FO8Pk9ug1MDHe3jNo0sbyLO/evk7DxN /IvcZKLGCrXMD6r2GsRYhCsi6Ma8VoqBAggvA0UwmmpLkbq7Ks5XXAOrcHnIfRJBg3VQ 7lrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=yu2JCWkP7NYdrcPQZD2JAvRccQo2pQnedGA9JoGG3ao=; b=tYnBa06YGk8Cp2zHQMHobikGiSMpQONFv9HSnjd5+qIICeZGAv+b7WVYtk4nowNgKU 7bcn08uWL8lQG0S0E3rpgAkSO7iqUjtGqnSEpAXGSdNpzEGtXYoNGGIuDMVgLYd8ydM6 Lu55+/IBx1PgUZAfbcZGCacTTe+YFM16QbmcxGDbiy4xsM+wy8jo5WAupMux2Rn6gVOz 8vZvSxvz7F7IQ4+e59Cxl9crcMk1MI1hhYGv/I7J6xZnRvmH5WlPl9aK/Y2BbCdTg3UC MfpXZdBURD/Eo/p3R4uj9hHqlJM9Cde5spAnipq98rGzS9ZJ2AGJqeVsbpU5uAUGqJo4 VGqA== X-Gm-Message-State: AA+aEWaVzzgbGL3MwAZo05qXkT/lXTKxmzHN+quP/9Wa+VArIvU7Izc/ Yai6Q6Zq45xYIPYDiKXBHLtPi8VKSFQ= X-Google-Smtp-Source: AFSGD/XpVDyidW4KcZ/d8uEebRzPSk9xuU0qPsHm5joeYs+qd1B8L93VfmmWdGClvZyYZCKkk8Ps0A== X-Received: by 2002:a25:2317:: with SMTP id j23-v6mr1153922ybj.457.1542827009992; Wed, 21 Nov 2018 11:03:29 -0800 (PST) Received: from localhost ([107.15.81.208]) by smtp.gmail.com with ESMTPSA id t141-v6sm7631345ywc.8.2018.11.21.11.03.29 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 21 Nov 2018 11:03:29 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 8/8] btrfs: reserve extra space during evict() Date: Wed, 21 Nov 2018 14:03:13 -0500 Message-Id: <20181121190313.24575-9-josef@toxicpanda.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20181121190313.24575-1-josef@toxicpanda.com> References: <20181121190313.24575-1-josef@toxicpanda.com> 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 We could generate a lot of delayed refs in evict but never have any left over space from our block rsv to make up for that fact. So reserve some extra space and give it to the transaction so it can be used to refill the delayed refs rsv every loop through the truncate path. Signed-off-by: Josef Bacik --- fs/btrfs/inode.c | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index cae30f6c095f..3da9ac463344 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -5258,13 +5258,15 @@ static struct btrfs_trans_handle *evict_refill_and_join(struct btrfs_root *root, { struct btrfs_fs_info *fs_info = root->fs_info; struct btrfs_block_rsv *global_rsv = &fs_info->global_block_rsv; + u64 delayed_refs_extra = btrfs_calc_trans_metadata_size(fs_info, 1); int failures = 0; for (;;) { struct btrfs_trans_handle *trans; int ret; - ret = btrfs_block_rsv_refill(root, rsv, rsv->size, + ret = btrfs_block_rsv_refill(root, rsv, + rsv->size + delayed_refs_extra, BTRFS_RESERVE_FLUSH_LIMIT); if (ret && ++failures > 2) { @@ -5273,9 +5275,28 @@ static struct btrfs_trans_handle *evict_refill_and_join(struct btrfs_root *root, return ERR_PTR(-ENOSPC); } + /* + * Evict can generate a large amount of delayed refs without + * having a way to add space back since we exhaust our temporary + * block rsv. We aren't allowed to do FLUSH_ALL in this case + * because we could deadlock with so many things in the flushing + * code, so we have to try and hold some extra space to + * compensate for our delayed ref generation. If we can't get + * that space then we need see if we can steal our minimum from + * the global reserve. We will be ratelimited by the amount of + * space we have for the delayed refs rsv, so we'll end up + * committing and trying again. + */ trans = btrfs_join_transaction(root); - if (IS_ERR(trans) || !ret) + if (IS_ERR(trans) || !ret) { + if (!IS_ERR(trans)) { + trans->block_rsv = &fs_info->trans_block_rsv; + trans->bytes_reserved = delayed_refs_extra; + btrfs_block_rsv_migrate(rsv, trans->block_rsv, + delayed_refs_extra, 1); + } return trans; + } /* * Try to steal from the global reserve if there is space for