Skip to contentSkip to conversation

x86-64, NUMA: Remove custom phys_to_nid() implementation

PATCH In review Tejun Heo 3 participants 3 messages Mar 31, 2011

Subsystems (2)
lore
Share & tools
lore

Tejun Heo

author
#0 lore raw

PATCH 1/1 x86-64, NUMA: Remove custom phys_to_nid() implementation

phys_to_nid() maps physical address to NUMA node id. This is implemented by building perfect hash in compute_hash_shift() during initialization.

However, with SPARSE memory model, the nid is encoded in page flags. The perfect hash implementation was for DISCONTIG memory model which got removed years ago by b263295dbf (x86: 64-bit, make sparsemem vmemmap the only memory model).

So, the perfect hash ends up being used only during initialization when the core SPARSE code already provides perfectly acceptable generic early_pfn_to_nid() implementation.

Drop phys_to_nid() and use the generic ealry_pfn_to_nid() instead.

Cc Christoph Lameter <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Yinghai Lu <[email protected]>
Cc "H. Peter Anvin" <[email protected]>
Cc Thomas Gleixner <[email protected]>

---
If no one objects, will route through x86-mm. Thanks.

 arch/x86/Kconfig                 |    4 -
 arch/x86/include/asm/mmzone_64.h |   23 -------
 arch/x86/mm/numa_64.c            |  123 ---------------------------------------
 3 files changed, 1 insertion(+), 149 deletions(-)
arch/x86/include/asm/mmzone_64.h +0 -23
Index: work/arch/x86/include/asm/mmzone_64.h
===================================================================
@@ -4,36 +4,13 @@
 #ifndef _ASM_X86_MMZONE_64_H
 #define _ASM_X86_MMZONE_64_H
 
-
 #ifdef CONFIG_NUMA
 
 #include <linux/mmdebug.h>
-
 #include <asm/smp.h>
 
-/* Simple perfect hash to map physical addresses to node numbers */
-struct memnode {
-	int shift;
-	unsigned int mapsize;
-	s16 *map;
-	s16 embedded_map[64 - 8];
-} ____cacheline_aligned; /* total size = 128 bytes */
-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(!memnodemap);
-	nid = memnodemap[addr >> memnode_shift];
-	VIRTUAL_BUG_ON(nid >= MAX_NUMNODES || !node_data[nid]);
-	return nid;
-}
-
 #define NODE_DATA(nid)		(node_data[nid])
 
 #define node_start_pfn(nid)	(NODE_DATA(nid)->node_start_pfn)
arch/x86/mm/numa_64.c +1 -122

145 lines not on this page · raw message

arch/x86/Kconfig +0 -4
Index: work/arch/x86/Kconfig
===================================================================
@@ -1703,10 +1703,6 @@ config ARCH_ENABLE_MEMORY_HOTREMOVE
 	def_bool y
 	depends on MEMORY_HOTPLUG
 
-config HAVE_ARCH_EARLY_PFN_TO_NID
-	def_bool X86_64
-	depends on NUMA
-
 config USE_PERCPU_NUMA_NODE_ID
 	def_bool y
 	depends on NUMA
Reviewed-by on v1 1/1
#1 lore raw
Quoted 4 lines · Tejun Heo

However, with SPARSE memory model, the nid is encoded in page flags. The perfect hash implementation was for DISCONTIG memory model which got removed years ago by b263295dbf (x86: 64-bit, make sparsemem vmemmap the only memory model).

Most memory models have the nid either in page flags or you can get it from the zone that a page belongs to. So after boot its easy to determine the node. However, at early boot the page flags may be initialized relatively late. early_pfn_to_nid does use the early node map to determine the node and not the page flags. You are switching to the generic implementation of __pfn_to_nid and dropping the duplicate arch logic.

Acked-by on v1 1/1
#2 lore raw
In reply to Tejun Heo
Quoted 21 lines · Tejun Heo

phys_to_nid() maps physical address to NUMA node id. This is implemented by building perfect hash in compute_hash_shift() during initialization.

However, with SPARSE memory model, the nid is encoded in page flags. The perfect hash implementation was for DISCONTIG memory model which got removed years ago by b263295dbf (x86: 64-bit, make sparsemem vmemmap the only memory model).

So, the perfect hash ends up being used only during initialization when the core SPARSE code already provides perfectly acceptable generic early_pfn_to_nid() implementation.

Drop phys_to_nid() and use the generic ealry_pfn_to_nid() instead.

Cc Christoph Lameter<[email protected]>
Cc Ingo Molnar<[email protected]>
Cc Yinghai Lu<[email protected]>
Cc "H. Peter Anvin"<[email protected]>
Cc Thomas Gleixner<[email protected]>
Quoted 7 lines

---
If no one objects, will route through x86-mm. Thanks.

  arch/x86/Kconfig                 |    4 -
  arch/x86/include/asm/mmzone_64.h |   23 -------
  arch/x86/mm/numa_64.c            |  123 ---------------------------------------
  3 files changed, 1 insertion(+), 149 deletions(-)

good finding.