Skip to contentSkip to conversation

Memory allocation from the nearest node.

RFC PATCH In review Yuji Shimada 2 participants 2 messages Apr 7, 2009

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 Memory allocation from the nearest node.

On current xen, memory is allocated from a NUMA node on which vcpu#0 is If there is no free memory on the node, next NUMA node is selected in numeric order. But second selected node is not always the nearest node from first selected node.

For example, If NUMA node #n is selected as first node on a machine which has m nodes, free memory is searched in the following order.

NUMA node #
(n) -> (n+1) -> ... -> (m-2) -> (m-1) -> (0) -> (1) -> ... -> (n-1)

On memory allocation, if there is no free memory on first selected node, the nearest node should be used for the next memory allocation. Because we can get better memory latency by using memory of near node.

This patch fixes to select the nearest node for next memory allocation.

BIOS sets distance between NUMA node to SLIT table of ACPI. This patch uses the value of SLIT table to get distance between NUMA node. If ACPI does not have SLIT table, the value of "10" is defined as the same node and "20" is defined as the different node.

I would like ask any comments of developers.
I will make the modified patch after Xen 3.4 is released.

Thanks,
--
Yuji Shimada

xen/arch/x86/srat.c +1 -1
diff -r 5a60eb7fad79 xen/arch/x86/srat.c
@@ -307,7 +307,7 @@
 	int index;
 
 	if (!acpi_slit)
-		return a == b ? 10 : 20;
+		return a == b ? LOCAL_DISTANCE : REMOTE_DISTANCE;
 	index = acpi_slit->locality_count * node_to_pxm(a);
 	return acpi_slit->entry[index + node_to_pxm(b)];
 }
xen/common/page_alloc.c +46 -6

92 lines not on this page · raw message

xen/include/asm-x86/numa.h +5 -0
diff -r 5a60eb7fad79 xen/include/asm-x86/numa.h
@@ -23,6 +23,8 @@
 #define ZONE_ALIGN (1UL << (MAX_ORDER+PAGE_SHIFT))
 #define VIRTUAL_BUG_ON(x) 
 #define NODEMAPSIZE 0xfff
+#define LOCAL_DISTANCE 10
+#define REMOTE_DISTANCE 20
 
 extern void numa_add_cpu(int cpu);
 extern void numa_init_array(void);
@@ -67,10 +69,13 @@
 #define node_end_pfn(nid)       (NODE_DATA(nid)->node_start_pfn + \
 				 NODE_DATA(nid)->node_spanned_pages)
 
+extern int __node_distance(int, int);
+#define node_distance(a, b) __node_distance(a,b)
 
 #else
 #define init_cpu_to_node() do {} while (0)
 #define clear_node_cpumask(cpu) do {} while (0)
+#define node_distance(a, b) ((a) == (b) ? LOCAL_DISTANCE : REMOTE_DISTANCE)
 #endif
#1 lore raw
Quoted 7 lines · Yuji Shimada

BIOS sets distance between NUMA node to SLIT table of ACPI. This patch uses the value of SLIT table to get distance between NUMA node. If ACPI does not have SLIT table, the value of "10" is defined as the same node and "20" is defined as the different node.

I would like ask any comments of developers.
I will make the modified patch after Xen 3.4 is released.

I'd personally rather initialise a N*N array and then search next_node[first_node][i], 0<=i<N. Otherwise we turned the O(N) node search into at least O(N^2), and it looks like node_distance() could hide further costs. And we'll typically be running that search *per page* allocated. It could easily add up to significant overhead. If N is big then we could allocate rows of the array on demand.

-- Keir