Skip to content

Commit 4bc277a

Browse files
committed
sh: bootmem refactoring.
This reworks much of the bootmem setup and initialization code allowing us to get rid of duplicate work between the NUMA and non-NUMA cases. The end result is that we end up with a much more flexible interface for supporting more complex topologies (fake NUMA, highmem, etc, etc.) which is entirely LMB backed. This is an incremental step for more NUMA work as well as gradually enabling migration off of bootmem entirely. Signed-off-by: Paul Mundt <lethal@linux-sh.org>
1 parent 5e2ff32 commit 4bc277a

4 files changed

Lines changed: 169 additions & 142 deletions

File tree

‎arch/sh/include/asm/mmzone.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ void __init plat_mem_setup(void);
4444
/* arch/sh/kernel/setup.c */
4545
void __init __add_active_range(unsigned int nid, unsigned long start_pfn,
4646
unsigned long end_pfn);
47+
/* arch/sh/mm/init.c */
48+
void __init allocate_pgdat(unsigned int nid);
4749

4850
#endif /* __KERNEL__ */
4951
#endif /* __ASM_SH_MMZONE_H */

‎arch/sh/include/asm/setup.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#define COMMAND_LINE ((char *) (PARAM+0x100))
2020

2121
void sh_mv_setup(void);
22+
void check_for_initrd(void);
2223

2324
#endif /* __KERNEL__ */
2425

‎arch/sh/kernel/setup.c‎

Lines changed: 4 additions & 139 deletions
Original file line numberDiff line numberDiff line change
@@ -114,31 +114,7 @@ static int __init early_parse_mem(char *p)
114114
}
115115
early_param("mem", early_parse_mem);
116116

117-
/*
118-
* Register fully available low RAM pages with the bootmem allocator.
119-
*/
120-
static void __init register_bootmem_low_pages(void)
121-
{
122-
unsigned long curr_pfn, last_pfn, pages;
123-
124-
/*
125-
* We are rounding up the start address of usable memory:
126-
*/
127-
curr_pfn = PFN_UP(__MEMORY_START);
128-
129-
/*
130-
* ... and at the end of the usable range downwards:
131-
*/
132-
last_pfn = PFN_DOWN(__pa(memory_end));
133-
134-
if (last_pfn > max_low_pfn)
135-
last_pfn = max_low_pfn;
136-
137-
pages = last_pfn - curr_pfn;
138-
free_bootmem(PFN_PHYS(curr_pfn), PFN_PHYS(pages));
139-
}
140-
141-
static void __init check_for_initrd(void)
117+
void __init check_for_initrd(void)
142118
{
143119
#ifdef CONFIG_BLK_DEV_INITRD
144120
unsigned long start, end;
@@ -240,85 +216,6 @@ void __init __add_active_range(unsigned int nid, unsigned long start_pfn,
240216
add_active_range(nid, start_pfn, end_pfn);
241217
}
242218

243-
void __init do_init_bootmem(void)
244-
{
245-
unsigned long bootmap_size;
246-
unsigned long bootmap_pages, bootmem_paddr;
247-
u64 total_pages = lmb_phys_mem_size() >> PAGE_SHIFT;
248-
int i;
249-
250-
bootmap_pages = bootmem_bootmap_pages(total_pages);
251-
252-
bootmem_paddr = lmb_alloc(bootmap_pages << PAGE_SHIFT, PAGE_SIZE);
253-
254-
/*
255-
* Find a proper area for the bootmem bitmap. After this
256-
* bootstrap step all allocations (until the page allocator
257-
* is intact) must be done via bootmem_alloc().
258-
*/
259-
bootmap_size = init_bootmem_node(NODE_DATA(0),
260-
bootmem_paddr >> PAGE_SHIFT,
261-
min_low_pfn, max_low_pfn);
262-
263-
/* Add active regions with valid PFNs. */
264-
for (i = 0; i < lmb.memory.cnt; i++) {
265-
unsigned long start_pfn, end_pfn;
266-
start_pfn = lmb.memory.region[i].base >> PAGE_SHIFT;
267-
end_pfn = start_pfn + lmb_size_pages(&lmb.memory, i);
268-
__add_active_range(0, start_pfn, end_pfn);
269-
}
270-
271-
/*
272-
* Add all physical memory to the bootmem map and mark each
273-
* area as present.
274-
*/
275-
register_bootmem_low_pages();
276-
277-
/* Reserve the sections we're already using. */
278-
for (i = 0; i < lmb.reserved.cnt; i++)
279-
reserve_bootmem(lmb.reserved.region[i].base,
280-
lmb_size_bytes(&lmb.reserved, i),
281-
BOOTMEM_DEFAULT);
282-
283-
node_set_online(0);
284-
285-
sparse_memory_present_with_active_regions(0);
286-
}
287-
288-
static void __init early_reserve_mem(void)
289-
{
290-
unsigned long start_pfn;
291-
292-
/*
293-
* Partially used pages are not usable - thus
294-
* we are rounding upwards:
295-
*/
296-
start_pfn = PFN_UP(__pa(_end));
297-
298-
/*
299-
* Reserve the kernel text and
300-
* Reserve the bootmem bitmap. We do this in two steps (first step
301-
* was init_bootmem()), because this catches the (definitely buggy)
302-
* case of us accidentally initializing the bootmem allocator with
303-
* an invalid RAM area.
304-
*/
305-
lmb_reserve(__MEMORY_START + CONFIG_ZERO_PAGE_OFFSET,
306-
(PFN_PHYS(start_pfn) + PAGE_SIZE - 1) -
307-
(__MEMORY_START + CONFIG_ZERO_PAGE_OFFSET));
308-
309-
/*
310-
* Reserve physical pages below CONFIG_ZERO_PAGE_OFFSET.
311-
*/
312-
if (CONFIG_ZERO_PAGE_OFFSET != 0)
313-
lmb_reserve(__MEMORY_START, CONFIG_ZERO_PAGE_OFFSET);
314-
315-
/*
316-
* Handle additional early reservations
317-
*/
318-
check_for_initrd();
319-
reserve_crashkernel();
320-
}
321-
322219
/*
323220
* Note: elfcorehdr_addr is not just limited to vmcore. It is also used by
324221
* is_kdump_kernel() to determine if we are booting after a panic. Hence
@@ -342,10 +239,6 @@ void __init __weak plat_early_device_setup(void)
342239
{
343240
}
344241

345-
void __init __weak plat_mem_setup(void)
346-
{
347-
}
348-
349242
void __init setup_arch(char **cmdline_p)
350243
{
351244
enable_mmu();
@@ -401,44 +294,16 @@ void __init setup_arch(char **cmdline_p)
401294

402295
plat_early_device_setup();
403296

404-
/* Let earlyprintk output early console messages */
405-
early_platform_driver_probe("earlyprintk", 1, 1);
406-
407-
lmb_init();
408-
409297
sh_mv_setup();
410-
sh_mv.mv_mem_init();
411-
412-
early_reserve_mem();
413298

414-
lmb_enforce_memory_limit(memory_limit);
415-
lmb_analyze();
416-
417-
lmb_dump_all();
418-
419-
/*
420-
* Determine low and high memory ranges:
421-
*/
422-
max_low_pfn = max_pfn = lmb_end_of_DRAM() >> PAGE_SHIFT;
423-
min_low_pfn = __MEMORY_START >> PAGE_SHIFT;
424-
425-
nodes_clear(node_online_map);
426-
427-
memory_start = (unsigned long)__va(__MEMORY_START);
428-
memory_end = memory_start + (memory_limit ?: lmb_phys_mem_size());
299+
/* Let earlyprintk output early console messages */
300+
early_platform_driver_probe("earlyprintk", 1, 1);
429301

430-
uncached_init();
431-
pmb_init();
432-
do_init_bootmem();
433-
plat_mem_setup();
434-
sparse_init();
302+
paging_init();
435303

436304
#ifdef CONFIG_DUMMY_CONSOLE
437305
conswitchp = &dummy_con;
438306
#endif
439-
paging_init();
440-
441-
ioremap_fixed_init();
442307

443308
/* Perform the machine specific initialisation */
444309
if (likely(sh_mv.mv_setup))

‎arch/sh/mm/init.c‎

Lines changed: 162 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,14 @@
1717
#include <linux/percpu.h>
1818
#include <linux/io.h>
1919
#include <linux/lmb.h>
20+
#include <linux/kexec.h>
2021
#include <linux/dma-mapping.h>
2122
#include <asm/mmu_context.h>
23+
#include <asm/mmzone.h>
2224
#include <asm/tlb.h>
2325
#include <asm/cacheflush.h>
2426
#include <asm/sections.h>
27+
#include <asm/setup.h>
2528
#include <asm/cache.h>
2629
#include <asm/sizes.h>
2730

@@ -33,6 +36,11 @@ void __init generic_mem_init(void)
3336
lmb_add(__MEMORY_START, __MEMORY_SIZE);
3437
}
3538

39+
void __init __weak plat_mem_setup(void)
40+
{
41+
/* Nothing to see here, move along. */
42+
}
43+
3644
#ifdef CONFIG_MMU
3745
static pte_t *__get_pte_phys(unsigned long addr)
3846
{
@@ -158,15 +166,166 @@ void __init page_table_range_init(unsigned long start, unsigned long end,
158166
}
159167
#endif /* CONFIG_MMU */
160168

161-
/*
162-
* paging_init() sets up the page tables
163-
*/
169+
void __init allocate_pgdat(unsigned int nid)
170+
{
171+
unsigned long start_pfn, end_pfn;
172+
#ifdef CONFIG_NEED_MULTIPLE_NODES
173+
unsigned long phys;
174+
#endif
175+
176+
get_pfn_range_for_nid(nid, &start_pfn, &end_pfn);
177+
178+
#ifdef CONFIG_NEED_MULTIPLE_NODES
179+
phys = __lmb_alloc_base(sizeof(struct pglist_data),
180+
SMP_CACHE_BYTES, end_pfn << PAGE_SHIFT);
181+
/* Retry with all of system memory */
182+
if (!phys)
183+
phys = __lmb_alloc_base(sizeof(struct pglist_data),
184+
SMP_CACHE_BYTES, lmb_end_of_DRAM());
185+
if (!phys)
186+
panic("Can't allocate pgdat for node %d\n", nid);
187+
188+
NODE_DATA(nid) = __va(phys);
189+
memset(NODE_DATA(nid), 0, sizeof(struct pglist_data));
190+
191+
NODE_DATA(nid)->bdata = &bootmem_node_data[nid];
192+
#endif
193+
194+
NODE_DATA(nid)->node_start_pfn = start_pfn;
195+
NODE_DATA(nid)->node_spanned_pages = end_pfn - start_pfn;
196+
}
197+
198+
static void __init bootmem_init_one_node(unsigned int nid)
199+
{
200+
unsigned long total_pages, paddr;
201+
unsigned long end_pfn;
202+
struct pglist_data *p;
203+
int i;
204+
205+
p = NODE_DATA(nid);
206+
207+
/* Nothing to do.. */
208+
if (!p->node_spanned_pages)
209+
return;
210+
211+
end_pfn = p->node_start_pfn + p->node_spanned_pages;
212+
213+
total_pages = bootmem_bootmap_pages(p->node_spanned_pages);
214+
215+
paddr = lmb_alloc(total_pages << PAGE_SHIFT, PAGE_SIZE);
216+
if (!paddr)
217+
panic("Can't allocate bootmap for nid[%d]\n", nid);
218+
219+
init_bootmem_node(p, paddr >> PAGE_SHIFT, p->node_start_pfn, end_pfn);
220+
221+
free_bootmem_with_active_regions(nid, end_pfn);
222+
223+
/*
224+
* XXX Handle initial reservations for the system memory node
225+
* only for the moment, we'll refactor this later for handling
226+
* reservations in other nodes.
227+
*/
228+
if (nid == 0) {
229+
/* Reserve the sections we're already using. */
230+
for (i = 0; i < lmb.reserved.cnt; i++)
231+
reserve_bootmem(lmb.reserved.region[i].base,
232+
lmb_size_bytes(&lmb.reserved, i),
233+
BOOTMEM_DEFAULT);
234+
}
235+
236+
sparse_memory_present_with_active_regions(nid);
237+
}
238+
239+
static void __init do_init_bootmem(void)
240+
{
241+
int i;
242+
243+
/* Add active regions with valid PFNs. */
244+
for (i = 0; i < lmb.memory.cnt; i++) {
245+
unsigned long start_pfn, end_pfn;
246+
start_pfn = lmb.memory.region[i].base >> PAGE_SHIFT;
247+
end_pfn = start_pfn + lmb_size_pages(&lmb.memory, i);
248+
__add_active_range(0, start_pfn, end_pfn);
249+
}
250+
251+
/* All of system RAM sits in node 0 for the non-NUMA case */
252+
allocate_pgdat(0);
253+
node_set_online(0);
254+
255+
plat_mem_setup();
256+
257+
for_each_online_node(i)
258+
bootmem_init_one_node(i);
259+
260+
sparse_init();
261+
}
262+
263+
static void __init early_reserve_mem(void)
264+
{
265+
unsigned long start_pfn;
266+
267+
/*
268+
* Partially used pages are not usable - thus
269+
* we are rounding upwards:
270+
*/
271+
start_pfn = PFN_UP(__pa(_end));
272+
273+
/*
274+
* Reserve the kernel text and Reserve the bootmem bitmap. We do
275+
* this in two steps (first step was init_bootmem()), because
276+
* this catches the (definitely buggy) case of us accidentally
277+
* initializing the bootmem allocator with an invalid RAM area.
278+
*/
279+
lmb_reserve(__MEMORY_START + CONFIG_ZERO_PAGE_OFFSET,
280+
(PFN_PHYS(start_pfn) + PAGE_SIZE - 1) -
281+
(__MEMORY_START + CONFIG_ZERO_PAGE_OFFSET));
282+
283+
/*
284+
* Reserve physical pages below CONFIG_ZERO_PAGE_OFFSET.
285+
*/
286+
if (CONFIG_ZERO_PAGE_OFFSET != 0)
287+
lmb_reserve(__MEMORY_START, CONFIG_ZERO_PAGE_OFFSET);
288+
289+
/*
290+
* Handle additional early reservations
291+
*/
292+
check_for_initrd();
293+
reserve_crashkernel();
294+
}
295+
164296
void __init paging_init(void)
165297
{
166298
unsigned long max_zone_pfns[MAX_NR_ZONES];
167299
unsigned long vaddr, end;
168300
int nid;
169301

302+
lmb_init();
303+
304+
sh_mv.mv_mem_init();
305+
306+
early_reserve_mem();
307+
308+
lmb_enforce_memory_limit(memory_limit);
309+
lmb_analyze();
310+
311+
lmb_dump_all();
312+
313+
/*
314+
* Determine low and high memory ranges:
315+
*/
316+
max_low_pfn = max_pfn = lmb_end_of_DRAM() >> PAGE_SHIFT;
317+
min_low_pfn = __MEMORY_START >> PAGE_SHIFT;
318+
319+
nodes_clear(node_online_map);
320+
321+
memory_start = (unsigned long)__va(__MEMORY_START);
322+
memory_end = memory_start + (memory_limit ?: lmb_phys_mem_size());
323+
324+
uncached_init();
325+
pmb_init();
326+
do_init_bootmem();
327+
ioremap_fixed_init();
328+
170329
/* We don't need to map the kernel through the TLB, as
171330
* it is permanatly mapped using P1. So clear the
172331
* entire pgd. */

0 commit comments

Comments
 (0)