Skip to content

Commit 5e2ff32

Browse files
committed
sh: rework memory limits to work with LMB.
This reworks the memory limit handling to tie in through the available LMB infrastructure. This requires a bit of reordering as we need to have all of the LMB reservations taken care of prior to establishing the limits. While we're at it, the crash kernel reservation semantics are reworked so that we allocate from the bottom up and reduce the risk of having to disable the memory limit due to a clash with the crash kernel reservation. Signed-off-by: Paul Mundt <lethal@linux-sh.org>
1 parent 19d8f84 commit 5e2ff32

3 files changed

Lines changed: 40 additions & 45 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949

5050
extern unsigned long shm_align_mask;
5151
extern unsigned long max_low_pfn, min_low_pfn;
52-
extern unsigned long memory_start, memory_end;
52+
extern unsigned long memory_start, memory_end, memory_limit;
5353

5454
static inline unsigned long
5555
pages_do_alias(unsigned long addr1, unsigned long addr2)

‎arch/sh/kernel/machine_kexec.c‎

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,8 @@ void __init reserve_crashkernel(void)
169169

170170
crash_size = PAGE_ALIGN(crashk_res.end - crashk_res.start + 1);
171171
if (!crashk_res.start) {
172-
crashk_res.start = lmb_alloc(crash_size, PAGE_SIZE);
172+
unsigned long max = lmb_end_of_DRAM() - memory_limit;
173+
crashk_res.start = __lmb_alloc_base(crash_size, PAGE_SIZE, max);
173174
if (!crashk_res.start) {
174175
pr_err("crashkernel allocation failed\n");
175176
goto disable;
@@ -183,15 +184,22 @@ void __init reserve_crashkernel(void)
183184
}
184185
}
185186

186-
pr_info("Reserving %ldMB of memory at %ldMB "
187+
crashk_res.end = crashk_res.start + crash_size - 1;
188+
189+
/*
190+
* Crash kernel trumps memory limit
191+
*/
192+
if ((lmb_end_of_DRAM() - memory_limit) <= crashk_res.end) {
193+
memory_limit = 0;
194+
pr_info("Disabled memory limit for crashkernel\n");
195+
}
196+
197+
pr_info("Reserving %ldMB of memory at 0x%08lx "
187198
"for crashkernel (System RAM: %ldMB)\n",
188199
(unsigned long)(crash_size >> 20),
189-
(unsigned long)(crashk_res.start >> 20),
200+
(unsigned long)(crashk_res.start),
190201
(unsigned long)(lmb_phys_mem_size() >> 20));
191202

192-
crashk_res.end = crashk_res.start + crash_size - 1;
193-
insert_resource(&iomem_resource, &crashk_res);
194-
195203
return;
196204

197205
disable:

‎arch/sh/kernel/setup.c‎

Lines changed: 25 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -95,28 +95,20 @@ unsigned long memory_start;
9595
EXPORT_SYMBOL(memory_start);
9696
unsigned long memory_end = 0;
9797
EXPORT_SYMBOL(memory_end);
98+
unsigned long memory_limit = 0;
9899

99100
static struct resource mem_resources[MAX_NUMNODES];
100101

101102
int l1i_cache_shape, l1d_cache_shape, l2_cache_shape;
102103

103104
static int __init early_parse_mem(char *p)
104105
{
105-
unsigned long size;
106+
if (!p)
107+
return 1;
106108

107-
memory_start = (unsigned long)__va(__MEMORY_START);
108-
size = memparse(p, &p);
109-
110-
if (size > __MEMORY_SIZE) {
111-
printk(KERN_ERR
112-
"Using mem= to increase the size of kernel memory "
113-
"is not allowed.\n"
114-
" Recompile the kernel with the correct value for "
115-
"CONFIG_MEMORY_SIZE.\n");
116-
return 0;
117-
}
109+
memory_limit = PAGE_ALIGN(memparse(p, &p));
118110

119-
memory_end = memory_start + size;
111+
pr_notice("Memory limited to %ldMB\n", memory_limit >> 20);
120112

121113
return 0;
122114
}
@@ -252,7 +244,7 @@ void __init do_init_bootmem(void)
252244
{
253245
unsigned long bootmap_size;
254246
unsigned long bootmap_pages, bootmem_paddr;
255-
u64 total_pages = (lmb_end_of_DRAM() - __MEMORY_START) >> PAGE_SHIFT;
247+
u64 total_pages = lmb_phys_mem_size() >> PAGE_SHIFT;
256248
int i;
257249

258250
bootmap_pages = bootmem_bootmap_pages(total_pages);
@@ -276,12 +268,6 @@ void __init do_init_bootmem(void)
276268
__add_active_range(0, start_pfn, end_pfn);
277269
}
278270

279-
/*
280-
* Handle additional early reservations
281-
*/
282-
check_for_initrd();
283-
reserve_crashkernel();
284-
285271
/*
286272
* Add all physical memory to the bootmem map and mark each
287273
* area as present.
@@ -299,7 +285,7 @@ void __init do_init_bootmem(void)
299285
sparse_memory_present_with_active_regions(0);
300286
}
301287

302-
static void __init setup_memory(void)
288+
static void __init early_reserve_mem(void)
303289
{
304290
unsigned long start_pfn;
305291

@@ -326,11 +312,11 @@ static void __init setup_memory(void)
326312
if (CONFIG_ZERO_PAGE_OFFSET != 0)
327313
lmb_reserve(__MEMORY_START, CONFIG_ZERO_PAGE_OFFSET);
328314

329-
lmb_analyze();
330-
lmb_dump_all();
331-
332-
do_init_bootmem();
333-
plat_mem_setup();
315+
/*
316+
* Handle additional early reservations
317+
*/
318+
check_for_initrd();
319+
reserve_crashkernel();
334320
}
335321

336322
/*
@@ -397,10 +383,6 @@ void __init setup_arch(char **cmdline_p)
397383
bss_resource.start = virt_to_phys(__bss_start);
398384
bss_resource.end = virt_to_phys(_ebss)-1;
399385

400-
memory_start = (unsigned long)__va(__MEMORY_START);
401-
if (!memory_end)
402-
memory_end = memory_start + __MEMORY_SIZE;
403-
404386
#ifdef CONFIG_CMDLINE_OVERWRITE
405387
strlcpy(command_line, CONFIG_CMDLINE, sizeof(command_line));
406388
#else
@@ -417,8 +399,6 @@ void __init setup_arch(char **cmdline_p)
417399

418400
parse_early_param();
419401

420-
uncached_init();
421-
422402
plat_early_device_setup();
423403

424404
/* Let earlyprintk output early console messages */
@@ -429,21 +409,28 @@ void __init setup_arch(char **cmdline_p)
429409
sh_mv_setup();
430410
sh_mv.mv_mem_init();
431411

432-
/*
433-
* Find the highest page frame number we have available
434-
*/
435-
max_pfn = PFN_DOWN(__pa(memory_end));
412+
early_reserve_mem();
413+
414+
lmb_enforce_memory_limit(memory_limit);
415+
lmb_analyze();
416+
417+
lmb_dump_all();
436418

437419
/*
438420
* Determine low and high memory ranges:
439421
*/
440-
max_low_pfn = max_pfn;
422+
max_low_pfn = max_pfn = lmb_end_of_DRAM() >> PAGE_SHIFT;
441423
min_low_pfn = __MEMORY_START >> PAGE_SHIFT;
442424

443425
nodes_clear(node_online_map);
444426

427+
memory_start = (unsigned long)__va(__MEMORY_START);
428+
memory_end = memory_start + (memory_limit ?: lmb_phys_mem_size());
429+
430+
uncached_init();
445431
pmb_init();
446-
setup_memory();
432+
do_init_bootmem();
433+
plat_mem_setup();
447434
sparse_init();
448435

449436
#ifdef CONFIG_DUMMY_CONSOLE

0 commit comments

Comments
 (0)