[PATCH 2/2] mm: Change mbind(MPOL_BIND) implementation for CDM nodes

From: Anshuman Khandual
Date: Wed Mar 08 2017 - 08:27:28 EST


CDM nodes need a way of explicit memory allocation mechanism from the user
space. After the previous FALLBACK zonelist rebuilding process changes, the
mbind(MPOL_BIND) based allocation request fails on the CDM node. This is
because allocation requesting local node's FALLBACK zonelist is selected
for further nodemask processing targeted at MPOL_BIND implementation. As
the CDM node's zones are not part of any other regular node's FALLBACK
zonelist, the allocation simply fails without getting any valid zone. The
allocation requesting node is always going to be different than the CDM
node which does not have any CPU. Hence MPOL_MBIND implementation must
choose given CDM node's FALLBACK zonelist instead of the requesting local
node's FALLBACK zonelist. This implements that change.

Signed-off-by: Anshuman Khandual <khandual@xxxxxxxxxxxxxxxxxx>
---
mm/mempolicy.c | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)

diff --git a/mm/mempolicy.c b/mm/mempolicy.c
index 1e7873e..6089c711 100644
--- a/mm/mempolicy.c
+++ b/mm/mempolicy.c
@@ -1692,6 +1692,27 @@ static struct zonelist *policy_zonelist(gfp_t gfp, struct mempolicy *policy,
WARN_ON_ONCE(policy->mode == MPOL_BIND && (gfp & __GFP_THISNODE));
}

+#ifdef CONFIG_COHERENT_DEVICE
+ /*
+ * Coherent Device Memory (CDM)
+ *
+ * In case the local requesting node is not part of the nodemask, test
+ * if the first node in the nodemask is CDM, in which case select it.
+ *
+ * XXX: There are multiple ways of doing this. This node check can be
+ * restricted to the first node in the node mask as implemented here or
+ * scan through the entire nodemask to find out any present CDM node on
+ * it or select the first CDM node only if all other nodes in the node
+ * mask are CDM. These are variour approaches possible, the first one
+ * is implemented here.
+ */
+ if (policy->mode == MPOL_BIND) {
+ if (unlikely(!node_isset(nd, policy->v.nodes))) {
+ if (is_cdm_node(first_node(policy->v.nodes)))
+ nd = first_node(policy->v.nodes);
+ }
+ }
+#endif
return node_zonelist(nd, gfp);
}

--
2.9.3