Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp1004509yba; Thu, 4 Apr 2019 02:12:39 -0700 (PDT) X-Google-Smtp-Source: APXvYqzmwpUFkA4u1hV5Ij4FI64n078U9zjqmWFm5BBpcNk8DSVQQPvKx3k7lBYGdwykjNYLFwv6 X-Received: by 2002:a63:c505:: with SMTP id f5mr4757615pgd.87.1554369159809; Thu, 04 Apr 2019 02:12:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554369159; cv=none; d=google.com; s=arc-20160816; b=bELhqDry6OwnkYXmgjCjUOEVYpfGGfJysBYBcIFo1Yrl4yfwOe4/D/94bXifR9C4dO FXOx2adOk26mgZ9oNhreAzEkaXleifN3RkSwtfDLvrrmgf3rO2gkLBt0hjAo6IObVqrY dGAIEBZdSJwhEPsCb3Dv9Wo7S6csLm+5eIoWsWeP8LEF9Q93CkyKpc+YEq1P9NpHOEP2 FM2Ejfy7knmPyUM6XxZTnsOPY0vMjT+0pBiFF5tIkPKT9I/cbK14Y09EWkqJwRN9+oqN HTH25raJZvT0tyQ1yubGFdiYWr3WDkZHFFM6bFo2wHLnlN0Wz7ojSUPyf/zMqO3N6mka ucog== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=ZtmqtFYF0Yl5dhGhzO97KtK14x6BuxTI1iYf2CRHI10=; b=xmDeWnAmJKj+Uj6AudisLgL5Dr5vLWVXRtPx1Fw/8fCLVpki1jXhTQ08R9NuRj88vK dZUn8uLdF98bG70PFuUAnO/oorOrllajzqK4lYzLT0w0bt4IwaYmplcIogFwdTiQa+OP STUhhAjTnFmJVewVE/wmlmDyqTFCTPnMUcSY156rsFqICoZHFi1x2ccAN29BwE4vyHiw vdRdDKX08QjJvV/ilyCGAY7MzpBggDDysWaGG2UuMLGs31cXX9ke1T2fael4qAd430df vOwE+Q+SzK4XqdhG2NxMyLwp98qP5I3+COP+uBnQzS+dSz7zfE3a8NPadives/QaNQST 7QWw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="w/A4pfDv"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g2si12109747pgi.19.2019.04.04.02.12.25; Thu, 04 Apr 2019 02:12:39 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="w/A4pfDv"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1733205AbfDDJLp (ORCPT + 99 others); Thu, 4 Apr 2019 05:11:45 -0400 Received: from mail.kernel.org ([198.145.29.99]:51646 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732770AbfDDJLo (ORCPT ); Thu, 4 Apr 2019 05:11:44 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 442D22054F; Thu, 4 Apr 2019 09:11:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1554369102; bh=W0lcxIKPPJJnqA5dMvs1llxGNMQZabJU00u8vNiPaxI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=w/A4pfDvkqZBbQfpJXjwXQ36iLLEa2RBVF5a2KRPxUTch5XmwVPa0mo1fHepjgDVm V+eLZPe2ESTxXWDoK4TH0qWv3u+EdDXmc0WokIA+E0V2t2OHq9rA5nOY19V+CXq31Z JcBK3ZTYMvrlZ0Ae6E8J+1sgNuFIRqrBLQaMIA8A= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Nikolay Borisov , Josef Bacik , David Sterba , Sasha Levin Subject: [PATCH 5.0 085/246] btrfs: dont enospc all tickets on flush failure Date: Thu, 4 Apr 2019 10:46:25 +0200 Message-Id: <20190404084622.117761306@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190404084619.236418459@linuxfoundation.org> References: <20190404084619.236418459@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 5.0-stable review patch. If anyone has any objections, please let me know. ------------------ [ Upstream commit f91587e4151e84f798f37839dddd3e4152fb4c76 ] 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. Reviewed-by: Nikolay Borisov Signed-off-by: Josef Bacik Signed-off-by: David Sterba Signed-off-by: Sasha Levin --- 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 a9656685a951..1b68700bc1c5 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -4808,6 +4808,7 @@ skip_async: } struct reserve_ticket { + u64 orig_bytes; u64 bytes; int error; struct list_head list; @@ -5030,7 +5031,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; @@ -5039,7 +5040,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; } /* @@ -5094,8 +5098,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; } @@ -5147,10 +5155,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); @@ -5171,14 +5180,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; } @@ -5204,6 +5211,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); @@ -5239,6 +5247,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); @@ -5279,25 +5288,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; } -- 2.19.1