1111#include <linux/kernel.h>
1212#include <linux/mm.h>
1313#include <linux/bootmem.h>
14+ #include <linux/memblock.h>
1415#include <linux/swap.h>
1516#include <linux/initrd.h>
1617#include <linux/pfn.h>
@@ -59,12 +60,10 @@ setup_memory_node(int nid, void *kernel_end)
5960 struct memclust_struct * cluster ;
6061 struct memdesc_struct * memdesc ;
6162 unsigned long start_kernel_pfn , end_kernel_pfn ;
62- unsigned long bootmap_size , bootmap_pages , bootmap_start ;
6363 unsigned long start , end ;
6464 unsigned long node_pfn_start , node_pfn_end ;
6565 unsigned long node_min_pfn , node_max_pfn ;
6666 int i ;
67- unsigned long node_datasz = PFN_UP (sizeof (pg_data_t ));
6867 int show_init = 0 ;
6968
7069 /* Find the bounds of current node */
@@ -134,24 +133,14 @@ setup_memory_node(int nid, void *kernel_end)
134133 /* Cute trick to make sure our local node data is on local memory */
135134 node_data [nid ] = (pg_data_t * )(__va (node_min_pfn << PAGE_SHIFT ));
136135#endif
137- /* Quasi-mark the pg_data_t as in-use */
138- node_min_pfn += node_datasz ;
139- if (node_min_pfn >= node_max_pfn ) {
140- printk (" not enough mem to reserve NODE_DATA" );
141- return ;
142- }
143- NODE_DATA (nid )-> bdata = & bootmem_node_data [nid ];
144-
145136 printk (" Detected node memory: start %8lu, end %8lu\n" ,
146137 node_min_pfn , node_max_pfn );
147138
148139 DBGDCONT (" DISCONTIG: node_data[%d] is at 0x%p\n" , nid , NODE_DATA (nid ));
149- DBGDCONT (" DISCONTIG: NODE_DATA(%d)->bdata is at 0x%p\n" , nid , NODE_DATA (nid )-> bdata );
150140
151141 /* Find the bounds of kernel memory. */
152142 start_kernel_pfn = PFN_DOWN (KERNEL_START_PHYS );
153143 end_kernel_pfn = PFN_UP (virt_to_phys (kernel_end ));
154- bootmap_start = -1 ;
155144
156145 if (!nid && (node_max_pfn < end_kernel_pfn || node_min_pfn > start_kernel_pfn ))
157146 panic ("kernel loaded out of ram" );
@@ -161,96 +150,19 @@ setup_memory_node(int nid, void *kernel_end)
161150 has much larger alignment than 8Mb, so it's safe. */
162151 node_min_pfn &= ~((1UL << (MAX_ORDER - 1 ))- 1 );
163152
164- /* We need to know how many physically contiguous pages
165- we'll need for the bootmap. */
166- bootmap_pages = bootmem_bootmap_pages (node_max_pfn - node_min_pfn );
167-
168- /* Now find a good region where to allocate the bootmap. */
169- for_each_mem_cluster (memdesc , cluster , i ) {
170- if (cluster -> usage & 3 )
171- continue ;
172-
173- start = cluster -> start_pfn ;
174- end = start + cluster -> numpages ;
175-
176- if (start >= node_max_pfn || end <= node_min_pfn )
177- continue ;
178-
179- if (end > node_max_pfn )
180- end = node_max_pfn ;
181- if (start < node_min_pfn )
182- start = node_min_pfn ;
183-
184- if (start < start_kernel_pfn ) {
185- if (end > end_kernel_pfn
186- && end - end_kernel_pfn >= bootmap_pages ) {
187- bootmap_start = end_kernel_pfn ;
188- break ;
189- } else if (end > start_kernel_pfn )
190- end = start_kernel_pfn ;
191- } else if (start < end_kernel_pfn )
192- start = end_kernel_pfn ;
193- if (end - start >= bootmap_pages ) {
194- bootmap_start = start ;
195- break ;
196- }
197- }
198-
199- if (bootmap_start == -1 )
200- panic ("couldn't find a contiguous place for the bootmap" );
201-
202- /* Allocate the bootmap and mark the whole MM as reserved. */
203- bootmap_size = init_bootmem_node (NODE_DATA (nid ), bootmap_start ,
204- node_min_pfn , node_max_pfn );
205- DBGDCONT (" bootmap_start %lu, bootmap_size %lu, bootmap_pages %lu\n" ,
206- bootmap_start , bootmap_size , bootmap_pages );
153+ memblock_add (PFN_PHYS (node_min_pfn ),
154+ (node_max_pfn - node_min_pfn ) << PAGE_SHIFT );
207155
208- /* Mark the free regions. */
209- for_each_mem_cluster (memdesc , cluster , i ) {
210- if (cluster -> usage & 3 )
211- continue ;
212-
213- start = cluster -> start_pfn ;
214- end = cluster -> start_pfn + cluster -> numpages ;
215-
216- if (start >= node_max_pfn || end <= node_min_pfn )
217- continue ;
218-
219- if (end > node_max_pfn )
220- end = node_max_pfn ;
221- if (start < node_min_pfn )
222- start = node_min_pfn ;
223-
224- if (start < start_kernel_pfn ) {
225- if (end > end_kernel_pfn ) {
226- free_bootmem_node (NODE_DATA (nid ), PFN_PHYS (start ),
227- (PFN_PHYS (start_kernel_pfn )
228- - PFN_PHYS (start )));
229- printk (" freeing pages %ld:%ld\n" ,
230- start , start_kernel_pfn );
231- start = end_kernel_pfn ;
232- } else if (end > start_kernel_pfn )
233- end = start_kernel_pfn ;
234- } else if (start < end_kernel_pfn )
235- start = end_kernel_pfn ;
236- if (start >= end )
237- continue ;
238-
239- free_bootmem_node (NODE_DATA (nid ), PFN_PHYS (start ), PFN_PHYS (end ) - PFN_PHYS (start ));
240- printk (" freeing pages %ld:%ld\n" , start , end );
241- }
242-
243- /* Reserve the bootmap memory. */
244- reserve_bootmem_node (NODE_DATA (nid ), PFN_PHYS (bootmap_start ),
245- bootmap_size , BOOTMEM_DEFAULT );
246- printk (" reserving pages %ld:%ld\n" , bootmap_start , bootmap_start + PFN_UP (bootmap_size ));
156+ NODE_DATA (nid )-> node_start_pfn = node_min_pfn ;
157+ NODE_DATA (nid )-> node_present_pages = node_max_pfn - node_min_pfn ;
247158
248159 node_set_online (nid );
249160}
250161
251162void __init
252163setup_memory (void * kernel_end )
253164{
165+ unsigned long kernel_size ;
254166 int nid ;
255167
256168 show_mem_layout ();
@@ -262,6 +174,9 @@ setup_memory(void *kernel_end)
262174 for (nid = 0 ; nid < MAX_NUMNODES ; nid ++ )
263175 setup_memory_node (nid , kernel_end );
264176
177+ kernel_size = virt_to_phys (kernel_end ) - KERNEL_START_PHYS ;
178+ memblock_reserve (KERNEL_START_PHYS , kernel_size );
179+
265180#ifdef CONFIG_BLK_DEV_INITRD
266181 initrd_start = INITRD_START ;
267182 if (initrd_start ) {
@@ -279,9 +194,8 @@ setup_memory(void *kernel_end)
279194 phys_to_virt (PFN_PHYS (max_low_pfn )));
280195 } else {
281196 nid = kvaddr_to_nid (initrd_start );
282- reserve_bootmem_node (NODE_DATA (nid ),
283- virt_to_phys ((void * )initrd_start ),
284- INITRD_SIZE , BOOTMEM_DEFAULT );
197+ memblock_reserve (virt_to_phys ((void * )initrd_start ),
198+ INITRD_SIZE );
285199 }
286200 }
287201#endif /* CONFIG_BLK_DEV_INITRD */
@@ -303,9 +217,8 @@ void __init paging_init(void)
303217 dma_local_pfn = virt_to_phys ((char * )MAX_DMA_ADDRESS ) >> PAGE_SHIFT ;
304218
305219 for_each_online_node (nid ) {
306- bootmem_data_t * bdata = & bootmem_node_data [nid ];
307- unsigned long start_pfn = bdata -> node_min_pfn ;
308- unsigned long end_pfn = bdata -> node_low_pfn ;
220+ unsigned long start_pfn = NODE_DATA (nid )-> node_start_pfn ;
221+ unsigned long end_pfn = start_pfn + NODE_DATA (nid )-> node_present_pages ;
309222
310223 if (dma_local_pfn >= end_pfn - start_pfn )
311224 zones_size [ZONE_DMA ] = end_pfn - start_pfn ;
0 commit comments