From patchwork Tue Aug 22 20:00:39 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 9916131 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 E6E12603F9 for ; Tue, 22 Aug 2017 20:00:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D649D28912 for ; Tue, 22 Aug 2017 20:00:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CB3BC28920; Tue, 22 Aug 2017 20:00:47 +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=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 2D94428912 for ; Tue, 22 Aug 2017 20:00:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752610AbdHVUAo (ORCPT ); Tue, 22 Aug 2017 16:00:44 -0400 Received: from mail-qt0-f196.google.com ([209.85.216.196]:33649 "EHLO mail-qt0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752063AbdHVUAo (ORCPT ); Tue, 22 Aug 2017 16:00:44 -0400 Received: by mail-qt0-f196.google.com with SMTP id 57so8246698qtu.0 for ; Tue, 22 Aug 2017 13:00:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id; bh=vOjl2nqrNg3qP7mbr12G3waCZF7I3xCTb0ueLAdqna8=; b=1fy+BoTMzLYZl/4jZnKJrc8P07BbZnTadq2vXbcjoo9bvFaGSUZdqm8nZBLQIJVMUh LX6mreecdurJJGuQCc+gWa9Wax5R0lJ2uXJ+i2Fw+8Wz+sSr97e1CYPxB06qNz2cITox ycReUPwz8AMdkm5lAy/d1D8mfNfh/een8LdBe1K8NLevp1LxcgBNmD5WlienLE/YxlWm v07uteW1pCeHZyCusA3rqY4rZmFRojCiVIUQCfxprE9Ad2Gz7It72MeUDkIMw1w+fSUr 365uVW+wpxSHU37DL9PwZ3yxeCyZQDmNHUDpnrdsD3eGaSBvOCcNviHqDnj+S2fSnYQg Asfg== 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; bh=vOjl2nqrNg3qP7mbr12G3waCZF7I3xCTb0ueLAdqna8=; b=eidwzE/cZzg7l3iG0UTyM/LcVU7V1nObGYVTjuNXEel3frhIX6KBe44h2tYIEhM6WL fx3nAs8EyDqVQNmZZjAH1EQklEzXLM/VzjQ9TzaCxUdOf9hA1aJheIrYO7DEif1RoIyt 7E1oBO8zsYp8ZdUKQWI+3kbjEZZlnD+sEK1RBfRB4v7PHKqXzKmIH3FB/wbSjsG9EBOm ZXO3evF4a1DLEVSctjCEB/DIuTkdZXtjtFK7YmwtbhFXrJTInV981wy+Cff22Rjvl00j uDodJzjfvQq7Ypl+vHxllaUxwspP41VzR5VMfxxU68r11790UN2ET/5/6OIuSwtPrFgw KG6g== X-Gm-Message-State: AHYfb5h51dJvA5roZb3xt1S671sklWtJNZzSX6AkUu8ZyAO6Z36KD30O 6GZnt1nMLLz5tHXTpt9KIA== X-Received: by 10.200.42.65 with SMTP id l1mr419910qtl.193.1503432040927; Tue, 22 Aug 2017 13:00:40 -0700 (PDT) Received: from localhost ([2606:a000:4381:1201:225:22ff:feb3:e51a]) by smtp.gmail.com with ESMTPSA id m42sm7209279qtf.34.2017.08.22.13.00.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 22 Aug 2017 13:00:40 -0700 (PDT) From: josef@toxicpanda.com X-Google-Original-From: jbacik@fb.com To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Cc: Josef Bacik Subject: [PATCH][v2] btrfs: change how we decide to commit transactions during flushing Date: Tue, 22 Aug 2017 16:00:39 -0400 Message-Id: <1503432039-7666-1-git-send-email-jbacik@fb.com> X-Mailer: git-send-email 2.7.4 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: Josef Bacik Nikolay reported that generic/273 was failing currently with ENOSPC. Turns out this is because we get to the point where the outstanding reservations are greater than the pinned space on the fs. This is a mistake, previously we used the current reservation amount in may_commit_transaction, not the entire outstanding reservation amount. Fix this to find the minimum byte size needed to make progress in flushing, and pass that into may_commit_transaction. From there we can make a smarter decision on whether to commit the transaction or not. This fixes the failure in generic/273. Reported-by: Nikolay Borisov Signed-off-by: Josef Bacik --- v1->v2: - check the ticket bytes in may_commit_transaction instead of copying bytes around. - clean up may_commit_transaction to remove unused arguments fs/btrfs/extent-tree.c | 42 ++++++++++++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 14 deletions(-) diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index a5d59dd..1464678 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -4836,6 +4836,13 @@ static void shrink_delalloc(struct btrfs_fs_info *fs_info, u64 to_reclaim, } } +struct reserve_ticket { + u64 bytes; + int error; + struct list_head list; + wait_queue_head_t wait; +}; + /** * maybe_commit_transaction - possibly commit the transaction if its ok to * @root - the root we're allocating for @@ -4847,18 +4854,29 @@ static void shrink_delalloc(struct btrfs_fs_info *fs_info, u64 to_reclaim, * will return -ENOSPC. */ static int may_commit_transaction(struct btrfs_fs_info *fs_info, - struct btrfs_space_info *space_info, - u64 bytes, int force) + struct btrfs_space_info *space_info) { + struct reserve_ticket *ticket = NULL; struct btrfs_block_rsv *delayed_rsv = &fs_info->delayed_block_rsv; struct btrfs_trans_handle *trans; + u64 bytes; trans = (struct btrfs_trans_handle *)current->journal_info; if (trans) return -EAGAIN; - if (force) - goto commit; + spin_lock(&space_info->lock); + if (!list_empty(&space_info->priority_tickets)) + ticket = list_first_entry(&space_info->priority_tickets, + struct reserve_ticket, list); + else if (!list_empty(&space_info->tickets)) + ticket = list_first_entry(&space_info->tickets, + struct reserve_ticket, list); + bytes = (ticket) ? ticket->bytes : 0; + spin_unlock(&space_info->lock); + + if (!bytes) + return 0; /* See if there is enough pinned space to make this reservation */ if (percpu_counter_compare(&space_info->total_bytes_pinned, @@ -4873,8 +4891,12 @@ static int may_commit_transaction(struct btrfs_fs_info *fs_info, return -ENOSPC; spin_lock(&delayed_rsv->lock); + if (delayed_rsv->size > bytes) + bytes = 0; + else + bytes -= delayed_rsv->size; if (percpu_counter_compare(&space_info->total_bytes_pinned, - bytes - delayed_rsv->size) < 0) { + bytes) < 0) { spin_unlock(&delayed_rsv->lock); return -ENOSPC; } @@ -4888,13 +4910,6 @@ static int may_commit_transaction(struct btrfs_fs_info *fs_info, return btrfs_commit_transaction(trans); } -struct reserve_ticket { - u64 bytes; - int error; - struct list_head list; - wait_queue_head_t wait; -}; - /* * Try to flush some data based on policy set by @state. This is only advisory * and may fail for various reasons. The caller is supposed to examine the @@ -4944,8 +4959,7 @@ static void flush_space(struct btrfs_fs_info *fs_info, ret = 0; break; case COMMIT_TRANS: - ret = may_commit_transaction(fs_info, space_info, - num_bytes, 0); + ret = may_commit_transaction(fs_info, space_info); break; default: ret = -ENOSPC;