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 B938BC369AB for ; Mon, 21 Apr 2025 20:28:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 73A0C6B000C; Mon, 21 Apr 2025 16:28:41 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6C1E86B000D; Mon, 21 Apr 2025 16:28:41 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 560466B000E; Mon, 21 Apr 2025 16:28:41 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 3587B6B000C for ; Mon, 21 Apr 2025 16:28:41 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 2A249BF463 for ; Mon, 21 Apr 2025 20:28:42 +0000 (UTC) X-FDA: 83359189284.24.CC6F8D0 Received: from mail-qt1-f178.google.com (mail-qt1-f178.google.com [209.85.160.178]) by imf29.hostedemail.com (Postfix) with ESMTP id 4A087120003 for ; Mon, 21 Apr 2025 20:28:40 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b="jmOy27/n"; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf29.hostedemail.com: domain of surenb@google.com designates 209.85.160.178 as permitted sender) smtp.mailfrom=surenb@google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1745267320; a=rsa-sha256; cv=none; b=yvpRVYkjhaZwaajM3sYuuIFMJkePkxLU8ABR6CzBqsC7dFqThgf4hGjXrRJ5etirvTbOvo wkYea7wmn6QFNmT+3CmSmg4ak8j0G9o1bzCwH7zvyxQZVAXjTNJkeGBpMs8O5LkA0TAyuc WBz85hXo27jd0LeW70eB72cxaBGamdc= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b="jmOy27/n"; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf29.hostedemail.com: domain of surenb@google.com designates 209.85.160.178 as permitted sender) smtp.mailfrom=surenb@google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1745267320; 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:dkim-signature; bh=vAh5KnPVbnTCxFdYE9r8rfJKB6a6HWJ1fuiZEddcuQU=; b=wsJG/O7mMt/Y+GmCQ3Ho+fCXe4JINKyYwuj0LBvKXYEG1NoMiHBcCLkvJcP7PrgUzVh4+x xTNazWtblZIqgMoqgNeJaV5oektFxBq+DD3gUHqCvqhz6D7gq3TXwYjsyScMelhGvIwS2V keu6EPKvtCG6XfrWMPKWqzKpK++n3b4= Received: by mail-qt1-f178.google.com with SMTP id d75a77b69052e-4769e30af66so1377261cf.1 for ; Mon, 21 Apr 2025 13:28:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1745267319; x=1745872119; darn=kvack.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=vAh5KnPVbnTCxFdYE9r8rfJKB6a6HWJ1fuiZEddcuQU=; b=jmOy27/nVHEsgCsu3k92VIY2J8vd3LiSgmphu/88k6mffkRvDo5SFaROsigdMS+fbw gzqgJq7tAhXqjUXhvirH2QgLZjTAqPgga8gaRi/7AN3szzaFv/hAQw0DeLf19cfd7HbB vqC5cB22CuMFGkKimoJW9cbQce+mTBexy4rF+N26vIhh/0dKBJP0DDqZueVln32zRJ7v WhKHOB2rx/vRpYod4l4oeI6EAcP924FgSSJ0XzwPgQmMhBVb4MvpeHtYYuVy3DVGglDL GQ/CzDjcPhj7lnpAzSCRHUZfbFjDJ8x05q+3Zi6EAt2ry4St5oSXRPbovcl+k1G8jTMd XpWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745267319; x=1745872119; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=vAh5KnPVbnTCxFdYE9r8rfJKB6a6HWJ1fuiZEddcuQU=; b=PiEOAMQITDPO+RCCw/ZiYw5BZ0/IhRkTkZjouDFsBU8Ezxf0BIMgj1bIR7iOscCdcX MJSuriZOUw/ihCVceSMbMr9sgjIyW/BdeKDQuzkZue9NKNyv6yTH7Mqh/4HTeWH1NCky 1P+wkQ1do6y9P8elWBsGgCEdUx1RNFl8hsCcbhVtiQ7tSrOJe1s/HiIpmNYZKMHCI42N 5jeJl6Dk5Ihb+t2eY7jaC0ONBaGQKdIiFadi6NSVdOoflqKrFbdZeCjeiOJqgzxkzE+x t8qLR+3x+vw6obGqY/bM3SC2DhGc64HwULWZbjwIqZHT0JLBray/N+vVWZj1wTQdLCWb AU6w== X-Forwarded-Encrypted: i=1; AJvYcCUNe0dFG7SMcybZp9/ATJK0tBR997VZdtDbCDovdseWLbeEVicnRVXcgAWVu/cX6AAzjAy5v2xkCA==@kvack.org X-Gm-Message-State: AOJu0YxKk3+JlnX4iBWnD9wa94OUMvkSCyCx1Ej+CfqTDqTVz9+ijFp+ C1bYWXUA3cN/sZpbKoA4XpwsWkCMoIszB0f/85+MGS6e5to2KP3NzuRx7ylnXUvAL+zVGcFr8du GVMbrZtOlTjS12bFTywVAP143sWNc3TTI+cnj X-Gm-Gg: ASbGnctfYQJ20hzp+pApqrG6A+oNp8vJLmwKUlRF591WC07mE5fDx4cjDXDtgLwaEfA hpJtrgBrAAu8PM/+F+jvAVtE/LXjKbU0M/h+VkOw+TKiGu8FZnbonDwFwNtIPCyfyGDRnXLOI50 Ls/h+qkVPDkTEckXz2AcBM X-Google-Smtp-Source: AGHT+IGKnE2CIBvT+fJdgDDbnrOGCsN9elt+h8uaJ3CxRx8HwLHVmG+as9HEI4lJpad7auuLPovlZ4a8MNRr3oL9OoY= X-Received: by 2002:ac8:1304:0:b0:47b:4be:8572 with SMTP id d75a77b69052e-47b04be86dbmr5883011cf.18.1745267319186; Mon, 21 Apr 2025 13:28:39 -0700 (PDT) MIME-Version: 1.0 References: <20250416082405.20988-1-zhangtianyang@loongson.cn> In-Reply-To: From: Suren Baghdasaryan Date: Mon, 21 Apr 2025 13:28:28 -0700 X-Gm-Features: ATxdqUFZ0mfZx8F5w1Q3I-1gslA_ZYU57nOssRIGO90YafrqVQ_j_evO36xBIiI Message-ID: Subject: Re: [PATCH] mm/page_alloc.c: Avoid infinite retries caused by cpuset race To: Harry Yoo Cc: Tianyang Zhang , akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Vlastimil Babka , Michal Hocko , Brendan Jackman , Johannes Weiner , Zi Yan Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 4A087120003 X-Stat-Signature: u8qm31ccng9fxco4poqpys6pz948oczb X-Rspam-User: X-HE-Tag: 1745267320-528260 X-HE-Meta: U2FsdGVkX1+sMk0dyrvO1prcwbeAAJG5adHTFDrs7k2XEaDe4s5vkvbifu09MvUrYaXq3TbnZ4dVSo38ZH/QfzS/RGqdLfXbJTLY2N9OgPTnI+SUGnl9mCEydvuJhlrL6K/RjtjzTAe52EL1CtaAlMbGHhHYsSBmDekwpgnIcueHtSmf/bgO0KvnSNz0YJtuw013YqnJPNvO1oMm6OKsN6CWP+6PmBNpt51k8xYXTkltZMDFUCiX//sG6iM6yY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ofilter, 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: On Mon, Apr 21, 2025 at 3:00=E2=80=AFAM Harry Yoo wr= ote: > > 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 =3D 0x1, ac->preferred->zone->nid =3D 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 =3D 0x3, ac->preferred->zone->nid =3D 1 */ > > if (should_reclaim_retry(gfp_mask, order, ac, alloc_flags, > > did_some_progress > 0, &no_progress_lo= ops)) > > 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"). > > 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. > > /* Ensure kswapd doesn't accidentally go to sleep as long as we l= oop */ > > if (alloc_flags & ALLOC_KSWAPD) > > wake_all_kswapds(order, gfp_mask, ac); > > -- > > 2.20.1 > > > >