From: Qu Wenruo <quwenruo.btrfs@gmx.com>
To: Mark Harmstone <mark@harmstone.com>, linux-btrfs@vger.kernel.org
Subject: Re: [PATCH] btrfs: fix double-decrement of bytes_may_use in submit_one_async_extent()
Date: Fri, 17 Apr 2026 06:58:59 +0930 [thread overview]
Message-ID: <b9b1f7e7-91f3-4b26-905b-6da1359ebe9d@gmx.com> (raw)
In-Reply-To: <20260416174359.262120-1-mark@harmstone.com>
在 2026/4/17 03:13, Mark Harmstone 写道:
> submit_one_async_extent() calls btrfs_reserve_extent(), which decrements
> bytes_may_use. If the call btrfs_create_io_em() fails, we jump to
> out_free_reserve, which calls extent_clear_unlock_delalloc().
>
> Because we're specifying EXTENT_DO_ACCOUNTING, i.e.
> EXTENT_CLEAR_META_RESV | EXTENT_CLEAR_DATA_RESV, this decreases
> bytes_may_use again. This can lead to problems later on, as an initial
> write can fail only for the writeback to silently ENOSPC.
>
> Fix this by replacing EXTENT_DO_ACCOUNTING with EXTENT_CLEAR_META_RESV.
> This parallels a4fe134fc1d8, which is the same fix in cow_one_range().
>
> Fixes: 151a41bc46df ("Btrfs: fix what bits we clear when erroring out from delalloc")
> Signed-off-by: Mark Harmstone <mark@harmstone.com>
Reviewed-by: Qu Wenruo <wqu@suse.com>
Thanks,
Qu
> ---
> fs/btrfs/inode.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
> index 36bbf2297a9987..abedaeb45189a2 100644
> --- a/fs/btrfs/inode.c
> +++ b/fs/btrfs/inode.c
> @@ -1204,7 +1204,7 @@ static void submit_one_async_extent(struct async_chunk *async_chunk,
> NULL, &cached,
> EXTENT_LOCKED | EXTENT_DELALLOC |
> EXTENT_DELALLOC_NEW |
> - EXTENT_DEFRAG | EXTENT_DO_ACCOUNTING,
> + EXTENT_DEFRAG | EXTENT_CLEAR_META_RESV,
> PAGE_UNLOCK | PAGE_START_WRITEBACK |
> PAGE_END_WRITEBACK);
> if (async_extent->cb)
next prev parent reply other threads:[~2026-04-16 21:29 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-16 17:43 [PATCH] btrfs: fix double-decrement of bytes_may_use in submit_one_async_extent() Mark Harmstone
2026-04-16 21:28 ` Qu Wenruo [this message]
2026-04-21 3:12 ` David Sterba
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=b9b1f7e7-91f3-4b26-905b-6da1359ebe9d@gmx.com \
--to=quwenruo.btrfs@gmx.com \
--cc=linux-btrfs@vger.kernel.org \
--cc=mark@harmstone.com \
/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