From: Filipe Manana <fdmanana@gmail.com>
To: Qu Wenruo <wqu@suse.com>
Cc: linux-btrfs <linux-btrfs@vger.kernel.org>,
Dan Carpenter <dan.carpenter@oracle.com>
Subject: Re: [PATCH] btrfs: add comment on why we can return 0 if we failed to atomically lock the page in read_extent_buffer_pages()
Date: Thu, 28 Jan 2021 11:56:51 +0000 [thread overview]
Message-ID: <CAL3q7H7EKXEroFBV-FVk0y-+fxqS72bJT_fcGiZd6=Fa8sA6pw@mail.gmail.com> (raw)
In-Reply-To: <20210128112508.123614-1-wqu@suse.com>
On Thu, Jan 28, 2021 at 11:29 AM Qu Wenruo <wqu@suse.com> wrote:
>
> In read_extent_buffer_pages(), if we failed to lock the page atomically,
> we just exit with return value 0.
>
> This is pretty counter-intuitive, as normally if we can't lock what we
> need, we would return something like -EAGAIN.
>
> But the that return hides under (wait == WAIT_NONE) branch, which only
> get triggered for readahead.
>
> And for readahead, if we failed to lock the page, it means the extent
> buffer is either being read by other thread, or has been read and is
> under modification.
> Either way the eb will or has been cached, thus readahead has no need to
> wait for it.
>
> This patch will add extra comment on this counter-intuitive behavior.
>
> Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
> Signed-off-by: Qu Wenruo <wqu@suse.com>
Reviewed-by: Filipe Manana <fdmanana@suse.com>
Looks good, thanks.
> ---
> fs/btrfs/extent_io.c | 7 +++++++
> 1 file changed, 7 insertions(+)
>
> diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c
> index 7f689ad7709c..038adc423454 100644
> --- a/fs/btrfs/extent_io.c
> +++ b/fs/btrfs/extent_io.c
> @@ -5577,6 +5577,13 @@ int read_extent_buffer_pages(struct extent_buffer *eb, int wait, int mirror_num)
> for (i = 0; i < num_pages; i++) {
> page = eb->pages[i];
> if (wait == WAIT_NONE) {
> + /*
> + * WAIT_NONE is only utilized by readahead. If we can't
> + * acquire the lock atomically it means either the eb
> + * is being read out or under modification.
> + * Either way the eb will be or has been cached,
> + * readahead can exit safely.
> + */
> if (!trylock_page(page))
> goto unlock_exit;
> } else {
> --
> 2.30.0
>
--
Filipe David Manana,
“Whether you think you can, or you think you can't — you're right.”
next prev parent reply other threads:[~2021-01-28 11:58 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-28 11:25 [PATCH] btrfs: add comment on why we can return 0 if we failed to atomically lock the page in read_extent_buffer_pages() Qu Wenruo
2021-01-28 11:30 ` Dan Carpenter
2021-01-28 11:56 ` Filipe Manana [this message]
2021-02-03 13:27 ` 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='CAL3q7H7EKXEroFBV-FVk0y-+fxqS72bJT_fcGiZd6=Fa8sA6pw@mail.gmail.com' \
--to=fdmanana@gmail.com \
--cc=dan.carpenter@oracle.com \
--cc=linux-btrfs@vger.kernel.org \
--cc=wqu@suse.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;
as well as URLs for NNTP newsgroup(s).