From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D3B1434678C for ; Wed, 1 Jul 2026 18:14:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782929651; cv=none; b=XnYpKw5hGTy1GniiLovRwopZFWNkCahV5XxHxUcxSxkRbKsDPKfqcobiCfGUVGGBCYVkD2DU3UQSRnwB90Q0gzdubjyhjfZHMwKCE/HxVMTRqtqsUP+gs0MhXzKZ9OsO6FsJX3dn60J1XQHwKYS3oft+6OsZu0e40semlbADN18= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782929651; c=relaxed/simple; bh=OBV5ArzalF3XPTGGO2vGslSh4bq4RFbAY7fwho4Cgpw=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=AyupMR0AK79V0HXOG39c+RlEdGuqv5uBs/GcPgA2zBu/5EmpG1gjptxMtkpr1+maZlKjlPZoYcmUVtOLRE7/nJuz+aMO/L4fpGq0Ig0J8/QqKj8MTYUJ4zX77yTQU4BDLZZyJfEFWFVLeU9QIszywV4f8EtFHwKGyPG4kr1bpNQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=o0A4txTL; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="o0A4txTL" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 747CD1F000E9; Wed, 1 Jul 2026 18:14:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1782929648; bh=PD5z0B3KLuf6QAzSmxugLBPawi7CkWU61EppSSVzf20=; h=Date:Subject:To:Cc:References:From:In-Reply-To; b=o0A4txTLWUptFpeU/Mi/BSpuDwvTNfldwpIE0TgrDcVds8g2WEZSvOpqN79Bj6sM7 MiLa10CAFyo5XQs5YFP7qj3yEr993E93vOH5j9XG1oDhdpvtskD3+WpW4PdOthV405 c6Nh+LhhVwMCiX2nr6J9mSNQapr+We1913hqbqEzLJyEFJ+PO42yv62MPP4gXIqAkI kRugLLa+JS8uo00oe6fQ2C44xoUkkaczdGmkM44VrdfqpNK9KpG1Ukue27iFZvRNIp SjuqYpm3ozd+EpwkuPwC1wG9/tlGQAHHszpp7PSJhafVckY+ppJdfafOnESkohjRpQ 09eQC530kPvpw== Message-ID: Date: Wed, 1 Jul 2026 20:14:05 +0200 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 2/4] mm: compaction: support non-movable compaction for pageblock requests Content-Language: en-US To: Johannes Weiner Cc: Andrew Morton , Suren Baghdasaryan , Michal Hocko , Brendan Jackman , Zi Yan , David Hildenbrand , Lorenzo Stoakes , "Liam R. Howlett" , Mike Rapoport , linux-mm@kvack.org, linux-kernel@vger.kernel.org References: <20260626182215.1107966-1-hannes@cmpxchg.org> <20260626182215.1107966-3-hannes@cmpxchg.org> From: "Vlastimil Babka (SUSE)" Autocrypt: addr=vbabka@kernel.org; keydata= xsFNBFZdmxYBEADsw/SiUSjB0dM+vSh95UkgcHjzEVBlby/Fg+g42O7LAEkCYXi/vvq31JTB KxRWDHX0R2tgpFDXHnzZcQywawu8eSq0LxzxFNYMvtB7sV1pxYwej2qx9B75qW2plBs+7+YB 87tMFA+u+L4Z5xAzIimfLD5EKC56kJ1CsXlM8S/LHcmdD9Ctkn3trYDNnat0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O8AOz/58j6O 2RHNy/mZEN+7tJ5Tsq42zVJ4jxsT8b9YplavCMsnBgDeRWhcbYhCyttoL7nYISyWg4kQYZ/P wIV3OuNv2f8iKYsxNsRuClOAF82+gvqOy1/1pprFjy8uo2pkoOrb63aOP3vO5VHnRKgra6dq NcaZ+c6J4H+nEJGi2SkHAUJz5oBzuThvPudLvPA/SK8sKoM01IRxSihev/S/5WLazXB1PGem OCbvzC1IjWJJraxiDJ5IygokapUa2RP7+WBR22skQ3SSl6G107QgWKSyTOGWEaRmV53vxQLV jXuCmzSSasTL60zq5yGrT4/DYQVSNEUiUbG4pYekxJujNeEDkUlky0Y= In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit 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 >> >> Reviewed-by: Vlastimil Babka (SUSE) > > 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 > 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 > 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.