2 * mm_init.c - Memory initialisation verification and debugging
4 * Copyright 2008 IBM Corporation, 2008
5 * Author Mel Gorman <mel@csn.ul.ie>
8 #include <linux/kernel.h>
9 #include <linux/init.h>
10 #include <linux/kobject.h>
11 #include <linux/module.h>
14 #ifdef CONFIG_DEBUG_MEMORY_INIT
15 int __meminitdata mminit_loglevel
;
17 /* The zonelists are simply reported, validation is manual. */
18 void mminit_verify_zonelist(void)
22 if (mminit_loglevel
< MMINIT_VERIFY
)
25 for_each_online_node(nid
) {
26 pg_data_t
*pgdat
= NODE_DATA(nid
);
29 struct zonelist
*zonelist
;
30 int i
, listid
, zoneid
;
32 BUG_ON(MAX_ZONELISTS
> 2);
33 for (i
= 0; i
< MAX_ZONELISTS
* MAX_NR_ZONES
; i
++) {
35 /* Identify the zone and nodelist */
36 zoneid
= i
% MAX_NR_ZONES
;
37 listid
= i
/ MAX_NR_ZONES
;
38 zonelist
= &pgdat
->node_zonelists
[listid
];
39 zone
= &pgdat
->node_zones
[zoneid
];
40 if (!populated_zone(zone
))
43 /* Print information about the zonelist */
44 printk(KERN_DEBUG
"mminit::zonelist %s %d:%s = ",
45 listid
> 0 ? "thisnode" : "general", nid
,
48 /* Iterate the zonelist */
49 for_each_zone_zonelist(zone
, z
, zonelist
, zoneid
) {
51 printk(KERN_CONT
"%d:%s ",
52 zone
->node
, zone
->name
);
54 printk(KERN_CONT
"0:%s ", zone
->name
);
55 #endif /* CONFIG_NUMA */
57 printk(KERN_CONT
"\n");
62 void __init
mminit_verify_pageflags_layout(void)
65 unsigned long or_mask
, add_mask
;
67 shift
= 8 * sizeof(unsigned long);
68 width
= shift
- SECTIONS_WIDTH
- NODES_WIDTH
- ZONES_WIDTH
;
69 mminit_dprintk(MMINIT_TRACE
, "pageflags_layout_widths",
70 "Section %d Node %d Zone %d Flags %d\n",
75 mminit_dprintk(MMINIT_TRACE
, "pageflags_layout_shifts",
76 "Section %d Node %d Zone %d\n",
84 mminit_dprintk(MMINIT_TRACE
, "pageflags_layout_offsets",
85 "Section %lu Node %lu Zone %lu\n",
86 (unsigned long)SECTIONS_PGSHIFT
,
87 (unsigned long)NODES_PGSHIFT
,
88 (unsigned long)ZONES_PGSHIFT
);
89 mminit_dprintk(MMINIT_TRACE
, "pageflags_layout_zoneid",
90 "Zone ID: %lu -> %lu\n",
91 (unsigned long)ZONEID_PGOFF
,
92 (unsigned long)(ZONEID_PGOFF
+ ZONEID_SHIFT
));
93 mminit_dprintk(MMINIT_TRACE
, "pageflags_layout_usage",
94 "location: %d -> %d unused %d -> %d flags %d -> %d\n",
95 shift
, width
, width
, NR_PAGEFLAGS
, NR_PAGEFLAGS
, 0);
96 #ifdef NODE_NOT_IN_PAGE_FLAGS
97 mminit_dprintk(MMINIT_TRACE
, "pageflags_layout_nodeflags",
98 "Node not in page flags");
101 if (SECTIONS_WIDTH
) {
102 shift
-= SECTIONS_WIDTH
;
103 BUG_ON(shift
!= SECTIONS_PGSHIFT
);
106 shift
-= NODES_WIDTH
;
107 BUG_ON(shift
!= NODES_PGSHIFT
);
110 shift
-= ZONES_WIDTH
;
111 BUG_ON(shift
!= ZONES_PGSHIFT
);
114 /* Check for bitmask overlaps */
115 or_mask
= (ZONES_MASK
<< ZONES_PGSHIFT
) |
116 (NODES_MASK
<< NODES_PGSHIFT
) |
117 (SECTIONS_MASK
<< SECTIONS_PGSHIFT
);
118 add_mask
= (ZONES_MASK
<< ZONES_PGSHIFT
) +
119 (NODES_MASK
<< NODES_PGSHIFT
) +
120 (SECTIONS_MASK
<< SECTIONS_PGSHIFT
);
121 BUG_ON(or_mask
!= add_mask
);
124 void __meminit
mminit_verify_page_links(struct page
*page
, enum zone_type zone
,
125 unsigned long nid
, unsigned long pfn
)
127 BUG_ON(page_to_nid(page
) != nid
);
128 BUG_ON(page_zonenum(page
) != zone
);
129 BUG_ON(page_to_pfn(page
) != pfn
);
132 static __init
int set_mminit_loglevel(char *str
)
134 get_option(&str
, &mminit_loglevel
);
137 early_param("mminit_loglevel", set_mminit_loglevel
);
138 #endif /* CONFIG_DEBUG_MEMORY_INIT */
140 struct kobject
*mm_kobj
;
141 EXPORT_SYMBOL_GPL(mm_kobj
);
143 static int __init
mm_sysfs_init(void)
145 mm_kobj
= kobject_create_and_add("mm", kernel_kobj
);
152 __initcall(mm_sysfs_init
);