1 // SPDX-License-Identifier: GPL-2.0-only
3 * mm_init.c - Memory initialisation verification and debugging
5 * Copyright 2008 IBM Corporation, 2008
6 * Author Mel Gorman <mel@csn.ul.ie>
9 #include <linux/kernel.h>
10 #include <linux/init.h>
11 #include <linux/kobject.h>
12 #include <linux/export.h>
13 #include <linux/memory.h>
14 #include <linux/notifier.h>
15 #include <linux/sched.h>
18 #ifdef CONFIG_DEBUG_MEMORY_INIT
19 int __meminitdata mminit_loglevel
;
21 #ifndef SECTIONS_SHIFT
22 #define SECTIONS_SHIFT 0
25 /* The zonelists are simply reported, validation is manual. */
26 void __init
mminit_verify_zonelist(void)
30 if (mminit_loglevel
< MMINIT_VERIFY
)
33 for_each_online_node(nid
) {
34 pg_data_t
*pgdat
= NODE_DATA(nid
);
37 struct zonelist
*zonelist
;
38 int i
, listid
, zoneid
;
40 BUG_ON(MAX_ZONELISTS
> 2);
41 for (i
= 0; i
< MAX_ZONELISTS
* MAX_NR_ZONES
; i
++) {
43 /* Identify the zone and nodelist */
44 zoneid
= i
% MAX_NR_ZONES
;
45 listid
= i
/ MAX_NR_ZONES
;
46 zonelist
= &pgdat
->node_zonelists
[listid
];
47 zone
= &pgdat
->node_zones
[zoneid
];
48 if (!populated_zone(zone
))
51 /* Print information about the zonelist */
52 printk(KERN_DEBUG
"mminit::zonelist %s %d:%s = ",
53 listid
> 0 ? "thisnode" : "general", nid
,
56 /* Iterate the zonelist */
57 for_each_zone_zonelist(zone
, z
, zonelist
, zoneid
)
58 pr_cont("%d:%s ", zone_to_nid(zone
), zone
->name
);
64 void __init
mminit_verify_pageflags_layout(void)
67 unsigned long or_mask
, add_mask
;
69 shift
= 8 * sizeof(unsigned long);
70 width
= shift
- SECTIONS_WIDTH
- NODES_WIDTH
- ZONES_WIDTH
- LAST_CPUPID_SHIFT
;
71 mminit_dprintk(MMINIT_TRACE
, "pageflags_layout_widths",
72 "Section %d Node %d Zone %d Lastcpupid %d Flags %d\n",
78 mminit_dprintk(MMINIT_TRACE
, "pageflags_layout_shifts",
79 "Section %d Node %d Zone %d Lastcpupid %d\n",
84 mminit_dprintk(MMINIT_TRACE
, "pageflags_layout_pgshifts",
85 "Section %lu Node %lu Zone %lu Lastcpupid %lu\n",
86 (unsigned long)SECTIONS_PGSHIFT
,
87 (unsigned long)NODES_PGSHIFT
,
88 (unsigned long)ZONES_PGSHIFT
,
89 (unsigned long)LAST_CPUPID_PGSHIFT
);
90 mminit_dprintk(MMINIT_TRACE
, "pageflags_layout_nodezoneid",
91 "Node/Zone ID: %lu -> %lu\n",
92 (unsigned long)(ZONEID_PGOFF
+ ZONEID_SHIFT
),
93 (unsigned long)ZONEID_PGOFF
);
94 mminit_dprintk(MMINIT_TRACE
, "pageflags_layout_usage",
95 "location: %d -> %d layout %d -> %d unused %d -> %d page-flags\n",
96 shift
, width
, width
, NR_PAGEFLAGS
, NR_PAGEFLAGS
, 0);
97 #ifdef NODE_NOT_IN_PAGE_FLAGS
98 mminit_dprintk(MMINIT_TRACE
, "pageflags_layout_nodeflags",
99 "Node not in page flags");
101 #ifdef LAST_CPUPID_NOT_IN_PAGE_FLAGS
102 mminit_dprintk(MMINIT_TRACE
, "pageflags_layout_nodeflags",
103 "Last cpupid not in page flags");
106 if (SECTIONS_WIDTH
) {
107 shift
-= SECTIONS_WIDTH
;
108 BUG_ON(shift
!= SECTIONS_PGSHIFT
);
111 shift
-= NODES_WIDTH
;
112 BUG_ON(shift
!= NODES_PGSHIFT
);
115 shift
-= ZONES_WIDTH
;
116 BUG_ON(shift
!= ZONES_PGSHIFT
);
119 /* Check for bitmask overlaps */
120 or_mask
= (ZONES_MASK
<< ZONES_PGSHIFT
) |
121 (NODES_MASK
<< NODES_PGSHIFT
) |
122 (SECTIONS_MASK
<< SECTIONS_PGSHIFT
);
123 add_mask
= (ZONES_MASK
<< ZONES_PGSHIFT
) +
124 (NODES_MASK
<< NODES_PGSHIFT
) +
125 (SECTIONS_MASK
<< SECTIONS_PGSHIFT
);
126 BUG_ON(or_mask
!= add_mask
);
129 static __init
int set_mminit_loglevel(char *str
)
131 get_option(&str
, &mminit_loglevel
);
134 early_param("mminit_loglevel", set_mminit_loglevel
);
135 #endif /* CONFIG_DEBUG_MEMORY_INIT */
137 struct kobject
*mm_kobj
;
138 EXPORT_SYMBOL_GPL(mm_kobj
);
141 s32 vm_committed_as_batch
= 32;
143 static void __meminit
mm_compute_batch(void)
146 s32 nr
= num_present_cpus();
147 s32 batch
= max_t(s32
, nr
*2, 32);
149 /* batch size set to 0.4% of (total memory/#cpus), or max int32 */
150 memsized_batch
= min_t(u64
, (totalram_pages()/nr
)/256, 0x7fffffff);
152 vm_committed_as_batch
= max_t(s32
, memsized_batch
, batch
);
155 static int __meminit
mm_compute_batch_notifier(struct notifier_block
*self
,
156 unsigned long action
, void *arg
)
168 static struct notifier_block compute_batch_nb __meminitdata
= {
169 .notifier_call
= mm_compute_batch_notifier
,
170 .priority
= IPC_CALLBACK_PRI
, /* use lowest priority */
173 static int __init
mm_compute_batch_init(void)
176 register_hotmemory_notifier(&compute_batch_nb
);
181 __initcall(mm_compute_batch_init
);
185 static int __init
mm_sysfs_init(void)
187 mm_kobj
= kobject_create_and_add("mm", kernel_kobj
);
193 postcore_initcall(mm_sysfs_init
);