Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp1005360yba; Thu, 4 Apr 2019 02:13:53 -0700 (PDT) X-Google-Smtp-Source: APXvYqzhtk7IrJfwOcV2nmMlCwhhpEFWMK6XaYd7A/Hff1/jQ7sG57eiNhS7t3Rzd8I7QdjpkfZc X-Received: by 2002:a65:5cc8:: with SMTP id b8mr4639646pgt.36.1554369233197; Thu, 04 Apr 2019 02:13:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554369233; cv=none; d=google.com; s=arc-20160816; b=bC32fqWBhrIiRfZa86PP1YtMh5tVpYhl6+qVLGi3Z5SG3sG+OowgQ2pRhcSPiT2SXH TP56epL+YzOovIQRz4MLk0V+AYhrwQctxnhCOQ2FTvDXcCmT0LzZkaq0iH4I9NvBaxTL +9qOKWSY7R0OvoaZ6RxEe3Thln2emWt9XO0NZaDnG20cxN4M9iwMWQXtiVU7q0qWYbeC aw8HQ7aisi3rIeraCGTWJxmXJ7xK2I3UBnBJRIXmVHquIck55rUFOEty7KB+wZy2KYR6 dGLQvjBL97LyNHIzJ1DJ0NxHxjpm+9ks6spq0fNHP6ac4LxdCk07tOJSFNQDggjceqtK Pm6g== 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=lb2b6XN8jT+6fPyFZ4ryNtTTfWi8geGLUmiwpqB1LEE=; b=mdzOn8t4AcZVDzU9Hfz/sH6QMkCm0v4grEr/sDv2ijQUec/e39F0pZ/EruiGj82DKR uBvMWMCxZJvsPoT/hl3aQTZ7z4W8DDTFtlQTsLMAdTu5PALMUKxD8z+4ks6IKUAVp5O2 oikaAV5MUWR9ZCN6OAXbUHKf3abnIM3smwUuLsTjuRejaRslOpUTkLGKYGzMQb9qVp/S dWnfOSn9ShRF/AEdSqRtGx9UGGMf5p9GwuqkoZbE37D6H+OA6zD4D7OsbzMCtaC2zcwL PZPVjB2wbhKSkv9zDRs3R4YXWRnKMucEWklWKSRlevqRz7gfCYDd1zFOpE7q6ct9LtFW G4/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=vWuKjwkQ; 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 m15si16386988pgj.126.2019.04.04.02.13.38; Thu, 04 Apr 2019 02:13:53 -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=vWuKjwkQ; 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 S1733012AbfDDJLr (ORCPT + 99 others); Thu, 4 Apr 2019 05:11:47 -0400 Received: from mail.kernel.org ([198.145.29.99]:51596 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733194AbfDDJLl (ORCPT ); Thu, 4 Apr 2019 05:11:41 -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 93AFE2054F; Thu, 4 Apr 2019 09:11:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1554369100; bh=bd8uKPHdqgqUbzuemPw5ZvsQVDhpftHuHdL7BklAn7I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vWuKjwkQEst17Gh97SLnYduVEviAXXmuUh8sKKBe4U+01VKA9tIoXoLgXDZcbuRUF tVbAwAmbGXNURLgkS5U/1T4C0YocSSWRe14Ps7a5GkuU2162K77QuOhCmXy6FrL9X0 sRABxmBpWhP/Uci18aWj/7AuYlDA1VGItutcAxJY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Qu Wenruo , David Sterba , Sasha Levin Subject: [PATCH 5.0 084/246] btrfs: qgroup: Make qgroup async transaction commit more aggressive Date: Thu, 4 Apr 2019 10:46:24 +0200 Message-Id: <20190404084622.082725562@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 f5fef4593653dfa2a865c485bb81415de51d5c99 ] [BUG] Btrfs qgroup will still hit EDQUOT under the following case: $ dev=/dev/test/test $ mnt=/mnt/btrfs $ umount $mnt &> /dev/null $ umount $dev &> /dev/null $ mkfs.btrfs -f $dev $ mount $dev $mnt -o nospace_cache $ btrfs subv create $mnt/subv $ btrfs quota enable $mnt $ btrfs quota rescan -w $mnt $ btrfs qgroup limit -e 1G $mnt/subv $ fallocate -l 900M $mnt/subv/padding $ sync $ rm $mnt/subv/padding # Hit EDQUOT $ xfs_io -f -c "pwrite 0 512M" $mnt/subv/real_file [CAUSE] Since commit a514d63882c3 ("btrfs: qgroup: Commit transaction in advance to reduce early EDQUOT"), btrfs is not forced to commit transaction to reclaim more quota space. Instead, we just check pertrans metadata reservation against some threshold and try to do asynchronously transaction commit. However in above case, the pertrans metadata reservation is pretty small thus it will never trigger asynchronous transaction commit. [FIX] Instead of only accounting pertrans metadata reservation, we calculate how much free space we have, and if there isn't much free space left, commit transaction asynchronously to try to free some space. This may slow down the fs when we have less than 32M free qgroup space, but should reduce a lot of false EDQUOT, so the cost should be acceptable. Signed-off-by: Qu Wenruo Signed-off-by: David Sterba Signed-off-by: Sasha Levin --- fs/btrfs/qgroup.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/fs/btrfs/qgroup.c b/fs/btrfs/qgroup.c index 543dd5e66f31..e28fb43e943b 100644 --- a/fs/btrfs/qgroup.c +++ b/fs/btrfs/qgroup.c @@ -2842,16 +2842,15 @@ out: /* * Two limits to commit transaction in advance. * - * For RATIO, it will be 1/RATIO of the remaining limit - * (excluding data and prealloc meta) as threshold. + * For RATIO, it will be 1/RATIO of the remaining limit as threshold. * For SIZE, it will be in byte unit as threshold. */ -#define QGROUP_PERTRANS_RATIO 32 -#define QGROUP_PERTRANS_SIZE SZ_32M +#define QGROUP_FREE_RATIO 32 +#define QGROUP_FREE_SIZE SZ_32M static bool qgroup_check_limits(struct btrfs_fs_info *fs_info, const struct btrfs_qgroup *qg, u64 num_bytes) { - u64 limit; + u64 free; u64 threshold; if ((qg->lim_flags & BTRFS_QGROUP_LIMIT_MAX_RFER) && @@ -2870,20 +2869,21 @@ static bool qgroup_check_limits(struct btrfs_fs_info *fs_info, */ if ((qg->lim_flags & (BTRFS_QGROUP_LIMIT_MAX_RFER | BTRFS_QGROUP_LIMIT_MAX_EXCL))) { - if (qg->lim_flags & BTRFS_QGROUP_LIMIT_MAX_EXCL) - limit = qg->max_excl; - else - limit = qg->max_rfer; - threshold = (limit - qg->rsv.values[BTRFS_QGROUP_RSV_DATA] - - qg->rsv.values[BTRFS_QGROUP_RSV_META_PREALLOC]) / - QGROUP_PERTRANS_RATIO; - threshold = min_t(u64, threshold, QGROUP_PERTRANS_SIZE); + if (qg->lim_flags & BTRFS_QGROUP_LIMIT_MAX_EXCL) { + free = qg->max_excl - qgroup_rsv_total(qg) - qg->excl; + threshold = min_t(u64, qg->max_excl / QGROUP_FREE_RATIO, + QGROUP_FREE_SIZE); + } else { + free = qg->max_rfer - qgroup_rsv_total(qg) - qg->rfer; + threshold = min_t(u64, qg->max_rfer / QGROUP_FREE_RATIO, + QGROUP_FREE_SIZE); + } /* * Use transaction_kthread to commit transaction, so we no * longer need to bother nested transaction nor lock context. */ - if (qg->rsv.values[BTRFS_QGROUP_RSV_META_PERTRANS] > threshold) + if (free < threshold) btrfs_commit_transaction_locksafe(fs_info); } -- 2.19.1