public inbox for linux-btrfs@vger.kernel.org
 help / color / mirror / Atom feed
From: Qu Wenruo <quwenruo.btrfs@gmx.com>
To: Matthew Wilcox <willy@infradead.org>, Qu Wenruo <wqu@suse.com>
Cc: Chris Mason <clm@fb.com>, Josef Bacik <josef@toxicpanda.com>,
	David Sterba <dsterba@suse.com>,
	linux-btrfs@vger.kernel.org
Subject: Re: [PATCH 2/2] btrfs: Use a folio array throughout the defrag process
Date: Sat, 9 Dec 2023 08:00:21 +1030	[thread overview]
Message-ID: <091034fc-fdc8-4fea-b282-cb2062e0ff52@gmx.com> (raw)
In-Reply-To: <ZXOJjiP7OoEMKYaT@casper.infradead.org>



On 2023/12/9 07:54, Matthew Wilcox wrote:
> On Sat, Dec 09, 2023 at 07:44:34AM +1030, Qu Wenruo wrote:
>>> @@ -875,7 +875,7 @@ static struct page *defrag_prepare_one_page(struct btrfs_inode *inode, pgoff_t i
>>>    	folio = __filemap_get_folio(mapping, index,
>>>    			FGP_LOCK | FGP_ACCESSED | FGP_CREAT, mask);
>>>    	if (IS_ERR(folio))
>>> -		return &folio->page;
>>
>> What's the proper way to grab the first page of a folio?
>
> It depends why you're doing it.
>
> If you're just doing it temporarily to convert back from folio to page
> so you can make progress on the conversion, use &folio->page.  That
> is a "bad code smell", but acceptable while you're doing the conversion.
> It's a good signal "there is more work here to be done".
>
>> For now, I'm going folio_page() and it's the same wrapper using folio->page,
>> but I'm wondering would there be any recommendation for it.
>
> folio_page() is good when you actually need a particular page.  eg you're
> going to call kmap().  When we get to finally divorcing folio from page,
> folio_page() will still work, and &folio->page won't.
>
>>> @@ -1172,7 +1172,7 @@ static int defrag_one_locked_target(struct btrfs_inode *inode,
>>>    	const u64 len = target->len;
>>>    	unsigned long last_index = (start + len - 1) >> PAGE_SHIFT;
>>>    	unsigned long start_index = start >> PAGE_SHIFT;
>>> -	unsigned long first_index = page_index(pages[0]);
>>> +	unsigned long first_index = folios[0]->index;
>>
>> The same for index, there is a folio_index() wrapper.
>>
>> So should we go the wrapper or would the wrapper be gone in the future?
>
> folio_index() has a specific purpose (just like page_index() did, but it
> seems like a lot of filesystem people never read the kernel-doc on it).

Indeed I should check the code, it says very clearly:

  * If you know
  * the page is definitely in the page cache, you can look at the folio's
  * index directly.


> In short, filesystems never need to call folio_index(), nor page_index().

Yep, as when fs got the page they are mostly already mapped.

> You can always just use folio->index unless you're in the direct-io path
> (and you shouldn't be looking at folio_index() then either!).

And DIO pages are never mapped thus never call that.

>
>>> @@ -1189,8 +1189,8 @@ static int defrag_one_locked_target(struct btrfs_inode *inode,
>>>    	/* Update the page status */
>>>    	for (i = start_index - first_index; i <= last_index - first_index; i++) {
>>> -		ClearPageChecked(pages[i]);
>>> -		btrfs_page_clamp_set_dirty(fs_info, pages[i], start, len);
>>> +		folio_clear_checked(folios[i]);
>>> +		btrfs_page_clamp_set_dirty(fs_info, &folios[i]->page, start, len);
>>
>> After my patch "2/3 btrfs: migrate subpage code to folio interfaces",
>> btrfs_page_*() helpers accept folio parameter directly, thus this may lead
>> to a conflicts.
>
> I built against linux-next 20231207; I thought all your folio changes
> had landed there?  If you want to adopt these patches and land them
> after yours, I am more than OK with that!

No big deal, David and I can definitely handle the conflicts, no need to
bother you.

Thanks a lot for the lesson on the folio interface best practice!
Qu

>

  reply	other threads:[~2023-12-08 21:30 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-08 19:27 [PATCH 1/2] btrfs: Convert defrag_prepare_one_page() to use a folio Matthew Wilcox (Oracle)
2023-12-08 19:27 ` [PATCH 2/2] btrfs: Use a folio array throughout the defrag process Matthew Wilcox (Oracle)
2023-12-08 21:14   ` Qu Wenruo
2023-12-08 21:24     ` Matthew Wilcox
2023-12-08 21:30       ` Qu Wenruo [this message]
2023-12-08 20:56 ` [PATCH 1/2] btrfs: Convert defrag_prepare_one_page() to use a folio Qu Wenruo
2023-12-08 21:16   ` Matthew Wilcox
2023-12-08 21:24     ` Qu Wenruo
  -- strict thread matches above, loose matches on Subject: below --
2023-08-14 17:03 Matthew Wilcox (Oracle)
2023-08-14 17:03 ` [PATCH 2/2] btrfs: Use a folio array throughout the defrag process Matthew Wilcox (Oracle)
2023-08-17 12:34   ` 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=091034fc-fdc8-4fea-b282-cb2062e0ff52@gmx.com \
    --to=quwenruo.btrfs@gmx.com \
    --cc=clm@fb.com \
    --cc=dsterba@suse.com \
    --cc=josef@toxicpanda.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=willy@infradead.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