[PATCH 1/3] mm/mempolicy: apply cpuset limits to tasks using default policy

From: Abel Wu
Date: Mon Apr 26 2021 - 03:00:18 EST


The nodemasks of non-default policies (pol->v) are calculated within
the restriction of task->mems_allowed, while default policies are not.
This may lead to improper results of mpol_misplaced(), since it can
return a target node outside of current->mems_allowed for tasks using
default policies. Although this is not a bug because migrating pages
to that out-of-cpuset node will fail eventually due to sanity checks
in page allocation, it still would be better to avoid such useless
efforts.

This patch also changes the behavior of autoNUMA a bit by showing
a tendency to move pages inside mems_allowed for tasks using default
policies, which is good for memory isolation.

Signed-off-by: Abel Wu <wuyun.abel@xxxxxxxxxxxxx>
---
mm/mempolicy.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/mm/mempolicy.c b/mm/mempolicy.c
index d79fa299b70c..e0ae6997bbfb 100644
--- a/mm/mempolicy.c
+++ b/mm/mempolicy.c
@@ -2516,7 +2516,10 @@ int mpol_misplaced(struct page *page, struct vm_area_struct *vma, unsigned long

/* Migrate the page towards the node whose CPU is referencing it */
if (pol->flags & MPOL_F_MORON) {
- polnid = thisnid;
+ if (node_isset(thisnid, cpuset_current_mems_allowed))
+ polnid = thisnid;
+ else
+ polnid = node_random(&cpuset_current_mems_allowed);

if (!should_numa_migrate_memory(current, page, curnid, thiscpu))
goto out;
--
2.31.1