Linux Btrfs filesystem development
 help / color / mirror / Atom feed
From: Qu Wenruo <quwenruo.btrfs@gmx.com>
To: dsterba@suse.cz
Cc: Qu Wenruo <wqu@suse.com>,
	linux-btrfs@vger.kernel.org,
	Julian Taylor <julian.taylor@1und1.de>,
	Filipe Manana <fdmanana@suse.com>
Subject: Re: [PATCH v2] btrfs: do not wait for short bulk allocation
Date: Fri, 5 Apr 2024 07:38:02 +1030	[thread overview]
Message-ID: <82f0c229-c478-49ff-ac08-5e9b788ab51e@gmx.com> (raw)
In-Reply-To: <20240404195710.GL14596@twin.jikos.cz>



在 2024/4/5 06:27, David Sterba 写道:
> On Fri, Mar 29, 2024 at 06:59:57AM +1030, Qu Wenruo wrote:
>>>> This patch would only call memalloc_retry_wait() if failed to allocate
>>>> any page for tree block allocation (which goes with __GFP_NOFAIL and may
>>>> not need the special handling anyway), and reduce the latency for
>>>> btrfs_alloc_page_array().
>>>
>>> Is this saying that it can fail with GFP_NOFAIL?
>>
>> I'd say no, but never say no to memory allocation failure.
>
> It's contradicting and looks confusing in the code, either it fails or
> not.
>
>>>> Reported-by: Julian Taylor <julian.taylor@1und1.de>
>>>> Tested-by: Julian Taylor <julian.taylor@1und1.de>
>>>> Link: https://lore.kernel.org/all/8966c095-cbe7-4d22-9784-a647d1bf27c3@1und1.de/
>>>> Fixes: 395cb57e8560 ("btrfs: wait between incomplete batch memory allocations")
>>>> Reviewed-by: Filipe Manana <fdmanana@suse.com>
>>>> Signed-off-by: Qu Wenruo <wqu@suse.com>
>>>> ---
>>>> Changelog:
>>>> v2:
>>>> - Still use bulk allocation function
>>>>     Since alloc_pages_bulk_array() would fall back to single page
>>>>     allocation by itself, there is no need to go alloc_page() manually.
>>>>
>>>> - Update the commit message to indicate other fses do not call
>>>>     memalloc_retry_wait() unconditionally
>>>>     In fact, they only call it when they need to retry hard and can not
>>>>     really fail.
>>>> ---
>>>>    fs/btrfs/extent_io.c | 22 +++++++++-------------
>>>>    1 file changed, 9 insertions(+), 13 deletions(-)
>>>>
>>>> diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c
>>>> index 7441245b1ceb..c96089b6f388 100644
>>>> --- a/fs/btrfs/extent_io.c
>>>> +++ b/fs/btrfs/extent_io.c
>>>> @@ -681,31 +681,27 @@ static void end_bbio_data_read(struct btrfs_bio *bbio)
>>>>    int btrfs_alloc_page_array(unsigned int nr_pages, struct page **page_array,
>>>>    			   gfp_t extra_gfp)
>>>>    {
>>>> +	const gfp_t gfp = GFP_NOFS | extra_gfp;
>>>>    	unsigned int allocated;
>>>>
>>>>    	for (allocated = 0; allocated < nr_pages;) {
>>>>    		unsigned int last = allocated;
>>>>
>>>> -		allocated = alloc_pages_bulk_array(GFP_NOFS | extra_gfp,
>>>> -						   nr_pages, page_array);
>>>> +		allocated = alloc_pages_bulk_array(gfp, nr_pages, page_array);
>>>> +		if (unlikely(allocated == last)) {
>>>> +			/* Can not fail, wait and retry. */
>>>> +			if (extra_gfp & __GFP_NOFAIL) {
>>>> +				memalloc_retry_wait(GFP_NOFS);
>>>
>>> Can this happen? alloc_pages_bulk_array() should not fail when
>>> GFP_NOFAIL is passed, there are two allocation phases in
>>> __alloc_pages_bulk() and if it falls back to __alloc_pages() + NOFAIL it
>>> will not fail ... so what's the point of the retry?
>>
>> Yeah, that's also one of my concern.
>>
>> Unlike other fses, btrfs utilizes NOFAIL for metadata memory allocation,
>> meanwhile others do not.
>> E.g. XFS always do the retry wait even the allocation does not got a
>> page allocated. (aka, another kind of NOFAIL).
>>
>> If needed, I can drop the retry part completely.
>
> The retry logic could make sense for the normal allocations (ie. without
> NOFAIL), but as it is now it's confusing. If memory management and
> allocator says something does not fail then we should take it as such,
> same what we do with bioset allocations of bios and do not expect them
> to fail.

Got it, would remove the retry part completely.

Thanks,
Qu

  reply	other threads:[~2024-04-04 21:08 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-25 22:46 [PATCH v2] btrfs: do not wait for short bulk allocation Qu Wenruo
2024-03-25 22:57 ` Sweet Tea Dorminy
2024-03-26 13:05 ` Johannes Thumshirn
2024-03-28 15:57 ` David Sterba
2024-03-28 20:29   ` Qu Wenruo
2024-04-04 19:57     ` David Sterba
2024-04-04 21:08       ` Qu Wenruo [this message]
     [not found] ` <20240414202622.B092.409509F4@e16-tech.com>
2024-04-14 22:19   ` Qu Wenruo
2024-04-15  2:35     ` Wang Yugui

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=82f0c229-c478-49ff-ac08-5e9b788ab51e@gmx.com \
    --to=quwenruo.btrfs@gmx.com \
    --cc=dsterba@suse.cz \
    --cc=fdmanana@suse.com \
    --cc=julian.taylor@1und1.de \
    --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