From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id B2A89C369C2 for ; Wed, 23 Apr 2025 02:39:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 11A5C6B0005; Tue, 22 Apr 2025 22:39:27 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0A3DB6B0007; Tue, 22 Apr 2025 22:39:27 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E5E9A6B0008; Tue, 22 Apr 2025 22:39:26 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id C52AA6B0005 for ; Tue, 22 Apr 2025 22:39:26 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 36154BE0FF for ; Wed, 23 Apr 2025 02:39:27 +0000 (UTC) X-FDA: 83363752374.14.DE876BF Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by imf14.hostedemail.com (Postfix) with ESMTP id 5CE88100007 for ; Wed, 23 Apr 2025 02:39:23 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf14.hostedemail.com: domain of zhangtianyang@loongson.cn designates 114.242.206.163 as permitted sender) smtp.mailfrom=zhangtianyang@loongson.cn ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1745375965; a=rsa-sha256; cv=none; b=sFsR1Uso+mZI94hBclSymXsVu8/Z7RS/zlqGH3xmnDte3jxwDN4bOaqtu8OWoB03QdX/V0 o4zfx/gv8YXPN3NqOSMRegw5Ng18YCRp0uhXzYXHbPWS3hNwR8kq3udZjWuNfE8aRZQBok 3kkXfqChJ76rWszurPT2Spa0Cq+j7kE= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf14.hostedemail.com: domain of zhangtianyang@loongson.cn designates 114.242.206.163 as permitted sender) smtp.mailfrom=zhangtianyang@loongson.cn ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1745375965; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=i3fFI7RL4R/iMAnkr+OgFDPrsB/MpzkoOnP6QBD2/1E=; b=Ls4yJQLjqhy9HIQBHYEK3HnWz8cn8WejLyUZamMN/wJsU5/trQpLITkUcWLGKCPSXbKMDA Rh7DhkXIKA9y2mIH0K91/8FGXYuDwgHqjxLslV8uYg5AX54KrulLmQaewXl2azNvRTg8at q8w45gtQsK6a7liLQRfgMLgHnhxc910= Received: from loongson.cn (unknown [10.20.42.24]) by gateway (Coremail) with SMTP id _____8AxquDQUghoKWbEAA--.21518S3; Wed, 23 Apr 2025 10:39:13 +0800 (CST) Received: from [10.20.42.24] (unknown [10.20.42.24]) by front1 (Coremail) with SMTP id qMiowMAxj8XHUghoTPyQAA--.35520S3; Wed, 23 Apr 2025 10:39:05 +0800 (CST) Subject: Re: [PATCH] mm/page_alloc.c: Avoid infinite retries caused by cpuset race To: Suren Baghdasaryan , Harry Yoo Cc: akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Vlastimil Babka , Michal Hocko , Brendan Jackman , Johannes Weiner , Zi Yan References: <20250416082405.20988-1-zhangtianyang@loongson.cn> From: Tianyang Zhang Message-ID: Date: Wed, 23 Apr 2025 10:38:26 +0800 User-Agent: Mozilla/5.0 (X11; Linux mips64; rv:68.0) Gecko/20100101 Thunderbird/68.7.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US X-CM-TRANSID:qMiowMAxj8XHUghoTPyQAA--.35520S3 X-CM-SenderInfo: x2kd0wxwld05hdqjqz5rrqw2lrqou0/ X-Coremail-Antispam: 1Uk129KBj93XoWxAF4DZFWkZry5XF1fuw1rAFc_yoWrAF13pF WxuF1jkws5AF1UCws7tw1kuFy0v3srtFW3JFyUGryxZwnIkryxKr1jkrWa9Fy8Zrs8AF1j qr4YyayxZFZ8AagCm3ZEXasCq-sJn29KB7ZKAUJUUUU5529EdanIXcx71UUUUU7KY7ZEXa sCq-sGcSsGvfJ3Ic02F40EFcxC0VAKzVAqx4xG6I80ebIjqfuFe4nvWSU5nxnvy29KBjDU 0xBIdaVrnRJUUUvjb4IE77IF4wAFF20E14v26r1j6r4UM7CY07I20VC2zVCF04k26cxKx2 IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48v e4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Gr0_Xr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI 0_Gr0_Cr1l84ACjcxK6I8E87Iv67AKxVW0oVCq3wA2z4x0Y4vEx4A2jsIEc7CjxVAFwI0_ GcCE3s1le2I262IYc4CY6c8Ij28IcVAaY2xG8wAqjxCEc2xF0cIa020Ex4CE44I27wAqx4 xG64xvF2IEw4CE5I8CrVC2j2WlYx0E2Ix0cI8IcVAFwI0_Jrv_JF1lYx0Ex4A2jsIE14v2 6r1j6r4UMcvjeVCFs4IE7xkEbVWUJVW8JwACjcxG0xvEwIxGrwCYjI0SjxkI62AI1cAE67 vIY487MxAIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4AY6r1j6r4UMI8I3I0E5I8CrVAF wI0_Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE17CEb7AF67AKxVWUtVW8ZwCIc4 0Y0x0E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m6Fr+wrLj+4MLzKLYOsY1qVsbYg2v15FMJ5jUTQfHEio0O36lb+AJsXs3I+0wSIRt9DifuWJ1eBdX+AHPXFOozYGbBfJbGcCkkB0d7s+T0vW3vkzErxM39aG8spXHJqEwW5I7WRN8Hzes1MFgggueYMidGwUoccQGd9ploytaIYI4uKcXeFOpAdY+9TqjabwGnm97NbtpbiKxTbxK97CrOeQ6HCgE+O n2R1vydX 3wpFA7alAL6KkECVBdxgARz6UShR82XxyLZKALgR6SK7rmw+tDKSfrJ0RdeapXlMXOawCkgXrI9j8Vr0gvmtQ1Uo7soKXGcUFhL47bJH1ooS7Y9yzkh+67mGKymYs5lT9BDba2xKzXOo+iglrJrgiESgJIet72NWDcADA8+3zkxLKH5u/uTeE9Po+btqTM2FYDfmR+8vdGOf75k8= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Hi, Suren 在 2025/4/22 上午4:28, Suren Baghdasaryan 写道: > On Mon, Apr 21, 2025 at 3:00 AM Harry Yoo wrote: >> On Wed, Apr 16, 2025 at 04:24:05PM +0800, Tianyang Zhang wrote: >>> __alloc_pages_slowpath has no change detection for ac->nodemask >>> in the part of retry path, while cpuset can modify it in parallel. >>> For some processes that set mempolicy as MPOL_BIND, this results >>> ac->nodemask changes, and then the should_reclaim_retry will >>> judge based on the latest nodemask and jump to retry, while the >>> get_page_from_freelist only traverses the zonelist from >>> ac->preferred_zoneref, which selected by a expired nodemask >>> and may cause infinite retries in some cases >>> >>> cpu 64: >>> __alloc_pages_slowpath { >>> /* ..... */ >>> retry: >>> /* ac->nodemask = 0x1, ac->preferred->zone->nid = 1 */ >>> if (alloc_flags & ALLOC_KSWAPD) >>> wake_all_kswapds(order, gfp_mask, ac); >>> /* cpu 1: >>> cpuset_write_resmask >>> update_nodemask >>> update_nodemasks_hier >>> update_tasks_nodemask >>> mpol_rebind_task >>> mpol_rebind_policy >>> mpol_rebind_nodemask >>> // mempolicy->nodes has been modified, >>> // which ac->nodemask point to >>> >>> */ >>> /* ac->nodemask = 0x3, ac->preferred->zone->nid = 1 */ >>> if (should_reclaim_retry(gfp_mask, order, ac, alloc_flags, >>> did_some_progress > 0, &no_progress_loops)) >>> goto retry; >>> } >>> >>> Simultaneously starting multiple cpuset01 from LTP can quickly >>> reproduce this issue on a multi node server when the maximum >>> memory pressure is reached and the swap is enabled >>> >>> Signed-off-by: Tianyang Zhang >>> --- >> What commit does it fix and should it be backported to -stable? > I think it fixes 902b62810a57 ("mm, page_alloc: fix more premature OOM > due to race with cpuset update"). I think this issue is unlikely to have been introduced by Patch 902b62810a57 , as the infinite-reties section from https://elixir.bootlin.com/linux/v6.15-rc3/source/mm/page_alloc.c#L4568 to https://elixir.bootlin.com/linux/v6.15-rc3/source/mm/page_alloc.c#L4628 where the cpuset race condition occurs remains unmodified in the logic of Patch 902b62810a57. >> There's a new 'MEMORY MANAGEMENT - PAGE ALLOCATOR' entry (only in >> Andrew's mm.git repository now). >> >> Let's Cc the page allocator folks here! >> >> -- >> Cheers, >> Harry / Hyeonggon >> >>> mm/page_alloc.c | 8 ++++++++ >>> 1 file changed, 8 insertions(+) >>> >>> diff --git a/mm/page_alloc.c b/mm/page_alloc.c >>> index fd6b865cb1ab..1e82f5214a42 100644 >>> --- a/mm/page_alloc.c >>> +++ b/mm/page_alloc.c >>> @@ -4530,6 +4530,14 @@ __alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order, >>> } >>> >>> retry: >>> + /* >>> + * Deal with possible cpuset update races or zonelist updates to avoid >>> + * infinite retries. >>> + */ >>> + if (check_retry_cpuset(cpuset_mems_cookie, ac) || >>> + check_retry_zonelist(zonelist_iter_cookie)) >>> + goto restart; >>> + > We have this check later in this block: > https://elixir.bootlin.com/linux/v6.15-rc3/source/mm/page_alloc.c#L4652, > so IIUC you effectively are moving it to be called before > should_reclaim_retry(). If so, I think you should remove the old one > (the one I linked earlier) as it seems to be unnecessary duplication > at this point. In my understanding, the code in https://elixir.bootlin.com/linux/v6.15-rc3/source/mm/page_alloc.c#L4652 was introduced to prevent unnecessary OOM (Out-of-Memory) conditions in__alloc_pages_may_oom. If old code is removed, the newly added code (on retry loop entry) cannot guarantee that the cpuset remains valid when the flow reaches in__alloc_pages_may_oom, especially if scheduling occurs during this section. Therefore, I think retaining the original code logic is necessary to ensure correctness under concurrency. > > >>> /* Ensure kswapd doesn't accidentally go to sleep as long as we loop */ >>> if (alloc_flags & ALLOC_KSWAPD) >>> wake_all_kswapds(order, gfp_mask, ac); >>> -- >>> 2.20.1 >>> >>> Thanks