From: Balbir Singh <bsingharora@gmail.com>
To: linux-mm@kvack.org, akpm@linux-foundation.org
Cc: khandual@linux.vnet.ibm.com, benh@kernel.crashing.org,
aneesh.kumar@linux.vnet.ibm.com, paulmck@linux.vnet.ibm.com,
srikar@linux.vnet.ibm.com, haren@linux.vnet.ibm.com,
jglisse@redhat.com, mgorman@techsingularity.net,
mhocko@kernel.org, arbab@linux.vnet.ibm.com, vbabka@suse.cz,
cl@linux.com, Balbir Singh <bsingharora@gmail.com>
Subject: [RFC 3/4] mm: Integrate N_COHERENT_MEMORY with mempolicy and the rest of the system
Date: Wed, 19 Apr 2017 17:52:41 +1000 [thread overview]
Message-ID: <20170419075242.29929-4-bsingharora@gmail.com> (raw)
In-Reply-To: <20170419075242.29929-1-bsingharora@gmail.com>
This patch integrates N_COHERENT_MEMORY and makes the integration
deeper. It does the following
1. Modifies mempolicy so as to
a. Allow policy_zonelist() and policy_nodemask() to
understand N_COHERENT_MEMORY nodes and allow the
right mask/list to be built when the policy contains
those nodes
b. Checks for N_COHERENT_MEMORY in mpol_new_nodemask()
and other places with hard-coded checks for N_MEMORY
2. Modifies mm/page_alloc.c, so that nodes marked as N_COHERENT_MEMORY
are not marked as N_MEMORY
3. Changes node zonelist creation, so that coherent memory is
present in the fallback in case multiple such nodes are
present.
Signed-off-by: Balbir Singh <bsingharora@gmail.com>
---
mm/memory_hotplug.c | 3 ++-
mm/mempolicy.c | 31 ++++++++++++++++++++++++++++---
mm/page_alloc.c | 21 +++++++++++++++++----
3 files changed, 47 insertions(+), 8 deletions(-)
diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c
index ebeb3af..12d5431 100644
--- a/mm/memory_hotplug.c
+++ b/mm/memory_hotplug.c
@@ -1037,7 +1037,8 @@ static void node_states_set_node(int node, struct memory_notify *arg)
if (arg->status_change_nid_high >= 0)
node_set_state(node, N_HIGH_MEMORY);
- node_set_state(node, N_MEMORY);
+ if (!node_state(node, N_COHERENT_MEMORY))
+ node_set_state(node, N_MEMORY);
}
bool zone_can_shift(unsigned long pfn, unsigned long nr_pages,
diff --git a/mm/mempolicy.c b/mm/mempolicy.c
index 37d0b33..141398e 100644
--- a/mm/mempolicy.c
+++ b/mm/mempolicy.c
@@ -217,6 +217,8 @@ static int mpol_set_nodemask(struct mempolicy *pol,
const nodemask_t *nodes, struct nodemask_scratch *nsc)
{
int ret;
+ int n;
+ nodemask_t tmp;
/* if mode is MPOL_DEFAULT, pol is NULL. This is right. */
if (pol == NULL)
@@ -226,6 +228,14 @@ static int mpol_set_nodemask(struct mempolicy *pol,
cpuset_current_mems_allowed, node_states[N_MEMORY]);
VM_BUG_ON(!nodes);
+
+ for_each_node_mask(n, *nodes) {
+ if (node_state(n, N_COHERENT_MEMORY)) {
+ tmp = nodemask_of_node(n);
+ nodes_or(nsc->mask1, nsc->mask1, tmp);
+ }
+ }
+
if (pol->mode == MPOL_PREFERRED && nodes_empty(*nodes))
nodes = NULL; /* explicit local allocation */
else {
@@ -1435,7 +1445,8 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
goto out_put;
}
- if (!nodes_subset(*new, node_states[N_MEMORY])) {
+ if (!nodes_subset(*new, node_states[N_MEMORY]) &&
+ !nodes_subset(*new, node_states[N_COHERENT_MEMORY])) {
err = -EINVAL;
goto out_put;
}
@@ -1670,7 +1681,9 @@ static nodemask_t *policy_nodemask(gfp_t gfp, struct mempolicy *policy)
/* Lower zones don't get a nodemask applied for MPOL_BIND */
if (unlikely(policy->mode == MPOL_BIND) &&
apply_policy_zone(policy, gfp_zone(gfp)) &&
- cpuset_nodemask_valid_mems_allowed(&policy->v.nodes))
+ (cpuset_nodemask_valid_mems_allowed(&policy->v.nodes) ||
+ nodes_intersects(policy->v.nodes,
+ node_states[N_COHERENT_MEMORY])))
return &policy->v.nodes;
return NULL;
@@ -1691,6 +1704,17 @@ static struct zonelist *policy_zonelist(gfp_t gfp, struct mempolicy *policy,
WARN_ON_ONCE(policy->mode == MPOL_BIND && (gfp & __GFP_THISNODE));
}
+ /*
+ * It is not sufficient to have the right nodemask, we need the
+ * correct zonelist for N_COHERENT_MEMORY
+ */
+ if (node_state(nd, N_COHERENT_MEMORY))
+ /*
+ * Ideally we should pick the best node, but for now use
+ * any one
+ */
+ nd = first_node(node_states[N_COHERENT_MEMORY]);
+
return node_zonelist(nd, gfp);
}
@@ -2689,7 +2713,8 @@ int mpol_parse_str(char *str, struct mempolicy **mpol)
*nodelist++ = '\0';
if (nodelist_parse(nodelist, nodes))
goto out;
- if (!nodes_subset(nodes, node_states[N_MEMORY]))
+ if (!nodes_subset(nodes, node_states[N_MEMORY]) &&
+ !nodes_subset(nodes, node_states[N_COHERENT_MEMORY]))
goto out;
} else
nodes_clear(nodes);
diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index e2c687d..59e4d30 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -4856,6 +4856,7 @@ static int find_next_best_node(int node, nodemask_t *used_node_mask)
int min_val = INT_MAX;
int best_node = NUMA_NO_NODE;
const struct cpumask *tmp = cpumask_of_node(0);
+ nodemask_t tmp_mask, tmp_mask2;
/* Use the local node if we haven't already */
if (!node_isset(node, *used_node_mask)) {
@@ -4863,7 +4864,17 @@ static int find_next_best_node(int node, nodemask_t *used_node_mask)
return node;
}
- for_each_node_state(n, N_MEMORY) {
+ tmp_mask = node_states[N_MEMORY];
+ tmp_mask2 = node_states[N_COHERENT_MEMORY];
+
+ /*
+ * If the nodemask has one coherent node, add others
+ * as well
+ */
+ if (node_state(node, N_COHERENT_MEMORY))
+ nodes_or(tmp_mask, tmp_mask2, tmp_mask);
+
+ for_each_node_mask(n, tmp_mask) {
/* Don't want a node to appear more than once */
if (node_isset(n, *used_node_mask))
@@ -6288,7 +6299,7 @@ static unsigned long __init early_calculate_totalpages(void)
unsigned long pages = end_pfn - start_pfn;
totalpages += pages;
- if (pages)
+ if (pages && !node_state(nid, N_COHERENT_MEMORY))
node_set_state(nid, N_MEMORY);
}
return totalpages;
@@ -6598,9 +6609,11 @@ void __init free_area_init_nodes(unsigned long *max_zone_pfn)
find_min_pfn_for_node(nid), NULL);
/* Any memory on that node */
- if (pgdat->node_present_pages)
+ if (pgdat->node_present_pages &&
+ !node_state(nid, N_COHERENT_MEMORY)) {
node_set_state(nid, N_MEMORY);
- check_for_memory(pgdat, nid);
+ check_for_memory(pgdat, nid);
+ }
}
}
--
2.9.3
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
next prev parent reply other threads:[~2017-04-19 7:53 UTC|newest]
Thread overview: 45+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-04-19 7:52 [RFC 0/4] RFC - Coherent Device Memory (Not for inclusion) Balbir Singh
2017-04-19 7:52 ` [RFC 1/4] mm: create N_COHERENT_MEMORY Balbir Singh
2017-04-27 18:42 ` Reza Arbab
2017-04-28 5:07 ` Balbir Singh
2017-04-19 7:52 ` [RFC 2/4] arch/powerpc/mm: add support for coherent memory Balbir Singh
2017-04-19 7:52 ` Balbir Singh [this message]
2017-04-19 7:52 ` [RFC 4/4] mm: Add documentation " Balbir Singh
2017-04-19 19:02 ` [RFC 0/4] RFC - Coherent Device Memory (Not for inclusion) Christoph Lameter
2017-04-20 1:25 ` Balbir Singh
2017-04-20 15:29 ` Christoph Lameter
2017-04-20 21:26 ` Benjamin Herrenschmidt
2017-04-21 16:13 ` Christoph Lameter
2017-04-21 21:15 ` Benjamin Herrenschmidt
2017-04-24 13:57 ` Christoph Lameter
2017-04-24 0:20 ` Balbir Singh
2017-04-24 14:00 ` Christoph Lameter
2017-04-25 0:52 ` Balbir Singh
2017-05-01 20:41 ` John Hubbard
2017-05-01 21:04 ` Reza Arbab
2017-05-01 21:56 ` John Hubbard
2017-05-01 23:51 ` Reza Arbab
2017-05-01 23:58 ` John Hubbard
2017-05-02 0:04 ` Reza Arbab
2017-05-02 1:29 ` Balbir Singh
2017-05-02 5:47 ` John Hubbard
2017-05-02 7:23 ` Balbir Singh
2017-05-02 17:50 ` John Hubbard
2017-05-02 14:36 ` Michal Hocko
2017-05-04 5:26 ` Balbir Singh
2017-05-04 12:52 ` Michal Hocko
2017-05-04 15:49 ` Benjamin Herrenschmidt
2017-05-04 17:33 ` Dave Hansen
2017-05-05 3:17 ` Balbir Singh
2017-05-05 14:51 ` Dave Hansen
2017-05-05 7:49 ` Benjamin Herrenschmidt
2017-05-05 14:52 ` Michal Hocko
2017-05-05 15:57 ` Benjamin Herrenschmidt
2017-05-05 17:48 ` Jerome Glisse
2017-05-05 17:59 ` Benjamin Herrenschmidt
2017-05-09 11:36 ` Michal Hocko
2017-05-09 13:43 ` Benjamin Herrenschmidt
2017-05-15 12:55 ` Michal Hocko
2017-05-15 15:53 ` Christoph Lameter
2017-05-10 23:04 ` Balbir Singh
2017-05-09 7:51 ` Balbir Singh
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170419075242.29929-4-bsingharora@gmail.com \
--to=bsingharora@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=aneesh.kumar@linux.vnet.ibm.com \
--cc=arbab@linux.vnet.ibm.com \
--cc=benh@kernel.crashing.org \
--cc=cl@linux.com \
--cc=haren@linux.vnet.ibm.com \
--cc=jglisse@redhat.com \
--cc=khandual@linux.vnet.ibm.com \
--cc=linux-mm@kvack.org \
--cc=mgorman@techsingularity.net \
--cc=mhocko@kernel.org \
--cc=paulmck@linux.vnet.ibm.com \
--cc=srikar@linux.vnet.ibm.com \
--cc=vbabka@suse.cz \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.