Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1221911

[PATCH v2 3/7] x86, gfp: Cache best near node for memory allocation.

From Tang Chen <tangchen@cn.fujitsu.com>
Newsgroups linux.kernel
Subject [PATCH v2 3/7] x86, gfp: Cache best near node for memory allocation.
Date 2015-09-10 06:40 +0200
Message-ID <q71Op-7Qc-19@gated-at.bofh.it> (permalink)
References <q71EK-7Fd-15@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


From: Gu Zheng <guz.fnst@cn.fujitsu.com>

In the current kernel, all possible cpus are mapped to the best near online
node if they reside in a memory-less node in init_cpu_to_node().

init_cpu_to_node()
{
	......
	for_each_possible_cpu(cpu) {
		......
		if (!node_online(node))
			node = find_near_online_node(node);
		numa_set_node(cpu, node);
	}
}

The reason for doing this is to prevent memory allocation failure if the
cpu is online but there is no memory on that node.

But since cpuid <-> nodeid mapping is planed to be made static, doing
so in initialization pharse makes no sense any more.

The best near online node for each cpu has been cached in an array in previous
patch. And the reason for doing this is to avoid mapping CPUs on memory-less
nodes to other nodes.

So in this patch, we get best near online node for CPUs on memory-less nodes
inside alloc_pages_node() and alloc_pages_exact_node() to avoid memory allocation
failure.

Signed-off-by: Gu Zheng <guz.fnst@cn.fujitsu.com>
Signed-off-by: Tang Chen <tangchen@cn.fujitsu.com>
---
 arch/x86/mm/numa.c  | 3 +--
 include/linux/gfp.h | 8 +++++++-
 2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/arch/x86/mm/numa.c b/arch/x86/mm/numa.c
index 8bd7661..e89b9fb 100644
--- a/arch/x86/mm/numa.c
+++ b/arch/x86/mm/numa.c
@@ -151,6 +151,7 @@ void numa_set_node(int cpu, int node)
 		return;
 	}
 #endif
+
 	per_cpu(x86_cpu_to_node_map, cpu) = node;
 
 	set_near_online_node(node);
@@ -787,8 +788,6 @@ void __init init_cpu_to_node(void)
 
 		if (node == NUMA_NO_NODE)
 			continue;
-		if (!node_online(node))
-			node = find_near_online_node(node);
 		numa_set_node(cpu, node);
 	}
 }
diff --git a/include/linux/gfp.h b/include/linux/gfp.h
index ad35f30..1a1324f 100644
--- a/include/linux/gfp.h
+++ b/include/linux/gfp.h
@@ -307,13 +307,19 @@ static inline struct page *alloc_pages_node(int nid, gfp_t gfp_mask,
 	if (nid < 0)
 		nid = numa_node_id();
 
+	if (!node_online(nid))
+		nid = get_near_online_node(nid);
+
 	return __alloc_pages(gfp_mask, order, node_zonelist(nid, gfp_mask));
 }
 
 static inline struct page *alloc_pages_exact_node(int nid, gfp_t gfp_mask,
 						unsigned int order)
 {
-	VM_BUG_ON(nid < 0 || nid >= MAX_NUMNODES || !node_online(nid));
+	VM_BUG_ON(nid < 0 || nid >= MAX_NUMNODES);
+
+	if (!node_online(nid))
+		nid = get_near_online_node(nid);
 
 	return __alloc_pages(gfp_mask, order, node_zonelist(nid, gfp_mask));
 }
-- 
1.9.3

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH v2 0/7] Make cpuid <-> nodeid mapping persistent. Tang Chen <tangchen@cn.fujitsu.com> - 2015-09-10 06:30 +0200
  [PATCH v2 6/7] x86, acpi, cpu-hotplug: Enable MADT APIs to return disabled apicid. Tang Chen <tangchen@cn.fujitsu.com> - 2015-09-10 06:40 +0200
  [PATCH v2 2/7] x86, numa: Introduce a node to node array to map a node to its best online node. Tang Chen <tangchen@cn.fujitsu.com> - 2015-09-10 06:40 +0200
  [PATCH v2 7/7] x86, acpi, cpu-hotplug: Set persistent cpuid <-> nodeid mapping when booting. Tang Chen <tangchen@cn.fujitsu.com> - 2015-09-10 06:40 +0200
  [PATCH v2 1/7] x86, numa: Move definition of find_near_online_node() forward. Tang Chen <tangchen@cn.fujitsu.com> - 2015-09-10 06:40 +0200
  [PATCH v2 5/7] x86, acpi, cpu-hotplug: Introduce apicid_to_cpuid[] array to store persistent cpuid <-> apicid mapping. Tang Chen <tangchen@cn.fujitsu.com> - 2015-09-10 06:40 +0200
    Re: [PATCH v2 5/7] x86, acpi, cpu-hotplug: Introduce  apicid_to_cpuid[] array to store persistent cpuid <-> apicid mapping. Tejun Heo <tj@kernel.org> - 2015-09-10 22:00 +0200
  [PATCH v2 3/7] x86, gfp: Cache best near node for memory allocation. Tang Chen <tangchen@cn.fujitsu.com> - 2015-09-10 06:40 +0200
    Re: [PATCH v2 3/7] x86, gfp: Cache best near node for memory  allocation. Tejun Heo <tj@kernel.org> - 2015-09-10 21:30 +0200
      Re: [PATCH v2 3/7] x86, gfp: Cache best near node for memory  allocation. Tejun Heo <tj@kernel.org> - 2015-09-10 21:40 +0200
        Re: [PATCH v2 3/7] x86, gfp: Cache best near node for memory  allocation. Christoph Lameter <cl@linux.com> - 2015-09-11 00:10 +0200
          Re: [PATCH v2 3/7] x86, gfp: Cache best near node for memory  allocation. Tejun Heo <tj@kernel.org> - 2015-09-11 00:10 +0200
        Re: [PATCH v2 3/7] x86, gfp: Cache best near node for memory  allocation. Christoph Lameter <cl@linux.com> - 2015-09-11 02:20 +0200
  [PATCH v2 4/7] x86, acpi, cpu-hotplug: Enable acpi to register all possible cpus at boot time. Tang Chen <tangchen@cn.fujitsu.com> - 2015-09-10 06:40 +0200
    Re: [PATCH v2 4/7] x86, acpi, cpu-hotplug: Enable acpi to register all possible cpus at boot time. "Rafael J. Wysocki" <rjw@rjwysocki.net> - 2015-09-11 00:50 +0200

csiph-web