From nobody Sun Feb 8 02:20:46 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 703071A9F9F for ; Wed, 7 Jan 2026 07:28:39 +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=1767770920; cv=none; b=bRTTL8ecxlN3uP/XZjPhNVkssymX/rWVpiUagquWF/eaXRnT0/y1ds1Ba0s0HUrGm6k4FxqUxGNwZMg+VU1Og5+aqVLS3D6Ptgeo50B5Rtj8b0aROtzHPrkMuxGQ/pUsNEOEtTfLGgE5fW3WPEhcIybeYkbwXiCWvDx7f+tvZww= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767770920; c=relaxed/simple; bh=9G2NXjnYOg1aT9+qV6x6kb7NWlp3+vimwZq0Qy1ODOQ=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=cm+dxISPN8Dr6sg6YroWmK7Mpr2bAYYRsBtyrUXqsHFSUEYtk5/k0HXuldCcXt5iGfJKK1UqVoG0vFx3UD2gJgpqNH88zNP1IMNuIpCzGVVqN3OVOUqzRJIQv+7O82y/5tiA4EvCUVmBncWFTEzrQPdTGFiUiwVNVLgUYc5pWxI= 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=igtrqn8u; 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="igtrqn8u" Received: by mail-dy1-f202.google.com with SMTP id 5a478bee46e88-2b04f8c5e84so1134674eec.1 for ; Tue, 06 Jan 2026 23:28:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1767770918; x=1768375718; 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=xZsdM3yNb3T+HIuMdwl9qQggHhqQbJEHsMkRZMl/CR0=; b=igtrqn8u/j8XPpgrbK8704o56pT1sRMoYUuzFknMTB+sdly61RgjSA4IZ0wHJsKO99 pryyJEO/06U0TXIVRNmqJjqRqya4yxMOQCVziJWy4PafVGLD/nvIsl+zlmLwHS2viU8b 82F+EMENt+H0LbXI1pq7W+yKUImj4Bp9n7f3X1qrn8vlOWINLcC81fUcH//AhiItRSzj c3zogreRFKT1wFgc5vHlCjkYmdA9LHaMHhLE7PEIVkc+rH9xb6KK27myvfpq7ceXzgB4 4dABhoMosVstasvweourYKr4Nq27yTRJpOsT3TcxVgURoGprL7THt9KkLi9+9BIXB5Ta J07Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767770918; x=1768375718; 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=xZsdM3yNb3T+HIuMdwl9qQggHhqQbJEHsMkRZMl/CR0=; b=P3d8qMNYdM/SWVa0RrvSA9vAxKPyrU21i04tkDYCghqmsGzH3gZyVObVj/e23NBkmq QWim0y2CyTw0PgtS2lNF/tPtVZ2VUJoUbFCOerydK1zQqRiPGm/kjX/OgHnBi0atxN+d cDzSYU3DRvhJSEoVOsdjpQ8dpI52JIwxKTP1pkX+CytMCbp3OHLTXTGnskSexrJ093Eg bTIVTjx4GSsb0dE1AeHfod/jOqAG7yqubyooQ26Jeje/j8zlgn2syaFRcUTmpVOIOuVg TD5cleQNDjEMJTQk0SFM1QGN4wVs6Jg2q5/62LAzRYHHiozwt3nfHLkC62oTC5veUloJ pKjw== X-Forwarded-Encrypted: i=1; AJvYcCWGntrqKYq+IchtB9wOdVB5RM/NOx0Qm+zYhL747iLnaE20LZ0W3Ep5m2zRRt2ubVIGv6QAkZLsn2Qc9N0=@vger.kernel.org X-Gm-Message-State: AOJu0YxNDYXS8Fp61KtTzGUaI6OepPfWKTdLqFCc1gsOscrXvirqyF12 JXyiH6sfhIODNhaOwpTlxMBB2GJZoFuisWQAru3cSe6Y8fA0CFlehSLE/p3660U9thdxgulipCv xEtLzspXiFUWabQ== X-Google-Smtp-Source: AGHT+IEnSu4SokYnEoOy1GYAc6KpMrqgiubRKJ54xg88A7PHQ7qAFtcBGxkS/pNhE4AjQ+N/NbqrwuAqVAwzRA== X-Received: from dlbrb22.prod.google.com ([2002:a05:7022:f016:b0:120:5f06:210a]) (user=bingjiao job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:2391:b0:11e:3e9:3ea0 with SMTP id a92af1059eb24-121f8b777b3mr1532979c88.49.1767770918357; Tue, 06 Jan 2026 23:28:38 -0800 (PST) Date: Wed, 7 Jan 2026 07:28:13 +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-2-bingjiao@google.com> Subject: [PATCH v1 1/2] mm/vmscan: balance demotion allocation in alloc_demote_folio() 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" When the preferred demotion node does not have enough free space, alloc_demote_folio() attempts to allocate from fallback nodes. Currently, it lacks a mechanism to distribute these fallback allocations, which can lead to unbalanced memory pressure across fallback nodes. Balance the allocation by randomly selecting a new preferred node from the fallback nodes if the initial allocation from the old preferred node fails. Signed-off-by: Bing Jiao --- mm/vmscan.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/mm/vmscan.c b/mm/vmscan.c index 81828fa625ed..db2413c4bd26 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -1009,6 +1009,11 @@ static struct folio *alloc_demote_folio(struct folio= *src, if (dst) return dst; + /* Randomly select a node from fallback nodes for balanced allocation */ + if (allowed_mask) { + mtc->nid =3D node_random(allowed_mask); + node_clear(mtc->nid, *allowed_mask); + } mtc->gfp_mask &=3D ~__GFP_THISNODE; mtc->nmask =3D allowed_mask; -- 2.52.0.358.g0dd7633a29-goog From nobody Sun Feb 8 02:20:46 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