From: Qu Wenruo <wqu@suse.com>
To: fdmanana@kernel.org, linux-btrfs@vger.kernel.org
Subject: Re: [PATCH v2 3/5] btrfs: simplify early error checking in btrfs_page_mkwrite()
Date: Thu, 15 May 2025 06:31:04 +0930 [thread overview]
Message-ID: <f7d7d87b-e147-453b-8850-4030c1eacd56@suse.com> (raw)
In-Reply-To: <401500c0e0108d519a4b5b5910c8678723885ed1.1747222631.git.fdmanana@suse.com>
在 2025/5/14 21:08, fdmanana@kernel.org 写道:
> From: Filipe Manana <fdmanana@suse.com>
>
> We have this entangled error checks early at btrfs_page_mkwrite():
>
> 1) Try to reserve delalloc space by calling btrfs_delalloc_reserve_space()
> and storing the return value in the ret2 variable;
>
> 2) If the reservation succeed, call file_update_time() and store the
> return value in ret2 and also set the local variable 'reserved' to
> true (1);
>
> 3) Then do an error check on ret2 to see if any of the previous calls
> failed and if so, jump either to the 'out' label or to the
> 'out_noreserve' label, depending on whether 'reserved' is true or
> not.
>
> This is unnecessarily complex. Instead change this to a simpler and
> more straighforward approach:
>
> 1) Call btrfs_delalloc_reserve_space(), if that returns an error jump to
> the 'out_noreserve' label;
>
> 2) The call file_update_time() and if that returns an error jump to the
> 'out' label.
>
> Like this there's less nested if statements, no need to use a local
> variable to track if space was reserved and if statements are used only
> to check errors.
>
> Also move the call to extent_changeset_free() out of the 'out_noreserve'
> label and under the 'out' label since the changeset is allocated only if
> the call to reserve delalloc space succeeded.
>
> Signed-off-by: Filipe Manana <fdmanana@suse.com>
Reviewed-by: Qu Wenruo <wqu@suse.com>
Thanks,
Qu> ---
> fs/btrfs/file.c | 15 +++++++--------
> 1 file changed, 7 insertions(+), 8 deletions(-)
>
> diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c
> index a2b1fc536fdd..9ecb9f3bd057 100644
> --- a/fs/btrfs/file.c
> +++ b/fs/btrfs/file.c
> @@ -1843,7 +1843,6 @@ static vm_fault_t btrfs_page_mkwrite(struct vm_fault *vmf)
> size_t fsize = folio_size(folio);
> vm_fault_t ret;
> int ret2;
> - int reserved = 0;
> u64 reserved_space;
> u64 page_start;
> u64 page_end;
> @@ -1866,17 +1865,17 @@ static vm_fault_t btrfs_page_mkwrite(struct vm_fault *vmf)
> */
> ret2 = btrfs_delalloc_reserve_space(BTRFS_I(inode), &data_reserved,
> page_start, reserved_space);
> - if (!ret2) {
> - ret2 = file_update_time(vmf->vma->vm_file);
> - reserved = 1;
> - }
> if (ret2) {
> ret = vmf_error(ret2);
> - if (reserved)
> - goto out;
> goto out_noreserve;
> }
>
> + ret2 = file_update_time(vmf->vma->vm_file);
> + if (ret2) {
> + ret = vmf_error(ret2);
> + goto out;
> + }
> +
> /* Make the VM retry the fault. */
> ret = VM_FAULT_NOPAGE;
> again:
> @@ -1972,9 +1971,9 @@ static vm_fault_t btrfs_page_mkwrite(struct vm_fault *vmf)
> btrfs_delalloc_release_extents(BTRFS_I(inode), fsize);
> btrfs_delalloc_release_space(BTRFS_I(inode), data_reserved, page_start,
> reserved_space, true);
> + extent_changeset_free(data_reserved);
> out_noreserve:
> sb_end_pagefault(inode->i_sb);
> - extent_changeset_free(data_reserved);
> return ret;
> }
>
next prev parent reply other threads:[~2025-05-14 21:01 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-14 10:29 [PATCH 0/3] btrfs: fix a bug and cleanups in btrfs_page_mkwrite() fdmanana
2025-05-14 10:29 ` [PATCH 1/3] btrfs: fix wrong start offset for delalloc space release during mmap write fdmanana
2025-05-14 10:38 ` Qu Wenruo
2025-05-14 10:41 ` Filipe Manana
2025-05-14 10:29 ` [PATCH 2/3] btrfs: pass true to btrfs_delalloc_release_space() at btrfs_page_mkwrite() fdmanana
2025-05-14 10:40 ` Qu Wenruo
2025-05-14 10:29 ` [PATCH 3/3] btrfs: simplify early error checking in btrfs_page_mkwrite() fdmanana
2025-05-14 10:50 ` Qu Wenruo
2025-05-14 10:57 ` Filipe Manana
2025-05-14 11:35 ` Filipe Manana
2025-05-14 11:38 ` [PATCH v2 0/5] btrfs: fix a bug and cleanups " fdmanana
2025-05-14 11:38 ` [PATCH v2 1/5] btrfs: fix wrong start offset for delalloc space release during mmap write fdmanana
2025-05-14 11:38 ` [PATCH v2 2/5] btrfs: pass true to btrfs_delalloc_release_space() at btrfs_page_mkwrite() fdmanana
2025-05-14 11:38 ` [PATCH v2 3/5] btrfs: simplify early error checking in btrfs_page_mkwrite() fdmanana
2025-05-14 21:01 ` Qu Wenruo [this message]
2025-05-14 11:38 ` [PATCH v2 4/5] btrfs: don't return VM_FAULT_SIGBUS on failure to set delalloc for mmap write fdmanana
2025-05-14 21:01 ` Qu Wenruo
2025-05-14 11:38 ` [PATCH v2 5/5] btrfs: use a single variable to track return value at btrfs_page_mkwrite() fdmanana
2025-05-14 21:02 ` Qu Wenruo
2025-05-15 13:19 ` [PATCH v2 0/5] btrfs: fix a bug and cleanups in btrfs_page_mkwrite() 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=f7d7d87b-e147-453b-8850-4030c1eacd56@suse.com \
--to=wqu@suse.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