From nobody Mon Feb 9 02:11:42 2026 Received: from mail-dy1-f202.google.com (mail-dy1-f202.google.com [74.125.82.202]) (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 D3CB5284671 for ; Wed, 7 Jan 2026 07:28:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767770923; cv=none; b=LvG728xvp+hVS9pwDT+EJ9b4Uii6kZEtQRdvl48BQ2P5I78FrqgghNPu9l0lW/5y/SZxczuRRVSzQYL1cviGuDu5qp6+/SF4A0AEXwkEG0xb28PdqZYjEUi8lK7TNkpHrJAsGIZQix5veLINNhqQOn5sHQavJVlhKhh2M6LJc60= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767770923; c=relaxed/simple; bh=2jRjAUjtQ0v2J5QFOCTKBFTZqbqFgad4K8hO3V3bvuE=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=NiKgyhi8WfCiyp0Ujpa/Z7VrYubzCotv5u7r3H4ppbXFmpn9Lw429yyMnV8SFklzmFHSvbJw3CJ2rFRY4vduHr9Uriqy108oR0Ge2ofXPk22jadtGyCZdV3L2UwAYqiwxSt23svXJXcbLqL+GLbPokxlBd6onn7LetB8QNZiM2Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--bingjiao.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=ExjxjgbQ; arc=none smtp.client-ip=74.125.82.202 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=flex--bingjiao.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="ExjxjgbQ" Received: by mail-dy1-f202.google.com with SMTP id 5a478bee46e88-2ac363a9465so949520eec.0 for ; Tue, 06 Jan 2026 23:28:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1767770921; x=1768375721; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=tVVdYtQjw2TjeADeQ9BPsRLaeco/a1loIhNj19y7Cbk=; b=ExjxjgbQ3jg/73kpFZo5QK1Lg2+W9cIPEvH2c+tnS2CkGHyWOOgQyQBYzR8tscuDtf vDrajNfDbzp6rYulZ5Nn3JNPMJbRJr9OuZ+dyXkA8qKf7VxoxrGxEkx+3f+0ofVpo3Ht QQfsY/7o2D5u/63up53Y9dv6sxChoNySGJOKqnbp7HJ//nnG0fvizeh4SiG2dMlGNzQn 1e7Fazf8Ar1cWjOSCqCzOJTLoiy2Qil2NUAR3Yh8p1I/qp6uBevbVB9I2hGMK2on1nyI TSXqf1cqWvEbNdqaMZbdlQtNozOR/qig5OZOCFehSt2Wye7knEFK8MMZfniNJpMrwFPp 5mFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767770921; x=1768375721; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=tVVdYtQjw2TjeADeQ9BPsRLaeco/a1loIhNj19y7Cbk=; b=rHvc1Rt5GSUJdLqCoQZq+lg6SDSAyqTWRaUmxKrCJ12u1qA+D7B/aVeVhsQ6LdMkYv quqvKfz4zcH575qRB/0lRJU5J3HXcXyk/zOatudtRPTIWBNmZ3LjLYLSNtanHEreKH9o 7MFoQsJdFpIBLPw16J66pF/DCAFnqrCSt8vW9TDWIXlcBAxmxyI0zacaeqDNkC/qDx7U pw784/+iqffC7DzxQCo9THraZQ+TA1LFW+ngLlE6X6tVEdo8LQoYId5zK0lc0ewh41cu nhdq9MkGO4R3TqCRtFesf8qLXlN1zI/n+A3bYFp2TFDgoIpgy3yrjY2Pb5ZoaZnIF8sf hszw== X-Forwarded-Encrypted: i=1; AJvYcCVSwr3JBzGYGsIBAwuz5Hly32WNi6xL/0aIZOt0LnTZAHXrgXTz1FDryuuQzwNDUF9nt/xT6SZGtARsAI0=@vger.kernel.org X-Gm-Message-State: AOJu0YyDJJnT3SA+H0KIk3KksOR04KYwujcklt+JXvd6XM2xWo2am8rW JFbWf6OHUCKr9Nov4MycIz0eCuv4BmSdbvJUAs441XjrGv0zj++PmJXMPOqqE0J+l5lfOWAFmG6 /lsIWjePQk16+Fw== X-Google-Smtp-Source: AGHT+IFxZws29DhbbpH/KLYsAEx4pmiup8IragiPN7LI9PGQse+5aOUlD8Y1F5pVoTzX71AYu/bTg5dfcYA6Bg== X-Received: from dybnl3.prod.google.com ([2002:a05:7300:cf83:b0:2ac:37c6:d441]) (user=bingjiao job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7301:188f:b0:2a4:4e54:dc69 with SMTP id 5a478bee46e88-2b17d343af1mr699818eec.38.1767770920934; Tue, 06 Jan 2026 23:28:40 -0800 (PST) Date: Wed, 7 Jan 2026 07:28:14 +0000 In-Reply-To: <20260107072814.2324646-1-bingjiao@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260107072814.2324646-1-bingjiao@google.com> X-Mailer: git-send-email 2.52.0.358.g0dd7633a29-goog Message-ID: <20260107072814.2324646-3-bingjiao@google.com> Subject: [PATCH v1 2/2] mm/vmscan: select the closest perferred node in demote_folio_list() From: Bing Jiao To: linux-mm@kvack.org Cc: Bing Jiao , Andrew Morton , Johannes Weiner , David Hildenbrand , Michal Hocko , Qi Zheng , Shakeel Butt , Lorenzo Stoakes , Axel Rasmussen , Yuanchu Xie , Wei Xu , linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The preferred demotion node should be the one closest to the source node to minimize migration latency. However, if the preferred node is not set in mems_allowed, demote_folio_list() currently randomly select one from allowed nodes as the new preferred node. This can result in selecting a very distant node. Update demote_folio_list() to traverse the demotion targets hierarchically until the perferred node is set in mems_allowed, ensuring the perferred target is always the closest available node. Signed-off-by: Bing Jiao --- mm/vmscan.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index db2413c4bd26..d452974c946e 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -1052,8 +1052,18 @@ static unsigned int demote_folio_list(struct list_he= ad *demote_folios, if (nodes_empty(allowed_mask)) return false; - if (!node_isset(target_nid, allowed_mask)) - target_nid =3D node_random(&allowed_mask); + while (target_nid !=3D NUMA_NO_NODE && + !node_isset(target_nid, allowed_mask)) { + /* Get the preferred demotion target from the next tier. */ + target_nid =3D next_demotion_node(target_nid); + } + + /* + * The perferred node query is subject to race conditions such as + * nodes in the next tier are hot-unplugged. + */ + if (target_nid =3D=3D NUMA_NO_NODE) + return 0; mtc.nid =3D target_nid; /* Demotion ignores all cpuset and mempolicy settings */ -- 2.52.0.358.g0dd7633a29-goog