public inbox for linux-btrfs@vger.kernel.org
 help / color / mirror / Atom feed
From: Leo Martins <loemra.dev@gmail.com>
To: fdmanana@kernel.org
Cc: linux-btrfs@vger.kernel.org
Subject: Re: [PATCH 2/3] btrfs: don't allow log trees to consume global reserve or overcommit metadata
Date: Tue,  3 Feb 2026 11:52:52 -0800	[thread overview]
Message-ID: <20260203195255.201241-1-loemra.dev@gmail.com> (raw)
In-Reply-To: <2e171d116e186d839cde6430cb42551aaea5943e.1770123545.git.fdmanana@suse.com>

On Tue,  3 Feb 2026 13:02:32 +0000 fdmanana@kernel.org wrote:

> From: Filipe Manana <fdmanana@suse.com>
> 
> For a fsync we never reserve space in advance, we just start a transaction
> without reserving space and we use an empty block reserve for a log tree.
> We reserve space as we need while updating a log tree, we end up in
> btrfs_use_block_rsv() when reserving space for the allocation of a log
> tree extent buffer and we attempt first to reserve without flushing,
> and if that fails we attempt to consume from the global reserve or
> overcommit metadata. This makes us consume space that may be the last
> resort for a transaction commit to succeed, therefore increasing the
> chances for a transaction abort with -ENOSPC.
> 
> So make btrfs_use_block_rsv() fail if we can't reserve metadata space for
> a log tree exent buffer allocation without flushing, making the fsync
> fallback to a transaction commit and avoid using critical space that could
> be the only resort for a transaction commit to succeed when we are in a
> critical space situation.

I agree. I thought it might be an interesting idea to use an
allowlist vs blocklist to be extra explicit about who is able
to use global block reserve, but it looks like the log tree
is unique in its ability to fallback from failing to reserve.

Reviewed-by: Leo Martins <loemra.dev@gmail.com>

> 
> Signed-off-by: Filipe Manana <fdmanana@suse.com>
> ---
>  fs/btrfs/block-rsv.c | 25 +++++++++++++++++++++++++
>  1 file changed, 25 insertions(+)
> 
> diff --git a/fs/btrfs/block-rsv.c b/fs/btrfs/block-rsv.c
> index e823230c09b7..fe81d9e9f08c 100644
> --- a/fs/btrfs/block-rsv.c
> +++ b/fs/btrfs/block-rsv.c
> @@ -540,6 +540,31 @@ struct btrfs_block_rsv *btrfs_use_block_rsv(struct btrfs_trans_handle *trans,
>  					   BTRFS_RESERVE_NO_FLUSH);
>  	if (!ret)
>  		return block_rsv;
> +
> +	/*
> +	 * If we are being used for updating a log tree, fail immediately, which
> +	 * makes the fsync fallback to a transaction commit.
> +	 *
> +	 * We don't want to consume from the global block reserve, as that is
> +	 * precious space that may be needed to do updates to some trees for
> +	 * which we don't reserve space during a transaction commit (update root
> +	 * items in the root tree, device stat items in the device tree and
> +	 * quota tree updates, see btrfs_init_root_block_rsv()), or to fallback
> +	 * to in case we did not reserve enough space to run delayed items,
> +	 * delayed references, or anything else we need in order to avoid a
> +	 * transaction abort.
> +	 *
> +	 * We also don't want to do a reservation in flush emergency mode, as
> +	 * we end up using metadata that could be critical to allow a
> +	 * transaction to complete successfully and therefore increase the
> +	 * chances for a transaction abort.
> +	 *
> +	 * Log trees are an optimization and should never consume from the
> +	 * global reserve or be allowed overcommitting metadata.
> +	 */
> +	if (btrfs_root_id(root) == BTRFS_TREE_LOG_OBJECTID)
> +		return ERR_PTR(ret);
> +
>  	/*
>  	 * If we couldn't reserve metadata bytes try and use some from
>  	 * the global reserve if its space type is the same as the global
> -- 
> 2.47.2

  reply	other threads:[~2026-02-03 19:53 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-03 13:02 [PATCH 0/3] btrfs: a few space reservation fixes and comment update fdmanana
2026-02-03 13:02 ` [PATCH 1/3] btrfs: be less agressive with metadata overcommit when we can do full flushing fdmanana
2026-02-03 21:02   ` Qu Wenruo
2026-02-03 21:46     ` Filipe Manana
2026-02-03 21:59       ` Qu Wenruo
2026-02-03 22:55         ` Filipe Manana
2026-02-03 23:04           ` Qu Wenruo
2026-02-03 23:09             ` Filipe Manana
2026-02-03 23:06           ` Filipe Manana
2026-02-03 13:02 ` [PATCH 2/3] btrfs: don't allow log trees to consume global reserve or overcommit metadata fdmanana
2026-02-03 19:52   ` Leo Martins [this message]
2026-02-03 13:02 ` [PATCH 3/3] btrfs: update comment for BTRFS_RESERVE_NO_FLUSH fdmanana
2026-02-03 23:38 ` [PATCH v2 0/3] btrfs: a few space reservation fixes and comment update fdmanana
2026-02-03 23:38   ` [PATCH v2 1/3] btrfs: be less agressive with metadata overcommit when we can do full flushing fdmanana
2026-02-03 23:39   ` [PATCH v2 2/3] btrfs: don't allow log trees to consume global reserve or overcommit metadata fdmanana
2026-02-03 23:39   ` [PATCH v2 3/3] btrfs: update comment for BTRFS_RESERVE_NO_FLUSH fdmanana

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260203195255.201241-1-loemra.dev@gmail.com \
    --to=loemra.dev@gmail.com \
    --cc=fdmanana@kernel.org \
    --cc=linux-btrfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox