Re: [PATCH RFC 2/2] mm, page_alloc: fail costly __GFP_NORETRY allocations faster

From: Vlastimil Babka
Date: Wed Dec 17 2025 - 03:58:54 EST


On 12/16/25 21:32, Johannes Weiner wrote:
> On Tue, Dec 16, 2025 at 04:54:22PM +0100, Vlastimil Babka wrote:
>> It might make therefore more sense to just fail unconditionally after
>> the initial compaction attempt, so do that instead. Costly allocations
>> that do want the reclaim/compaction to happen at least once can omit
>> __GFP_NORETRY, or even specify __GFP_RETRY_MAYFAIL for more than one
>> attempt.
>>
>> There is a slight potential unfairness in that costly __GFP_NORETRY
>> allocations that can't perform direct compaction (i.e. lack __GFP_IO)
>> will still be allowed to direct reclaim, while those that can direct
>> compact will now never attempt direct reclaim. However, in cases of
>> memory pressure causing compaction to be skipped due to insufficient
>> base pages, direct reclaim was already not done before, so there should
>> be no functional regressions from this change.
>
> Hm, kind of. There could be enough basepages for compaction_suitable()
> but compaction odds are still higher with more free pages. So there
> might be cases it regresses.
>
> __GFP_NORETRY semantics say it'll try reclaim at least once. We should
> be able to keep that and still simplify, no?
>
>> if (costly_order && (gfp_mask & __GFP_NORETRY)) {
>> - if (gfp_mask & __GFP_THISNODE)
>> - goto nopage;
>> + goto nopage;
>
> IOW, maybe directly select for the NUMA-THP special case here?
>
> /* Optimistic node-local huge page - only compact once */
> if (costly_order &&
> ((gfp_mask & (__GFP_NORETRY|__GFP_THISNODE)) ==
> (__GFP_NORETRY|__GFP_THISNODE)))
> goto nopage;
>
> and then let other __GFP_NORETRY fall through.

I did consider it as an alternative when realizing the potential unfairness
mentioned above, but then went with the simpler code option.
With your suggestion we keep the THP-specific check but at least remove the
arguably illogical compaction feedback.