From nobody Mon Jun 8 21:46:47 2026 Received: from out162-62-57-49.mail.qq.com (out162-62-57-49.mail.qq.com [162.62.57.49]) (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 597833D9DB2 for ; Tue, 26 May 2026 12:26:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=162.62.57.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779798374; cv=none; b=jcG1grNkJl4lQFsGeoRFttwjUSRRqxnXcvKsYdqiJZ0YcHJOwkanzkIWeAEbrq5x4Ganri3o7olVyL5RhFrlHVVFbB9H7mWAaKY+i3fYeutsaper8b9VjRyFlR2eLSA2Xk4m2YeMTz9IIietTnRf1B9mL/VQTgreDw3xTMBUgZ8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779798374; c=relaxed/simple; bh=bcD01gayVjPMsff1XHSnMwLagNPRM/r5+6PEL3jAngw=; h=Message-ID:From:To:Cc:Subject:Date:MIME-Version; b=VUtqI1UACYMhcPhix6xbgcj4L8qzj8MtmCUObewXFncFO7pxBLHmyl/hgIXQpVN47MmtlC60UQykwhX/WmjK7w5RVFWO6w73WHjU8cSDhEYvd68y7Jut4VDSmICqSxiyeJ5ePgTVXAmpmE1m8JHjUNxpeVeNSo/WSp4NLKL7vL4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=qq.com; spf=pass smtp.mailfrom=qq.com; dkim=pass (1024-bit key) header.d=qq.com header.i=@qq.com header.b=DSDfvx85; arc=none smtp.client-ip=162.62.57.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=qq.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=qq.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=qq.com header.i=@qq.com header.b="DSDfvx85" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qq.com; s=s201512; t=1779798361; bh=uLM7/NlopyOMxo2181Ezg67uHn3G3gEhhqZIJrXI3j8=; h=From:To:Cc:Subject:Date; b=DSDfvx858yg9jrQnaKFQC2zo/vKt6jgWonlLe1ATuYNMm86wuLARvDCVS1fw4JXED yjq1RotRmlQY35fFmGA9GMwNmNLMr7idl87K/hU109T67TX3eDlUndMBXF8cwQTGyn W/btznbYe45ydhJHK6uXqTMYZO5rR8DoC2pA1/VE= Received: from node68.. ([166.111.236.25]) by newxmesmtplogicsvrszb43-0.qq.com (NewEsmtp) with SMTP id 5A9A9C49; Tue, 26 May 2026 20:22:41 +0800 X-QQ-mid: xmsmtpt1779798161t1d4m5qgl Message-ID: X-QQ-XMAILINFO: N9lasXYeZMXW3yzfmkc4S95cmtDONwRrGXy7pxZoIOlHv2m5QUm1v/pKsxH3jh P9cFmdRsBtHJGp5jf+MCQVm3pzY0FW6mOmd6pMkNcU6meOMRPRNm5jjaXYQ/+kLmu/Ly/+JZAOB0 n9XLxBLeXSHkhAauXhPQTiyO0awxRxxG7U1pAU2C1rpjFMIvS2OTKAAtI3h9JnB6LwrTFV3ZcIg+ 6d74K9wGSuismigEBmT5RAGPUnPXw7Bk+kvN5OF2HNTDo5W0BO2SwfzQ2en6xqN2x5VMVLcYmi04 dS8FdhPhi6Dh4DjdpMvdQd6urAadNtbpL3+6SAf8asePWFVSZzI+41PhZOAmKzqrx346+KX5oqG5 5FYnJ0/W+os0QdpYv8VNY1e7RYtvBgaUQt3m80KogU2cIvkFoVQyMd+R2F2Wp2jAu0eZqh58KV/Q fGHWUttqxp8bWABoWZPrivaHpQ/6eViz6C5UGeKkTcqtbgufhyRlKoFyC627tLDjnt4NaLsKr905 OUKPh3LJVC6HGPNlxpuR/7sVTDjnbiDsLNOo0jYpbA8gbwA4Iww/zB7bZfpgJgjxLVmfKpTRqq00 8oiVjnqypFtPXH9WtEEJycSv7i/UBAbSbLNCLQQriK6soIj6qZUDemuvTB9ceNQECw6u8HHnEvBV IoAw27byIBTJxQpR4JD3J8LCex4nYpcmp/tbI9PaQd8Fxug+vH6o/plpravufCMPkcJdLcI14ctO WXfmtQkY/QvfUtAsUVvHk2KTzWxxkej7+uQxDQiJElc5DJaO29pKLWG/7z0JjDA46pxB2dFi6O8r RPSPbz3Re4eJrgvmxrebedZ/a4FaW6h3GrUqj246BPvUVwsfMq+f33M/Y8vKImDXGYxC1CWwz3/t yK0ygVrSJZdPBBbOR4gO5BN2EyJ7XNYQL9jnLjmy/V9mQxTuTkwL9BZvOTg3b2D+2BMx3JnV9jh7 MhlZTS91ca+gQioHWSrEzQHWGrtF7GoyVwDPZX1RRrNWlT0IymbhADrutZC93NOpuZ2U359tQHfZ +bH1Fulfv8N886Msi57mxj29d4Seo= X-QQ-XMRINFO: M/715EihBoGS47X28/vv4NpnfpeBLnr4Qg== From: fujunjie To: Andrew Morton , linux-mm@kvack.org Cc: Vlastimil Babka , Michal Hocko , Suren Baghdasaryan , Brendan Jackman , Johannes Weiner , Zi Yan , linux-kernel@vger.kernel.org Subject: [PATCH] mm/compaction: respect cpusets when checking retry suitability Date: Tue, 26 May 2026 12:22:41 +0000 X-OQ-MSGID: <20260526122241.609248-1-fujunjie1@qq.com> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" should_compact_retry() handles COMPACT_SKIPPED by asking compaction_zonelist_suitable() whether reclaim can make a later compaction attempt worthwhile. That answer is used for the current allocation, so it should follow the same zone eligibility rules as the allocation itself. When cpusets are enabled, allocator slowpath decisions are marked with ALLOC_CPUSET. The allocation path, direct compaction and reclaim retry all skip zones rejected by __cpuset_zone_allowed(). compaction_zonelist_suitable() does not apply that filter. It only walks ac->zonelist/ac->nodemask, so it can return true because a zone that is not usable for the current allocation would pass __compaction_suitable(). That does not let the allocation use the disallowed zone. Later allocation and direct compaction paths still apply cpuset filtering. However, it can make should_compact_retry() retry based on memory that this allocation cannot use. Pass gfp_mask down and apply the same ALLOC_CPUSET check in compaction_zonelist_suitable(). This keeps the retry decision aligned with the zones that the allocation is allowed to use. A temporary debugfs probe was also used to call the old and new compaction_zonelist_suitable() predicates in the same two-node NUMA guest. The task was restricted to mems=3D0 while ac->nodemask covered nodes 0-1. After putting pressure on node0, node0 failed __compaction_suitable() for order-10 and node1 passed it, but node1 was rejected by __cpuset_zone_allowed(). In that state the old predicate returned true and the patched predicate returned false. Signed-off-by: fujunjie Reviewed-by: Vlastimil Babka (SUSE) --- include/linux/compaction.h | 2 +- mm/compaction.c | 6 +++++- mm/page_alloc.c | 15 +++++++++------ 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/include/linux/compaction.h b/include/linux/compaction.h index 173d9c07a895..c829c48d1c71 100644 --- a/include/linux/compaction.h +++ b/include/linux/compaction.h @@ -101,7 +101,7 @@ extern void compaction_defer_reset(struct zone *zone, i= nt order, bool alloc_success); =20 bool compaction_zonelist_suitable(struct alloc_context *ac, int order, - int alloc_flags); + int alloc_flags, gfp_t gfp_mask); =20 extern void __meminit kcompactd_run(int nid); extern void __meminit kcompactd_stop(int nid); diff --git a/mm/compaction.c b/mm/compaction.c index 3648ce22c807..2295b2487dfc 100644 --- a/mm/compaction.c +++ b/mm/compaction.c @@ -2447,7 +2447,7 @@ bool compaction_suitable(struct zone *zone, int order= , unsigned long watermark, =20 /* Used by direct reclaimers */ bool compaction_zonelist_suitable(struct alloc_context *ac, int order, - int alloc_flags) + int alloc_flags, gfp_t gfp_mask) { struct zone *zone; struct zoneref *z; @@ -2460,6 +2460,10 @@ bool compaction_zonelist_suitable(struct alloc_conte= xt *ac, int order, ac->highest_zoneidx, ac->nodemask) { unsigned long available; =20 + if (cpusets_enabled() && (alloc_flags & ALLOC_CPUSET) && + !__cpuset_zone_allowed(zone, gfp_mask)) + continue; + /* * Do not consider all the reclaimable memory because we do not * want to trash just for a single high order allocation which diff --git a/mm/page_alloc.c b/mm/page_alloc.c index ddeb79fa12db..93d56ba339fb 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -4199,7 +4199,8 @@ __alloc_pages_direct_compact(gfp_t gfp_mask, unsigned= int order, } =20 static inline bool -should_compact_retry(struct alloc_context *ac, int order, int alloc_flags, +should_compact_retry(gfp_t gfp_mask, struct alloc_context *ac, int order, + int alloc_flags, enum compact_result compact_result, enum compact_priority *compact_priority, int *compaction_retries) @@ -4221,7 +4222,8 @@ should_compact_retry(struct alloc_context *ac, int or= der, int alloc_flags, * migration targets. Continue if reclaim can help. */ if (compact_result =3D=3D COMPACT_SKIPPED) { - ret =3D compaction_zonelist_suitable(ac, order, alloc_flags); + ret =3D compaction_zonelist_suitable(ac, order, alloc_flags, + gfp_mask); goto out; } =20 @@ -4274,7 +4276,8 @@ __alloc_pages_direct_compact(gfp_t gfp_mask, unsigned= int order, } =20 static inline bool -should_compact_retry(struct alloc_context *ac, int order, int alloc_flags, +should_compact_retry(gfp_t gfp_mask, struct alloc_context *ac, int order, + int alloc_flags, enum compact_result compact_result, enum compact_priority *compact_priority, int *compaction_retries) @@ -4892,9 +4895,9 @@ __alloc_pages_slowpath(gfp_t gfp_mask, unsigned int o= rder, * of free memory (see __compaction_suitable) */ if (did_some_progress > 0 && can_compact && - should_compact_retry(ac, order, alloc_flags, - compact_result, &compact_priority, - &compaction_retries)) + should_compact_retry(gfp_mask, ac, order, alloc_flags, + compact_result, &compact_priority, + &compaction_retries)) goto retry; =20 /* Reclaim/compaction failed to prevent the fallback */ base-commit: e8c2f9fdadee7cbc75134dc463c1e0d856d6e5c7 --=20 2.34.1