From patchwork Tue Sep 11 17:57:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 10596063 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 F0E1914BD for ; Tue, 11 Sep 2018 17:58:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DD52529B9F for ; Tue, 11 Sep 2018 17:58:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D205E29BA1; Tue, 11 Sep 2018 17:58: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 503B729B9F for ; Tue, 11 Sep 2018 17:58:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728240AbeIKW6u (ORCPT ); Tue, 11 Sep 2018 18:58:50 -0400 Received: from mail-qk1-f196.google.com ([209.85.222.196]:46775 "EHLO mail-qk1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728184AbeIKW6u (ORCPT ); Tue, 11 Sep 2018 18:58:50 -0400 Received: by mail-qk1-f196.google.com with SMTP id j7-v6so17311471qkd.13 for ; Tue, 11 Sep 2018 10:58:24 -0700 (PDT) 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=2mxVzCNxACq1z3poMv0B/IjfLJSxWzySpk6OgPHhaxI=; b=mRE0iScY9hMuK02B0ao6tutv7o61X6fIN/aprzkXDpH2rKgAKObxbM54t7ME0uDTcJ mwbSp5SfOd/Suck5/rEG0WiuJMqFENE3Sa7MK2JnTwOzDFKXN2LdfA3Vm1qrWO7qKJnQ nONCJ3KDC72V1wxc21H6HpgzPezHWx1IeTSU7nf5Rdi0EzNlSMqokpe5RZEopfANzsLi cInE2vS8o6SVlF+Y2NwfGJVusXrODNRTDXTcFcN6xSn2Vr/LPgLljyAytQDWAFIhtKp0 WSNwzW27zy53R2sCfUUIitOyKxCRhVSrM/+AcS0EWR4Yp/aVH3O1kUF2M9Cubvc8r28m G+7Q== 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=2mxVzCNxACq1z3poMv0B/IjfLJSxWzySpk6OgPHhaxI=; b=hGs/rnaYL399WR7qPPwdxJK71mnN5JMI4bEke3Y3CK0IP18pbxF3jPw5V84K3Zys4R AaUkTpthe5iQoDbOE2EipAjLOLTQ89IRR11Z9insfJZOWX/lHCpePsI6H6uF6GLUG9Va awGxzgHbAX8ZeDGxervVJhIiaepCsQ6F9AuHKbh2o/7VgIfqQBEjAAaRxFVmrT6qVFi3 EqZmHYkHfPcCRVsw7RsfxiYjsglas2744ZbsPsd+eMU9r/immEqaNlA3TyklU1o2skIY lbrjIKbrjcmRjgx4ntMQvPq2sflyJOoQw5o9asJK0IyIasVOyRm9e/28OuEHpuPMynVc xaEg== X-Gm-Message-State: APzg51BHNB3QmsuQobwxx+OrSwIOQ4GZSA8Xc6uzqwS5yJYt+63OX72+ FOKTNsSxGgUPg39ZoTI7KaeXPg== X-Google-Smtp-Source: ANB0VdY3wiPDgkzaeJ3dmhZeodUew3x5VUfbbCnZzbrADKVP/88ahKe3wegm71nmhmJT+lHw9kPWzA== X-Received: by 2002:ae9:dc05:: with SMTP id q5-v6mr18853984qkf.332.1536688704047; Tue, 11 Sep 2018 10:58:24 -0700 (PDT) Received: from localhost ([107.15.81.208]) by smtp.gmail.com with ESMTPSA id y27-v6sm12913705qtj.58.2018.09.11.10.58.22 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 11 Sep 2018 10:58:23 -0700 (PDT) From: Josef Bacik To: kernel-team@fb.com, linux-btrfs@vger.kernel.org Subject: [PATCH 07/36] btrfs: check if free bgs for commit Date: Tue, 11 Sep 2018 13:57:38 -0400 Message-Id: <20180911175807.26181-8-josef@toxicpanda.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180911175807.26181-1-josef@toxicpanda.com> References: <20180911175807.26181-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 --- 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 7168e2476944..a3baa16d456f 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -4830,10 +4830,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 -ENOSPC; + + /* + * 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; /* @@ -4841,7 +4849,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; @@ -4855,17 +4863,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; } /*