From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f180.google.com (mail-pl1-f180.google.com [209.85.214.180]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7A4383112BA for ; Mon, 2 Mar 2026 19:18:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.180 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772479116; cv=none; b=qNpWst3qMcKATuD9Lquz5KzvecSPENqLq6/W9pp9sxq9NxPUojyFiJzEFhk6VwDxA3KG6FLn+mYj8CqQXzkoQtYQx+PYbddPB19fM5wdBble1O0eJ9uSQQMALBAJfDpzKg+nCTUVAtidkh4ZJa5+r8sbUECqpMeyXMUW+Fq+7E4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772479116; c=relaxed/simple; bh=WggpwN+Uwg0Wd/vkg2cy2W2g6k3EbBVnAZDA347zRSk=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=luTU/6QDjFNaYVfVizjB4rHFWN6G0o8woOQRolnK56Fs1ZiW/nFK8WZ9VLm+eVVNt5cqlK2QicSxglLAJZzttr854xYT0eM8PPF5yGgT8hxLgnRrmiPOOixEAc6o8n6ImoX0DzIsN6hJXJ6YU1FaEwYeCzz2uUCEDWW/67/5rnY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=V385BnsG; arc=none smtp.client-ip=209.85.214.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="V385BnsG" Received: by mail-pl1-f180.google.com with SMTP id d9443c01a7336-2ae523d54d2so9545ad.1 for ; Mon, 02 Mar 2026 11:18:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1772479113; x=1773083913; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=jtDyJ1DNghVCC4Cyf0GGPlWwN5ZBkZX1JdKXeNO+zdQ=; b=V385BnsG86Y0FWFrlUu56nxur6JYIWRqHnW6grwvaT7qSsvLWzVWcFMAu8/gVpCkxb fWx9GiamF+Z2b9x515fzQZF3xWcl6L4tmLaa26RCW3mW618+4gA5Et8n9qBDNUECwo8V uJm/DON/6RPTX9mxR+1pzMzRuL52lTyc9T+FAKIKSz9fgF5dny9McbbFEKj9jW50MCHv 10OR9KQEb835MV1+kv4W0xNMsUPlLJYtBiS93tGS1RxJGg4JkgR05AuH4ISvH62jTNV5 7r/tAOoRVoI8hawfna2l4Qoirr3CZKsRf4LqrBxhOjm6qUcfYv/3Wz6d0VQvocBZJr0i uUmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772479113; x=1773083913; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=jtDyJ1DNghVCC4Cyf0GGPlWwN5ZBkZX1JdKXeNO+zdQ=; b=uENgpN90ZV9XVrX1CkAsgtIP4f89/1Yy7E7F/J6BsOlBF98tXDiNggT10aZ5b5EymR jwdwpAYDoI2J6LeJeBLpT8ZUGsL6FMXto389VMMw72218UG7TFC1cdeJePkxwonAdIvH FwD3r65qD5IUDlpPaGPCqxkFiK5OOubV+/CFqqM00EqJpFUyRrFN7Q/n0hhkNP8SJCAs h6RlqS+ILBSHFdllY54DFGoUEyHA+tMt5qkCPzqPRBylkK3zSSzlBa1dvXSqZe276PJq ZyLzTvJ1WQDSLNN2roilTynyUNX2Sv8o6DclP62LmN9COKoMaz5fX7II3DHvjo1jRI6J dtmg== X-Forwarded-Encrypted: i=1; AJvYcCUXiYBQH9QRdpPkpU8Y/BBd9ZLllhNxUuBXXCUV/l/UbMb1NdZJG/5xh8xSJpApzpA07jtFiqDJ06/THc0=@vger.kernel.org X-Gm-Message-State: AOJu0YztmGv9qQGl68SO96202h1LpsKkpGr2DpQ6b8MWNDUAeQCDS+vH PkfVa/oZuDjFDg2oz+f2EvUskQRMXl7sRKbRmSvqzWkh2QhxPu1tudD0YZLTa7x+xDEn1wyFLyk acNoraQ== X-Gm-Gg: ATEYQzz+StrSwXVA4ZQ5HHm3U07zik47N2B3/OZZqqPdZghg3c0Rpm+z3WZAjxcTMAP HnYuL1wILms9med5nk19sAoT/HQDsj8TxkhQzaTcTR7Br8yPfVoiQLjbOs/0TuKNXeHeOjmScsT w5VrbmKoJDz8mAhSmZq8+O2OdvklMQU9uXk0mqDuUnalUjlsTxPg+S92lBde9WiKBxRMeqcoK4/ azXbFBZNbOidiilNrKjvJS1Wlp3tyhhweRFDlhNRPzLW9a1QV76p7S2m9B6ICcJ9Gjw6DoxA7xG VVbtR4BEgVlMgGhIzvNMtIlJvqyp/ShYxSG9a/ie/LbqQfVvmJnNId5mNfk3RGcMKimaUedjrEj b79PvL6DD/LjQTbhXFvAdjL2kjqNM+viyxxthFnbdZ5xErA5cLG+jwEoCqb7zCozOoIIZ11slWc kA3aVZVZEf+iOEAw3tbxoJ9pQ2hOMmn9A0BuJsCt6bWPGHwkGpnvezpeLr5kA3Xv6p69QiwceWp u4= X-Received: by 2002:a17:902:c94d:b0:2ae:57e6:616a with SMTP id d9443c01a7336-2ae57e66a09mr2293425ad.2.1772479112254; Mon, 02 Mar 2026 11:18:32 -0800 (PST) Received: from google.com (206.238.125.34.bc.googleusercontent.com. [34.125.238.206]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2adfb5b48f4sm146719015ad.13.2026.03.02.11.18.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Mar 2026 11:18:31 -0800 (PST) Date: Mon, 2 Mar 2026 19:18:26 +0000 From: Bing Jiao To: "David Hildenbrand (Arm)" Cc: linux-mm@kvack.org, Andrew Morton , Johannes Weiner , Michal Hocko , Qi Zheng , Shakeel Butt , Lorenzo Stoakes , Axel Rasmussen , Yuanchu Xie , Wei Xu , linux-kernel@vger.kernel.org Subject: Re: [PATCH] mm/vmscan: restore allowed mask in alloc_demote_folio() Message-ID: References: <20260302070351.3465439-1-bingjiao@google.com> <98480065-e988-477f-ba37-f9521e4aecbb@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <98480065-e988-477f-ba37-f9521e4aecbb@kernel.org> On Mon, Mar 02, 2026 at 09:00:07AM +0100, David Hildenbrand (Arm) wrote: > On 3/2/26 08:03, Bing Jiao wrote: > > In alloc_demote_folio(), mtc->nmask is set to NULL for the first > > allocation. If that succeeds, it returns without restoring mtc->nmask > > to allowed_mask. For subsequent allocations from the migrate_pages() > > batch, mtc->nmask will be NULL. If the target node then becomes full, > > the fallback allocation will use nmask = NULL, allocating from any > > node allowed by the task cpuset, which for kswapd is all nodes. > > > > To address this issue, restore the mtc->nmask to its original allowed > > nodemask after the first allocation. > > > > That would be > > Fixes: 320080272892 ("mm/demotion: demote pages according to allocation fallback order") > > ? Thanks for pointing it out. Will add it in the new patch. > > Signed-off-by: Bing Jiao > > --- > > mm/vmscan.c | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > diff --git a/mm/vmscan.c b/mm/vmscan.c > > index cbffc0a27824..b42abd17aee7 100644 > > --- a/mm/vmscan.c > > +++ b/mm/vmscan.c > > @@ -985,11 +985,11 @@ static struct folio *alloc_demote_folio(struct folio *src, > > mtc->nmask = NULL; > > mtc->gfp_mask |= __GFP_THISNODE; > > dst = alloc_migration_target(src, (unsigned long)mtc); > > + mtc->nmask = allowed_mask; > > if (dst) > > return dst; > > > > mtc->gfp_mask &= ~__GFP_THISNODE; > > - mtc->nmask = allowed_mask; > > > > return alloc_migration_target(src, (unsigned long)mtc); > > } > > -- > > 2.53.0.473.g4a7958ca14-goog > > > > Maybe we should just not touch the original mtc? > > diff --git a/mm/vmscan.c b/mm/vmscan.c > index de62225b381a..f07716e5389e 100644 > --- a/mm/vmscan.c > +++ b/mm/vmscan.c > @@ -985,9 +985,9 @@ static void folio_check_dirty_writeback(struct folio *folio, > static struct folio *alloc_demote_folio(struct folio *src, > unsigned long private) > { > + struct migration_target_control *mtc, target_nid_mtc; > struct folio *dst; > nodemask_t *allowed_mask; > - struct migration_target_control *mtc; > > mtc = (struct migration_target_control *)private; > > @@ -1001,15 +1001,12 @@ static struct folio *alloc_demote_folio(struct folio *src, > * a demotion of cold pages from the target memtier. This can result > * in the kernel placing hot pages in slower(lower) memory tiers. > */ > - mtc->nmask = NULL; > - mtc->gfp_mask |= __GFP_THISNODE; > - dst = alloc_migration_target(src, (unsigned long)mtc); > + target_nid_mtc = *mtc; > + target_nid_mtc.nmask = NULL; > + target_nid_mtc.gfp_mask |= __GFP_THISNODE; > + dst = alloc_migration_target(src, (unsigned long)&target_nid_mtc); > if (dst) > return dst; > - > - mtc->gfp_mask &= ~__GFP_THISNODE; > - mtc->nmask = allowed_mask; > - > return alloc_migration_target(src, (unsigned long)mtc); > } > > > > -- > Cheers, > > David Thank you for the suggestion, David. I agree that not touching the original mtc is a better. It makes the distinction between the two allocation attempts much clearer and avoids the side-effect bug. Will update it then. Best, Bing