Skip to contentSkip to conversation

x86_64: Make the NUMA hash function nodemap allocation dynamic and remove NODEMAPSIZE

PATCH In review Amul Shah 3 participants 5 messages Nov 8, 2006 – Nov 10, 2006

lore
Share & tools
lore

Amul Shah

author
#0 lore raw

PATCH 1/1 x86_64: Make the NUMA hash function nodemap allocation dynamic and remove NODEMAPSIZE

This patch removes the statically allocated memory to NUMA node hash map in favor of a dynamically allocated memory to node hash map (it is cache aligned).

This patch has the nice side effect in that it allows the hash map to grow for systems with large amounts of memory (256GB - 1TB), but suffer from having small PCI space tacked onto the boot node (which is somewhere between 192MB to 512MB on the ES7000).

---
Patch applies to 2.6.18 and 2.6.19-rc4 and has been tested with each. This patch needs testing on a K8 NUMA platform.

arch/x86_64/kernel/e820.c +6 -0
diff -uprN linux-2.6.19-rc4/arch/x86_64/kernel/e820.c linux-2.6.19-rc4-az/arch/x86_64/kernel/e820.c
@@ -83,6 +83,12 @@ static inline int bad_addr(unsigned long
 		return 1;
 	}
 
+	/* NUMA memory to node map */
+	if (last >= nodemap_addr && addr < nodemap_addr + nodemap_size) {
+		*addrp = nodemap_addr + nodemap_size;
+		return 1;
+	}
+
 	/* XXX ramdisk image here? */ 
 	return 0;
 } 
arch/x86_64/kernel/setup.c +4 -0
diff -uprN linux-2.6.19-rc4/arch/x86_64/kernel/setup.c linux-2.6.19-rc4-az/arch/x86_64/kernel/setup.c
@@ -445,6 +445,10 @@ void __init setup_arch(char **cmdline_p)
 	if (ebda_addr)
 		reserve_bootmem_generic(ebda_addr, ebda_size);
 
+	/* reserve nodemap region */
+	if (nodemap_addr)
+		reserve_bootmem_generic(nodemap_addr, nodemap_size);
+
 #ifdef CONFIG_SMP
 	/*
 	 * But first pinch a few for the stack/trampoline stuff
arch/x86_64/mm/numa.c +59 -9

99 lines not on this page · raw message

include/asm-x86_64/e820.h +1 -0
diff -uprN linux-2.6.19-rc4/include/asm-x86_64/e820.h linux-2.6.19-rc4-az/include/asm-x86_64/e820.h
@@ -56,6 +56,7 @@ extern void finish_e820_parsing(void);
 extern struct e820map e820;
 
 extern unsigned ebda_addr, ebda_size;
+extern unsigned long nodemap_addr, nodemap_size;
 #endif/*!__ASSEMBLY__*/
 
 #endif/*__E820_HEADER*/
include/asm-x86_64/mmzone.h +6 -5
diff -uprN linux-2.6.19-rc4/include/asm-x86_64/mmzone.h linux-2.6.19-rc4-az/include/asm-x86_64/mmzone.h
@@ -11,24 +11,25 @@
 
 #include <asm/smp.h>
 
-/* Should really switch to dynamic allocation at some point */
-#define NODEMAPSIZE 0x4fff
-
 /* Simple perfect hash to map physical addresses to node numbers */
 struct memnode {
 	int shift;
-	u8 map[NODEMAPSIZE];
+	u64 mapsize;
+	u8 *map;
+	u8 zero;
 } ____cacheline_aligned;
 extern struct memnode memnode;
 #define memnode_shift memnode.shift
 #define memnodemap memnode.map
+#define memnodemapsize memnode.mapsize
 
 extern struct pglist_data *node_data[];
 
 static inline __attribute__((pure)) int phys_to_nid(unsigned long addr) 
 { 
 	unsigned nid; 
-	VIRTUAL_BUG_ON((addr >> memnode_shift) >= NODEMAPSIZE);
+	VIRTUAL_BUG_ON(!memnodemap);
+	VIRTUAL_BUG_ON((addr >> memnode_shift) >= memnodemapsize);
 	nid = memnodemap[addr >> memnode_shift]; 
 	VIRTUAL_BUG_ON(nid >= MAX_NUMNODES || !node_data[nid]); 
 	return nid; 
#1 lore raw

arch/x86_64/kernel/e820.c static inline int bad_addr(unsigned long · line 90

Quoted 13 lines

diff -uprN linux-2.6.19-rc4/arch/x86_64/kernel/e820.c linux-2.6.19-rc4-az/arch/x86_64/kernel/e820.c

arch/x86_64/kernel/e820.c +5 -0
@@ -83,6 +83,12 @@ static inline int bad_addr(unsigned long
 		return 1;
 	}
 
+	/* NUMA memory to node map */
+	if (last >= nodemap_addr && addr < nodemap_addr + nodemap_size) {
+		*addrp = nodemap_addr + nodemap_size;
+		return 1;
+	}

Using the e820 allocator will now mean it's rounded up to pages. That will waste a bit of memory, but i suppose it's ok.

arch/x86_64/kernel/e820.c static inline int bad_addr(unsigned long · line 91

Quoted 1 line
arch/x86_64/kernel/e820.c +1 -0
+	for (i=20; !(bitfield&(1UL << i)) && i<BITS_PER_LONG; i++);

That's find_first_bit() ? Please use that

arch/x86_64/kernel/e820.c static inline int bad_addr(unsigned long · line 93

Quoted 3 lines
arch/x86_64/kernel/e820.c +2 -0
+	shift = extract_lsb_from_nodes(nodes, numnodes);
+	if ( allocate_cachealigned_memnodemap() )

No extra spaces here please (and in some other places)

arch/x86_64/kernel/e820.c static inline int bad_addr(unsigned long

Quoted 2 lines
arch/x86_64/kernel/e820.c +2 -0
+	u8 *map;
+	u8 zero;

zero?

Quoted 5 lines

} ____cacheline_aligned;
extern struct memnode memnode;
#define memnode_shift memnode.shift
#define memnodemap memnode.map
+#define memnodemapsize memnode.mapsize

Have you checked how much the code .text size changes because of the pointer reference? If it's a lot phys_to_nid might need to be out of lined.

-Andi

#2 lore raw
Quoted 3 lines · Andi Kleen

Have you checked how much the code .text size changes because of the pointer reference? If it's a lot phys_to_nid might need to be out of lined.

Here I have also big numbers on pfn_to_page(), on a machine with mapsize=1 (NUMA kernel, but one node)

oprofile results L1_AND_L2_DTLB_MISSES /usr/src/linux-2.6.18/vmlinux

Counted L1_AND_L2_DTLB_MISSES events (L1 and L2 DTLB misses) with a unit mask of 0x00 (No unit mask) count 10000

ffffffff80258fa0 <pfn_to_page>: /* pfn_to_page total: 48433 0.4914 */

So adding yet another indirection (to a another cache line) might hurt.

Therefore I suggest to use a structure like that :

struct memnode {

 	int shift;
	unsigned int mapsize; /* no need to use 8 bytes here */
	u8 *map;
	u8 embedded_map[64-8]; /* total size = 64 bytes */

} ____cacheline_aligned;

and make memnode.map point to memnode.embedded_map if mapsize <= 56 ?

This way, most AMD64 dual/quad processors wont waste a full PAGE to store few bytes in it, and should use only one cache line.

Thank you

Eric

#3 lore raw
Quoted 10 lines · Eric Dumazet

Therefore I suggest to use a structure like that :

struct memnode {

 	int shift;
	unsigned int mapsize; /* no need to use 8 bytes here */
	u8 *map;
	u8 embedded_map[64-8]; /* total size = 64 bytes */

} ____cacheline_aligned;

Arg... [64 - 16] sorry

Quoted 1 line

and make memnode.map point to memnode.embedded_map if mapsize <= 56 ?

mapsize <= 48

Quoted 8 lines

This way, most AMD64 dual/quad processors wont waste a full PAGE to store few bytes in it, and should use only one cache line.

Thank you

Eric

#4 lore raw
In reply to Eric Dumazet
Quoted 11 lines

Therefore I suggest to use a structure like that :

struct memnode {

 	int shift;
	unsigned int mapsize; /* no need to use 8 bytes here */
	u8 *map;
	u8 embedded_map[64-8]; /* total size = 64 bytes */

} ____cacheline_aligned;

and make memnode.map point to memnode.embedded_map if mapsize <= 56 ?

That's a good idea yes.

-Andi