Skip to contentSkip to conversation

mem_map definition / declaration.

PATCH In review Ralf Baechle 3 participants 4 messages May 31, 2006 – Jun 10, 2006

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

mm/memory defines mem_map and max_mapnr only if !CONFIG_NEED_MULTIPLE_NODES. <linux/mm.h> declares mem_map[] if !CONFIG_DISCONTIGMEM. Shouldn't both depend on !CONFIG_FLATMEM? As things are now mem_map may be declared but not defined for a non-NUMA sparsemem system which may make tracking a remaining mem_map reference in the code a little harder.

Ralf

#1 lore raw
Quoted 5 lines · Ralf Baechle

mm/memory defines mem_map and max_mapnr only if !CONFIG_NEED_MULTIPLE_NODES. <linux/mm.h> declares mem_map[] if !CONFIG_DISCONTIGMEM. Shouldn't both depend on !CONFIG_FLATMEM? As things are now mem_map may be declared but not defined for a non-NUMA sparsemem system which may make tracking a remaining mem_map reference in the code a little harder.

Sounds suspect for sure. I will take a look and see. Thanks for the head up.

-apw

#2 lore raw

PATCH 1/1 mem_map is part of the FLATMEM model

As Ralf Baechle points out the definition and the declaration of mem_map are made under differing config options. This leads to difficulty tracking errant references to mem_map when it is not available. Below is a patch to sort out the mem_map definition, making the fact that it is part of the FLATMEM memory model explicit.

It builds and boots on all my test boxes. It build tests for all sane combinations of memory model on x86. The most likely architecture to have trouble with this is arm as it makes significant use of mem_map, but as far as I know it uses FLATMEM and should be fine. Testing there would be helpful.

-apw

=== 8< ===
mem_map is part of the FLATMEM model

It seems that the definition and declaration of mem_map are inconsistent meaning we get usless undirected link failures about mem_map when its being used when it shouldn't be.

Reviewing mem_map, its actually only valid and initialised when CONFIG_FLATMEM is defined. Indeed in all essence it is part of that memory model used out of FLATMEM's __pfn_to_page etc. mem_map (and max_mapnr) should only be defined and declared when the FLATMEM memory model is selected.

---
 include/linux/mm.h     |    6 +++---
 include/linux/mmzone.h |    5 ++++-
 mm/memory.c            |    2 +-
 3 files changed, 8 insertions(+), 5 deletions(-)
include/linux/mm.h +3 -3
diff -upN reference/include/linux/mm.h current/include/linux/mm.h
@@ -19,7 +19,7 @@
 struct mempolicy;
 struct anon_vma;
 
-#ifndef CONFIG_DISCONTIGMEM          /* Don't use mapnrs, do it properly */
+#ifdef CONFIG_FLATMEM          /* Don't use mapnrs, do it properly */
 extern unsigned long max_mapnr;
 #endif
 
@@ -529,8 +529,8 @@ static inline void set_page_links(struct
 	set_page_section(page, pfn_to_section_nr(pfn));
 }
 
-#ifndef CONFIG_DISCONTIGMEM
-/* The array of struct pages - for discontigmem use pgdat->lmem_map */
+#ifdef CONFIG_FLATMEM
+/* The array of struct pages, only used in FLATMEM */
 extern struct page *mem_map;
 #endif
 
include/linux/mmzone.h +4 -1
diff -upN reference/include/linux/mmzone.h current/include/linux/mmzone.h
@@ -424,11 +424,14 @@ int percpu_pagelist_fraction_sysctl_hand
 #define numa_node_id()		(cpu_to_node(raw_smp_processor_id()))
 #endif
 
+#ifdef CONFIG_FLATMEM
+#define NODE_MEM_MAP(nid)	mem_map
+#endif
+
 #ifndef CONFIG_NEED_MULTIPLE_NODES
 
 extern struct pglist_data contig_page_data;
 #define NODE_DATA(nid)		(&contig_page_data)
-#define NODE_MEM_MAP(nid)	mem_map
 #define MAX_NODES_SHIFT		1
 
 #else /* CONFIG_NEED_MULTIPLE_NODES */
mm/memory.c +1 -1
diff -upN reference/mm/memory.c current/mm/memory.c
@@ -59,7 +59,7 @@
 #include <linux/swapops.h>
 #include <linux/elf.h>
 
-#ifndef CONFIG_NEED_MULTIPLE_NODES
+#ifdef CONFIG_FLATMEM
 /* use the per-pgdat data instead for discontigmem - mbligh */
 unsigned long max_mapnr;
 struct page *mem_map;
#3 lore raw

Re: [PATCH] mem_map is part of the FLATMEM model

Quoted 7 lines · Andy Whitcroft

mem_map is part of the FLATMEM model

It seems that the definition and declaration of mem_map are inconsistent meaning we get usless undirected link failures about mem_map when its being used when it shouldn't be.

Quoted 5 lines

Reviewing mem_map, its actually only valid and initialised when CONFIG_FLATMEM is defined. Indeed in all essence it is part of that memory model used out of FLATMEM's __pfn_to_page etc. mem_map (and max_mapnr) should only be defined and declared when the FLATMEM memory model is selected.

sparc64 allmodconfig:

arch/sparc64/mm/init.c: In function `paging_init':
arch/sparc64/mm/init.c:1339: error: `max_mapnr' undeclared (first use in this function) arch/sparc64/mm/init.c:1339: error: (Each undeclared identifier is reported only once