public inbox for linux-btrfs@vger.kernel.org
 help / color / mirror / Atom feed
From: Qu Wenruo <quwenruo.btrfs@gmx.com>
To: dsterba@suse.cz, Qu Wenruo <wqu@suse.com>,
	Linux Memory Management List <linux-mm@kvack.org>
Cc: linux-btrfs@vger.kernel.org
Subject: Re: [PATCH v2 1/3] btrfs: introduce a read path dedicated extent lock helper
Date: Wed, 26 Feb 2025 10:34:01 +1030	[thread overview]
Message-ID: <41726b65-3b69-4aa3-a3e8-257d2bd3680b@gmx.com> (raw)
In-Reply-To: <20250225130018.GO5777@twin.jikos.cz>



在 2025/2/25 23:30, David Sterba 写道:
> On Wed, Feb 12, 2025 at 01:22:45PM +1030, Qu Wenruo wrote:
>> Signed-off-by: Qu Wenruo <wqu@suse.com>
[...]
>> +	folio = filemap_get_folio(binode->vfs_inode.i_mapping,
>> +				  cur >> PAGE_SHIFT);
>
> Should this be folio_shift?

This is the biggest trap!

The filemap_* helpers are always using page index, no matter the folio size.

The filemap can be considered as a super large array of folio pointers.
(Implenmented by xarray)

For the current folio size == page size case, it's straight forward, if
there is a pointer then there is a cached folio for that index.

For larger folios, the overall idea is not changed, just we can have a
larger folio covering multiple slots, no longer one folio one slot.

So when doing the search we should always use PAGE_SHIFT.

And that why I hope the MM guys can provide a fileoff based
filemap_get_folio_by_fileoff().

CC MM guys, will a dedicated helper reduce such confusion?
Or it's just making the currently very simple filemap_*() helpers too
complex?

Thanks,
Qu

[...]
>> +again:
>> +	lock_extent(&binode->io_tree, start, end, cached_state);
>> +	cur_pos = start;
>> +	while (cur_pos < end) {
>> +		ordered = btrfs_lookup_ordered_range(binode, cur_pos,
>> +						     end - cur_pos + 1);
>> +		/*
>> +		 * No ordered extents in the range, and we hold the
>> +		 * extent lock, no one can modify the extent maps
>> +		 * in the range, we're safe to return.
>> +		 */
>> +		if (!ordered)
>> +			break;
>> +
>> +		/* Check if we can skip waiting for the whole OE. */
>> +		if (can_skip_ordered_extent(binode, ordered, start, end)) {
>> +			cur_pos = min(ordered->file_offset + ordered->num_bytes,
>> +				      end + 1);
>> +			btrfs_put_ordered_extent(ordered);
>> +			continue;
>> +		}
>> +
>> +		/* Now wait for the OE to finish. */
>> +		unlock_extent(&binode->io_tree, start, end,
>> +			      cached_state);
>> +		btrfs_start_ordered_extent(ordered, start, end + 1 - start);
>> +		btrfs_put_ordered_extent(ordered);
>> +		/* We have unlocked the whole range, restart from the beginning. */
>> +		goto again;
>
> This is a bit wild, goto at the end of a while loop but I don't see a
> cleaner way without making complicated in another way.

I have fixed this in the one submitted the mail list, by introducing
another layer of while loop (in another function).

Thanks,
Qu

  reply	other threads:[~2025-02-26  0:04 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-12  2:52 [PATCH v2 0/3] btrfs: enhancement to pass generic/563 Qu Wenruo
2025-02-12  2:52 ` [PATCH v2 1/3] btrfs: introduce a read path dedicated extent lock helper Qu Wenruo
2025-02-25 13:00   ` David Sterba
2025-02-26  0:04     ` Qu Wenruo [this message]
2025-02-12  2:52 ` [PATCH v2 2/3] btrfs: make btrfs_do_readpage() to do block-by-block read Qu Wenruo
2025-02-25 13:04   ` David Sterba
2025-02-12  2:52 ` [PATCH v2 3/3] btrfs: allow buffered write to avoid full page read if it's block aligned Qu Wenruo
2025-02-25 13:05   ` 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=41726b65-3b69-4aa3-a3e8-257d2bd3680b@gmx.com \
    --to=quwenruo.btrfs@gmx.com \
    --cc=dsterba@suse.cz \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=linux-mm@kvack.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