From: "Vlastimil Babka (SUSE)" <vbabka@kernel.org>
To: Johannes Weiner <hannes@cmpxchg.org>,
Salvatore Dipietro <dipiets@amazon.it>
Cc: akpm@linux-foundation.org, abuehaze@amazon.com,
alisaidi@amazon.com, blakgeof@amazon.com, brauner@kernel.org,
brendan.jackman@linux.dev, david@redhat.com, dgc@kernel.org,
dipietro.salvatore@gmail.com, djwong@kernel.org,
hch@infradead.org, hch@lst.de, linux-fsdevel@vger.kernel.org,
linux-kernel@vger.kernel.org, linux-mm@kvack.org,
linux-xfs@vger.kernel.org, mhocko@suse.com,
ritesh.list@gmail.com, rvvandan@amazon.com,
stable@vger.kernel.org, surenb@google.com, willy@infradead.org,
ziy@nvidia.com
Subject: Re: [PATCH v4] mm/page_alloc: avoid direct compaction for costly __GFP_NORETRY allocations
Date: Wed, 16 Sep 2026 13:24:31 +0200 [thread overview]
Message-ID: <8d6a8a63-4adc-458a-b548-a47bf5ff8eb7@kernel.org> (raw)
In-Reply-To: <aqQlUr-1h07G8JWM@cmpxchg.org>
On 9/11/26 17:59, Johannes Weiner wrote:
> On Thu, Sep 10, 2026 at 11:46:02AM +0000, Salvatore Dipietro wrote:
>>
>> On Sat, 05 Sep 2026 17:42:39 -0700 Andrew Morton <akpm@linux-foundation.org> wrote:
>>
>> > Is there anything particularly unusual about this test case?
>>
>> It is a stock pgbench simple-update PostgreSQL workload on a large
>> instance (96 vCPUs), using standard PostgreSQL settings and with no huge
>> pages assigned to the database. We deliberately overprovision the
>> pgbench clients: 1024 clients over 96 threads. That keeps enough writers
>> in the buffered write path concurrently to hit the costly-order
>> allocation failure path continuously. The memory fragmentation comes from
>> page tables: PostgreSQL spawns a new process per client, and those page
>> tables consume ~40% of memory, which significantly limits the page cache
>> and the free memory available.
>>
>>
>> > > Results (average of 3 runs, TPS):
>> > >
>> > > Config Avg TPS % vs Baseline
>> > > baseline (no patch) 59,408 -
>> > > With this patch 155,409 +161.6%
>> >
>> > Is this back to pre-5d8edfb900d5 performance?
>>
>> Yes - fully recovered. Here is the summary, same host and workload
>> throughout, average of 3 runs:
>>
>> Config Avg TPS % vs baseline
>> AL2023 stock 6.1 kernel 136,942 n/a
>> v7.3-rc1 baseline (no patch) 59,408 -
>> v7.3-rc1, 5d8edfb900d5 behaviour reverted 151,184 +154.5%
>> v7.3-rc1 + v4 155,409 +161.6%
>>
>> The 6.1 row predates 5d8edfb900d5 entirely. A different kernel version,
>> so not directly comparable, but it shows the performance this workload
>> used to get on this host.
>>
>> A literal "git revert 5d8edfb900d5" does not apply to v7.3-rc1 -
>> iomap_write_iter() has been rewritten since - so the reverted row is a
>> one-line behavioural revert, forcing the write loop back to copying at
>> most PAGE_SIZE per iteration:
>>
>> - size_t chunk = mapping_max_folio_size(mapping);
>> + size_t chunk = PAGE_SIZE;
>>
>> which is what the pre-5d8edfb900d5 loop computed. That makes
>> iomap_get_folio() pass no order hint, so the path issues only order-0
>> allocations.
>>
>>
>> > AI review asked a few serious-looking questions:
>> > https://sashiko.dev/#/patchset/20260904115629.3993331-1-dipiets@amazon.it
>>
>> Thanks for pointing that out. To address them, we can have something
>> like the patch below. Performance results are still similar to v4. Happy
>> to submit a formal v5 patch with it if you would like.
>
> The feedback looks misleading to me.
Agreed.
> ALLOC_NON_BLOCKING itself is fine, it usually only means something in
> conjunction with other flags, like __GFP_HIGH.
+1
> The access to
> MIGRATE_HIGHATOMIC that it points out is in itself too generous. This
> seems like a real but separate bug. It will allow GFP_TRANSHUGE_LIGHT
> into the highatomic reserves as well, for example.
I don't follow this part. For ALLOC_HIGHATOMIC you need __GFP_HIGH in
alloc_flags_nonblocking(). So GFP_TRANSHUGE_LIGHT won't get the access, no?
> The rt issue seems made up too. We're talking about costly_order &&
> __GFP_NORETRY allocations. Why would they need access to reserves?
Yep.
And the concern about warning is also moot as __GFP_NORETRY is still needed
and its users virtually always add __GFP_NOWARN as well.
>> Config Avg TPS % vs baseline
>> v7.3-rc1 baseline (no patch) 59,408 -
>> v7.3-rc1 + v4 155,409 +161.6%
>> v7.3-rc1 + proposed patch 161,994 +172.7%
>>
>> diff --git a/mm/page_alloc.c b/mm/page_alloc.c
>> index 12fac9084c48..be8b0d72a2db 100644
>> --- a/mm/page_alloc.c
>> +++ b/mm/page_alloc.c
>> @@ -4784,10 +4784,22 @@ static inline struct page *
>> __alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order,
>> struct alloc_context *ac)
>> {
>> - bool can_direct_reclaim = gfp_mask & __GFP_DIRECT_RECLAIM;
>> + const bool costly_order = order > PAGE_ALLOC_COSTLY_ORDER;
>> + /*
>> + * Costly __GFP_NORETRY callers have a cheap fallback to a lower order,
>> + * so don't stall them in direct reclaim or direct compaction. Exempt
>> + * __GFP_THISNODE (the THP attempt from alloc_pages_mpol() needs direct
>> + * compaction) and __GFP_NOFAIL (must not be made to fail). Don't
>> + * clear __GFP_DIRECT_RECLAIM from gfp_mask instead: that would also
>> + * change the alloc_flags derived by alloc_flags_slowpath().
>> + */
>> + const bool costly_noretry = costly_order &&
>> + (gfp_mask & __GFP_NORETRY) &&
>> + !(gfp_mask & (__GFP_THISNODE | __GFP_NOFAIL));
>> + bool can_direct_reclaim = !costly_noretry &&
>> + (gfp_mask & __GFP_DIRECT_RECLAIM);
>
> IMO this is worse because now there is a disconnect between these
> flags and the gfp mask again. This sets us up for subtle bugs.
>
> I much preferred v4.
Unless I'm mistaken about that MIGRATE_HIGHATOMIC part, it seems all sashiko
concerns can be dismissed and then indeed v4 is the better version.
next prev parent reply other threads:[~2026-09-16 11:24 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-04 11:56 Salvatore Dipietro
2026-09-04 14:11 ` Vlastimil Babka (SUSE)
2026-09-04 15:08 ` Zi Yan
2026-09-07 7:30 ` Vlastimil Babka (SUSE)
2026-09-09 2:33 ` Zi Yan
2026-09-09 8:51 ` Vlastimil Babka (SUSE)
2026-09-04 16:10 ` Johannes Weiner
2026-09-06 0:42 ` Andrew Morton
2026-09-06 23:05 ` Dave Chinner
2026-09-10 11:46 ` Salvatore Dipietro
2026-09-10 22:00 ` Andrew Morton
2026-09-11 14:30 ` Salvatore Dipietro
2026-09-11 15:59 ` Johannes Weiner
2026-09-16 11:24 ` Vlastimil Babka (SUSE) [this message]
2026-09-16 15:58 ` Johannes Weiner
2026-09-16 22:34 ` Andrew Morton
2026-09-16 22:35 ` Andrew Morton
2026-09-07 5:54 ` Christoph Hellwig
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=8d6a8a63-4adc-458a-b548-a47bf5ff8eb7@kernel.org \
--to=vbabka@kernel.org \
--cc=abuehaze@amazon.com \
--cc=akpm@linux-foundation.org \
--cc=alisaidi@amazon.com \
--cc=blakgeof@amazon.com \
--cc=brauner@kernel.org \
--cc=brendan.jackman@linux.dev \
--cc=david@redhat.com \
--cc=dgc@kernel.org \
--cc=dipietro.salvatore@gmail.com \
--cc=dipiets@amazon.it \
--cc=djwong@kernel.org \
--cc=hannes@cmpxchg.org \
--cc=hch@infradead.org \
--cc=hch@lst.de \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux-xfs@vger.kernel.org \
--cc=mhocko@suse.com \
--cc=ritesh.list@gmail.com \
--cc=rvvandan@amazon.com \
--cc=stable@vger.kernel.org \
--cc=surenb@google.com \
--cc=willy@infradead.org \
--cc=ziy@nvidia.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
all inboxes | Powered by JetHome®