[PATCH v1 1/2] mm/vmscan: balance demotion allocation in alloc_demote_folio()

From: Bing Jiao

Date: Wed Jan 07 2026 - 02:28:39 EST


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 <bingjiao@xxxxxxxxxx>
---
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 = node_random(allowed_mask);
+ node_clear(mtc->nid, *allowed_mask);
+ }
mtc->gfp_mask &= ~__GFP_THISNODE;
mtc->nmask = allowed_mask;

--
2.52.0.358.g0dd7633a29-goog