Re: [PATCH 2/4] mm: compaction: support non-movable compaction for pageblock requests
From: Vlastimil Babka (SUSE)
Date: Wed Jul 01 2026 - 14:14:32 EST
On 7/1/26 17:28, Johannes Weiner wrote:
> On Wed, Jul 01, 2026 at 04:19:29PM +0200, Vlastimil Babka (SUSE) wrote:
>> On 6/26/26 20:21, Johannes Weiner wrote:
>> > While trying to fix a reclaim storm in defrag_mode, I noticed that
>> > non-movable direct compaction is extremely inefficient.
>> >
>> > When searching for space to evacuate, compaction only allows blocks of
>> > the same type as the incoming request. This is to prevent migratetype
>> > pollution, where a small non-movable request frees space in a movable
>> > block and provokes the allocator to fall back and pollute it.
>> >
>> > This protection is reasonable on one hand, but the downside is that it
>> > makes non-movable direct compaction nearly useless: if we get the type
>> > annotations right, by definition there aren't any movable pages inside
>> > the non-movable blocks it is allowed to scan.
>> >
>> > With defrag_mode, the goal is the production of whole blocks, which
>> > are essentially type neutral: __rmqueue_claim() will convert them
>> > wholesale on alloc. This makes type mixing and pollution a non-issue.
>> >
>> > Fix the pollution gates to take the requested order into account, and
>> > allow whole-block requests to scan blocks of other types.
>> >
>> > The only exception is CMA blocks. That type is sticky and these blocks
>> > cannot be claimed to other types. Continue to be strict with them, and
>> > allow only explicit ALLOC_CMA requests and kcompactd to evacuate them.
>> >
>> > Signed-off-by: Johannes Weiner <hannes@xxxxxxxxxxx>
>>
>> Reviewed-by: Vlastimil Babka (SUSE) <vbabka@xxxxxxxxxx>
>
> Thanks!
>
>> > diff --git a/mm/compaction.c b/mm/compaction.c
>> > index f08765ade014..7df3a85d43af 100644
>> > --- a/mm/compaction.c
>> > +++ b/mm/compaction.c
>> > @@ -1381,12 +1381,33 @@ static bool suitable_migration_source(struct compact_control *cc,
>> > if (pageblock_skip_persistent(page))
>> > return false;
>> >
>> > - if ((cc->mode != MIGRATE_ASYNC) || !cc->direct_compaction)
>> > + /*
>> > + * Background compaction produces blocks for the zone at
>> > + * large, with no particular allocation context. Allow all
>> > + * block types, including CMA.
>> > + */
>> > + if (!cc->direct_compaction)
>> > return true;
>> >
>> > block_mt = get_pageblock_migratetype(page);
>> >
>> > - if (cc->migratetype == MIGRATE_MOVABLE)
>> > + /*
>> > + * CMA pages can only be taken by ALLOC_CMA requests. For anybody
>> > + * else, vacating a CMA block consumes free pages the caller
>> > + * could have used, and produces free pages it cannot.
>> > + */
>> > + if (is_migrate_cma(block_mt) && !(cc->alloc_flags & ALLOC_CMA))
>> > + return false;
>> > +
>> > + if (cc->mode != MIGRATE_ASYNC)
>> > + return true;
>>
>> This now stands out as uncommented. Can we come up with a rationale? :)
>
> Let's see. Originally it came from here:
>
> commit 9927af740b1b9b1e769310bd0b91425e8047b803
> Author: Mel Gorman <mel@xxxxxxxxx>
> Date: Thu Jan 13 15:45:59 2011 -0800
>
> mm: compaction: perform a faster migration scan when migrating asynchronously
>
> This limited async scanners to movable blocks. By keeping them to the
> most productive space, it keeps their latencies down.
>
> But then there was a follow up here:
>
> commit 282722b0d258ec23fc79d80165418fee83f01736
> Author: Vlastimil Babka <vbabka@xxxxxxxxxx>
> Date: Mon May 8 15:54:49 2017 -0700
>
> mm, compaction: restrict async compaction to pageblocks of same migratetype
Aha :)
> This made the migratetype filtering about preventing block
> pollution. The patch quotes reduced extfrag numbers.
>
> So now we have a block pollution guard that we apply only if... the
> scanner is latency sensitive? :) Is this actually desired behavior?
Yeah indeed I was wondering in this direction.
> Another way of looking at it would be this:
>
> /*
> * Allocation fallbacks can spread migratable pages
> * into non-movable blocks.
But also vice versa, non-movable pages into movable blocks? (without
defrag_mode?).
> This is high-effort,
> * low-result work. Restrict it to sync scans.
> */
Works for me.