2019-06-04 11:11:33 +03:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2013-01-18 13:42:20 +04:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2004, 2007-2010, 2011-2012 Synopsys, Inc. (www.synopsys.com)
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/mm.h>
|
|
|
|
#include <linux/memblock.h>
|
2012-09-09 12:37:40 +04:00
|
|
|
#ifdef CONFIG_BLK_DEV_INITRD
|
|
|
|
#include <linux/initrd.h>
|
|
|
|
#endif
|
2016-04-26 19:29:34 +03:00
|
|
|
#include <linux/of_fdt.h>
|
2013-01-18 13:42:20 +04:00
|
|
|
#include <linux/swap.h>
|
|
|
|
#include <linux/module.h>
|
2015-10-28 16:36:10 +03:00
|
|
|
#include <linux/highmem.h>
|
2013-01-18 13:42:20 +04:00
|
|
|
#include <asm/page.h>
|
|
|
|
#include <asm/sections.h>
|
|
|
|
#include <asm/arcregs.h>
|
|
|
|
|
|
|
|
pgd_t swapper_pg_dir[PTRS_PER_PGD] __aligned(PAGE_SIZE);
|
|
|
|
char empty_zero_page[PAGE_SIZE] __aligned(PAGE_SIZE);
|
|
|
|
EXPORT_SYMBOL(empty_zero_page);
|
|
|
|
|
2017-08-15 21:13:54 +03:00
|
|
|
static const unsigned long low_mem_start = CONFIG_LINUX_RAM_BASE;
|
2015-10-28 16:18:17 +03:00
|
|
|
static unsigned long low_mem_sz;
|
2013-01-18 13:42:20 +04:00
|
|
|
|
2015-10-28 16:36:10 +03:00
|
|
|
#ifdef CONFIG_HIGHMEM
|
2016-04-18 08:19:56 +03:00
|
|
|
static unsigned long min_high_pfn, max_high_pfn;
|
2020-08-28 19:39:02 +03:00
|
|
|
static phys_addr_t high_mem_start;
|
|
|
|
static phys_addr_t high_mem_sz;
|
arc: use FLATMEM with freeing of unused memory map instead of DISCONTIGMEM
Currently ARC uses DISCONTIGMEM to cope with sparse physical memory address
space on systems with 2 memory banks. While DISCONTIGMEM avoids wasting
memory on unpopulated memory map, it adds both memory and CPU overhead
relatively to FLATMEM. Moreover, DISCONTINGMEM is generally considered
deprecated.
The obvious replacement for DISCONTIGMEM would be SPARSEMEM, but it is also
less efficient than FLATMEM in pfn_to_page() and page_to_pfn() conversions.
Besides it requires tuning of SECTION_SIZE which is not trivial for
possible ARC memory configuration.
Since the memory map for both banks is always allocated from the "lowmem"
bank, it is possible to use FLATMEM for two-bank configuration and simply
free the unused hole in the memory map. All is required for that is to
provide ARC-specific pfn_valid() that will take into account actual
physical memory configuration and define HAVE_ARCH_PFN_VALID.
The resulting kernel image configured with defconfig + HIGHMEM=y is
smaller:
$ size a/vmlinux b/vmlinux
text data bss dec hex filename
4673503 1245456 279756 6198715 5e95bb a/vmlinux
4658706 1246864 279756 6185326 5e616e b/vmlinux
$ ./scripts/bloat-o-meter a/vmlinux b/vmlinux
add/remove: 28/30 grow/shrink: 42/399 up/down: 10986/-29025 (-18039)
...
Total: Before=4709315, After = 4691276, chg -0.38%
Booting nSIM with haps_ns.dts results in the following memory usage
reports:
a:
Memory: 1559104K/1572864K available (3531K kernel code, 595K rwdata, 752K rodata, 136K init, 275K bss, 13760K reserved, 0K cma-reserved, 1048576K highmem)
b:
Memory: 1559112K/1572864K available (3519K kernel code, 594K rwdata, 752K rodata, 136K init, 280K bss, 13752K reserved, 0K cma-reserved, 1048576K highmem)
Link: https://lkml.kernel.org/r/20201101170454.9567-11-rppt@kernel.org
Signed-off-by: Mike Rapoport <rppt@linux.ibm.com>
Cc: Alexey Dobriyan <adobriyan@gmail.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Geert Uytterhoeven <geert@linux-m68k.org>
Cc: Greg Ungerer <gerg@linux-m68k.org>
Cc: John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: Matt Turner <mattst88@gmail.com>
Cc: Meelis Roos <mroos@linux.ee>
Cc: Michael Schmitz <schmitzmic@gmail.com>
Cc: Russell King <linux@armlinux.org.uk>
Cc: Tony Luck <tony.luck@intel.com>
Cc: Vineet Gupta <vgupta@synopsys.com>
Cc: Will Deacon <will@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2020-12-15 06:10:04 +03:00
|
|
|
unsigned long arch_pfn_offset;
|
|
|
|
EXPORT_SYMBOL(arch_pfn_offset);
|
2015-10-28 16:36:10 +03:00
|
|
|
#endif
|
|
|
|
|
2017-01-18 23:59:21 +03:00
|
|
|
long __init arc_get_mem_sz(void)
|
|
|
|
{
|
|
|
|
return low_mem_sz;
|
|
|
|
}
|
|
|
|
|
2013-01-18 13:42:20 +04:00
|
|
|
/* User can over-ride above with "mem=nnn[KkMm]" in cmdline */
|
|
|
|
static int __init setup_mem_sz(char *str)
|
|
|
|
{
|
2015-10-28 16:18:17 +03:00
|
|
|
low_mem_sz = memparse(str, NULL) & PAGE_MASK;
|
2013-01-18 13:42:20 +04:00
|
|
|
|
|
|
|
/* early console might not be setup yet - it will show up later */
|
2015-10-28 16:18:17 +03:00
|
|
|
pr_info("\"mem=%s\": mem sz set to %ldM\n", str, TO_MB(low_mem_sz));
|
2013-01-18 13:42:20 +04:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
early_param("mem", setup_mem_sz);
|
|
|
|
|
2013-01-22 15:30:52 +04:00
|
|
|
void __init early_init_dt_add_memory_arch(u64 base, u64 size)
|
|
|
|
{
|
2015-10-28 16:36:10 +03:00
|
|
|
int in_use = 0;
|
|
|
|
|
|
|
|
if (!low_mem_sz) {
|
2015-12-15 11:27:16 +03:00
|
|
|
if (base != low_mem_start)
|
2017-08-15 21:13:54 +03:00
|
|
|
panic("CONFIG_LINUX_RAM_BASE != DT memory { }");
|
2015-12-15 11:27:16 +03:00
|
|
|
|
2015-10-28 16:36:10 +03:00
|
|
|
low_mem_sz = size;
|
|
|
|
in_use = 1;
|
2021-11-05 23:44:49 +03:00
|
|
|
memblock_add_node(base, size, 0, MEMBLOCK_NONE);
|
2015-10-28 16:36:10 +03:00
|
|
|
} else {
|
|
|
|
#ifdef CONFIG_HIGHMEM
|
|
|
|
high_mem_start = base;
|
|
|
|
high_mem_sz = size;
|
|
|
|
in_use = 1;
|
2021-11-05 23:44:49 +03:00
|
|
|
memblock_add_node(base, size, 1, MEMBLOCK_NONE);
|
2020-08-28 19:39:02 +03:00
|
|
|
memblock_reserve(base, size);
|
2015-10-28 16:36:10 +03:00
|
|
|
#endif
|
|
|
|
}
|
2015-01-23 15:40:26 +03:00
|
|
|
|
2015-10-28 16:36:10 +03:00
|
|
|
pr_info("Memory @ %llx [%lldM] %s\n",
|
|
|
|
base, TO_MB(size), !in_use ? "Not used":"");
|
2013-01-22 15:30:52 +04:00
|
|
|
}
|
|
|
|
|
2020-06-04 01:58:03 +03:00
|
|
|
bool arch_has_descending_max_zone_pfns(void)
|
|
|
|
{
|
|
|
|
return !IS_ENABLED(CONFIG_ARC_HAS_PAE40);
|
|
|
|
}
|
|
|
|
|
2013-01-18 13:42:20 +04:00
|
|
|
/*
|
|
|
|
* First memory setup routine called from setup_arch()
|
|
|
|
* 1. setup swapper's mm @init_mm
|
|
|
|
* 2. Count the pages we have and setup bootmem allocator
|
|
|
|
* 3. zone setup
|
|
|
|
*/
|
|
|
|
void __init setup_arch_memory(void)
|
|
|
|
{
|
2020-06-04 01:58:03 +03:00
|
|
|
unsigned long max_zone_pfn[MAX_NR_ZONES] = { 0 };
|
2013-01-18 13:42:20 +04:00
|
|
|
|
2021-07-08 04:08:26 +03:00
|
|
|
setup_initial_init_mm(_text, _etext, _edata, _end);
|
2013-01-18 13:42:20 +04:00
|
|
|
|
|
|
|
/* first page of system - kernel .vector starts here */
|
arc: use FLATMEM with freeing of unused memory map instead of DISCONTIGMEM
Currently ARC uses DISCONTIGMEM to cope with sparse physical memory address
space on systems with 2 memory banks. While DISCONTIGMEM avoids wasting
memory on unpopulated memory map, it adds both memory and CPU overhead
relatively to FLATMEM. Moreover, DISCONTINGMEM is generally considered
deprecated.
The obvious replacement for DISCONTIGMEM would be SPARSEMEM, but it is also
less efficient than FLATMEM in pfn_to_page() and page_to_pfn() conversions.
Besides it requires tuning of SECTION_SIZE which is not trivial for
possible ARC memory configuration.
Since the memory map for both banks is always allocated from the "lowmem"
bank, it is possible to use FLATMEM for two-bank configuration and simply
free the unused hole in the memory map. All is required for that is to
provide ARC-specific pfn_valid() that will take into account actual
physical memory configuration and define HAVE_ARCH_PFN_VALID.
The resulting kernel image configured with defconfig + HIGHMEM=y is
smaller:
$ size a/vmlinux b/vmlinux
text data bss dec hex filename
4673503 1245456 279756 6198715 5e95bb a/vmlinux
4658706 1246864 279756 6185326 5e616e b/vmlinux
$ ./scripts/bloat-o-meter a/vmlinux b/vmlinux
add/remove: 28/30 grow/shrink: 42/399 up/down: 10986/-29025 (-18039)
...
Total: Before=4709315, After = 4691276, chg -0.38%
Booting nSIM with haps_ns.dts results in the following memory usage
reports:
a:
Memory: 1559104K/1572864K available (3531K kernel code, 595K rwdata, 752K rodata, 136K init, 275K bss, 13760K reserved, 0K cma-reserved, 1048576K highmem)
b:
Memory: 1559112K/1572864K available (3519K kernel code, 594K rwdata, 752K rodata, 136K init, 280K bss, 13752K reserved, 0K cma-reserved, 1048576K highmem)
Link: https://lkml.kernel.org/r/20201101170454.9567-11-rppt@kernel.org
Signed-off-by: Mike Rapoport <rppt@linux.ibm.com>
Cc: Alexey Dobriyan <adobriyan@gmail.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Geert Uytterhoeven <geert@linux-m68k.org>
Cc: Greg Ungerer <gerg@linux-m68k.org>
Cc: John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: Matt Turner <mattst88@gmail.com>
Cc: Meelis Roos <mroos@linux.ee>
Cc: Michael Schmitz <schmitzmic@gmail.com>
Cc: Russell King <linux@armlinux.org.uk>
Cc: Tony Luck <tony.luck@intel.com>
Cc: Vineet Gupta <vgupta@synopsys.com>
Cc: Will Deacon <will@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2020-12-15 06:10:04 +03:00
|
|
|
min_low_pfn = virt_to_pfn(CONFIG_LINUX_RAM_BASE);
|
2013-01-18 13:42:20 +04:00
|
|
|
|
2015-10-28 16:18:17 +03:00
|
|
|
/* Last usable page of low mem */
|
|
|
|
max_low_pfn = max_pfn = PFN_DOWN(low_mem_start + low_mem_sz);
|
2013-01-18 13:42:20 +04:00
|
|
|
|
2015-10-28 16:18:17 +03:00
|
|
|
/*------------- bootmem allocator setup -----------------------*/
|
2015-10-28 16:36:10 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* seed the bootmem allocator after any DT memory node parsing or
|
|
|
|
* "mem=xxx" cmdline overrides have potentially updated @arc_mem_sz
|
|
|
|
*
|
|
|
|
* Only low mem is added, otherwise we have crashes when allocating
|
|
|
|
* mem_map[] itself. NO_BOOTMEM allocates mem_map[] at the end of
|
|
|
|
* avail memory, ending in highmem with a > 32-bit address. However
|
|
|
|
* it then tries to memset it with a truncaed 32-bit handle, causing
|
|
|
|
* the crash
|
|
|
|
*/
|
|
|
|
|
2018-12-19 19:16:16 +03:00
|
|
|
memblock_reserve(CONFIG_LINUX_LINK_BASE,
|
|
|
|
__pa(_end) - CONFIG_LINUX_LINK_BASE);
|
2013-01-18 13:42:20 +04:00
|
|
|
|
2012-09-09 12:37:40 +04:00
|
|
|
#ifdef CONFIG_BLK_DEV_INITRD
|
2018-11-06 01:54:31 +03:00
|
|
|
if (phys_initrd_size) {
|
|
|
|
memblock_reserve(phys_initrd_start, phys_initrd_size);
|
|
|
|
initrd_start = (unsigned long)__va(phys_initrd_start);
|
|
|
|
initrd_end = initrd_start + phys_initrd_size;
|
|
|
|
}
|
2012-09-09 12:37:40 +04:00
|
|
|
#endif
|
|
|
|
|
2016-04-26 19:29:34 +03:00
|
|
|
early_init_fdt_reserve_self();
|
|
|
|
early_init_fdt_scan_reserved_mem();
|
|
|
|
|
2013-01-18 13:42:20 +04:00
|
|
|
memblock_dump_all();
|
|
|
|
|
2015-10-28 16:18:17 +03:00
|
|
|
/*----------------- node/zones setup --------------------------*/
|
2020-06-04 01:58:03 +03:00
|
|
|
max_zone_pfn[ZONE_NORMAL] = max_low_pfn;
|
2015-02-13 11:29:53 +03:00
|
|
|
|
2015-10-28 16:36:10 +03:00
|
|
|
#ifdef CONFIG_HIGHMEM
|
2016-04-18 08:19:56 +03:00
|
|
|
/*
|
|
|
|
* On ARC (w/o PAE) HIGHMEM addresses are actually smaller (0 based)
|
2021-06-29 05:42:43 +03:00
|
|
|
* than addresses in normal aka low memory (0x8000_0000 based).
|
2016-04-18 08:19:56 +03:00
|
|
|
* Even with PAE, the huge peripheral space hole would waste a lot of
|
2021-06-29 05:42:43 +03:00
|
|
|
* mem with single contiguous mem_map[].
|
|
|
|
* Thus when HIGHMEM on ARC is enabled the memory map corresponding
|
|
|
|
* to the hole is freed and ARC specific version of pfn_valid()
|
|
|
|
* handles the hole in the memory map.
|
2016-04-18 08:19:56 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
min_high_pfn = PFN_DOWN(high_mem_start);
|
|
|
|
max_high_pfn = PFN_DOWN(high_mem_start + high_mem_sz);
|
|
|
|
|
2021-04-27 15:13:54 +03:00
|
|
|
/*
|
|
|
|
* max_high_pfn should be ok here for both HIGHMEM and HIGHMEM+PAE.
|
|
|
|
* For HIGHMEM without PAE max_high_pfn should be less than
|
|
|
|
* min_low_pfn to guarantee that these two regions don't overlap.
|
|
|
|
* For PAE case highmem is greater than lowmem, so it is natural
|
|
|
|
* to use max_high_pfn.
|
|
|
|
*
|
|
|
|
* In both cases, holes should be handled by pfn_valid().
|
|
|
|
*/
|
|
|
|
max_zone_pfn[ZONE_HIGHMEM] = max_high_pfn;
|
2016-04-18 08:19:56 +03:00
|
|
|
|
2015-10-28 16:36:10 +03:00
|
|
|
high_memory = (void *)(min_high_pfn << PAGE_SHIFT);
|
arc: use FLATMEM with freeing of unused memory map instead of DISCONTIGMEM
Currently ARC uses DISCONTIGMEM to cope with sparse physical memory address
space on systems with 2 memory banks. While DISCONTIGMEM avoids wasting
memory on unpopulated memory map, it adds both memory and CPU overhead
relatively to FLATMEM. Moreover, DISCONTINGMEM is generally considered
deprecated.
The obvious replacement for DISCONTIGMEM would be SPARSEMEM, but it is also
less efficient than FLATMEM in pfn_to_page() and page_to_pfn() conversions.
Besides it requires tuning of SECTION_SIZE which is not trivial for
possible ARC memory configuration.
Since the memory map for both banks is always allocated from the "lowmem"
bank, it is possible to use FLATMEM for two-bank configuration and simply
free the unused hole in the memory map. All is required for that is to
provide ARC-specific pfn_valid() that will take into account actual
physical memory configuration and define HAVE_ARCH_PFN_VALID.
The resulting kernel image configured with defconfig + HIGHMEM=y is
smaller:
$ size a/vmlinux b/vmlinux
text data bss dec hex filename
4673503 1245456 279756 6198715 5e95bb a/vmlinux
4658706 1246864 279756 6185326 5e616e b/vmlinux
$ ./scripts/bloat-o-meter a/vmlinux b/vmlinux
add/remove: 28/30 grow/shrink: 42/399 up/down: 10986/-29025 (-18039)
...
Total: Before=4709315, After = 4691276, chg -0.38%
Booting nSIM with haps_ns.dts results in the following memory usage
reports:
a:
Memory: 1559104K/1572864K available (3531K kernel code, 595K rwdata, 752K rodata, 136K init, 275K bss, 13760K reserved, 0K cma-reserved, 1048576K highmem)
b:
Memory: 1559112K/1572864K available (3519K kernel code, 594K rwdata, 752K rodata, 136K init, 280K bss, 13752K reserved, 0K cma-reserved, 1048576K highmem)
Link: https://lkml.kernel.org/r/20201101170454.9567-11-rppt@kernel.org
Signed-off-by: Mike Rapoport <rppt@linux.ibm.com>
Cc: Alexey Dobriyan <adobriyan@gmail.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Geert Uytterhoeven <geert@linux-m68k.org>
Cc: Greg Ungerer <gerg@linux-m68k.org>
Cc: John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: Matt Turner <mattst88@gmail.com>
Cc: Meelis Roos <mroos@linux.ee>
Cc: Michael Schmitz <schmitzmic@gmail.com>
Cc: Russell King <linux@armlinux.org.uk>
Cc: Tony Luck <tony.luck@intel.com>
Cc: Vineet Gupta <vgupta@synopsys.com>
Cc: Will Deacon <will@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2020-12-15 06:10:04 +03:00
|
|
|
|
|
|
|
arch_pfn_offset = min(min_low_pfn, min_high_pfn);
|
2015-10-28 16:36:10 +03:00
|
|
|
kmap_init();
|
arc: use FLATMEM with freeing of unused memory map instead of DISCONTIGMEM
Currently ARC uses DISCONTIGMEM to cope with sparse physical memory address
space on systems with 2 memory banks. While DISCONTIGMEM avoids wasting
memory on unpopulated memory map, it adds both memory and CPU overhead
relatively to FLATMEM. Moreover, DISCONTINGMEM is generally considered
deprecated.
The obvious replacement for DISCONTIGMEM would be SPARSEMEM, but it is also
less efficient than FLATMEM in pfn_to_page() and page_to_pfn() conversions.
Besides it requires tuning of SECTION_SIZE which is not trivial for
possible ARC memory configuration.
Since the memory map for both banks is always allocated from the "lowmem"
bank, it is possible to use FLATMEM for two-bank configuration and simply
free the unused hole in the memory map. All is required for that is to
provide ARC-specific pfn_valid() that will take into account actual
physical memory configuration and define HAVE_ARCH_PFN_VALID.
The resulting kernel image configured with defconfig + HIGHMEM=y is
smaller:
$ size a/vmlinux b/vmlinux
text data bss dec hex filename
4673503 1245456 279756 6198715 5e95bb a/vmlinux
4658706 1246864 279756 6185326 5e616e b/vmlinux
$ ./scripts/bloat-o-meter a/vmlinux b/vmlinux
add/remove: 28/30 grow/shrink: 42/399 up/down: 10986/-29025 (-18039)
...
Total: Before=4709315, After = 4691276, chg -0.38%
Booting nSIM with haps_ns.dts results in the following memory usage
reports:
a:
Memory: 1559104K/1572864K available (3531K kernel code, 595K rwdata, 752K rodata, 136K init, 275K bss, 13760K reserved, 0K cma-reserved, 1048576K highmem)
b:
Memory: 1559112K/1572864K available (3519K kernel code, 594K rwdata, 752K rodata, 136K init, 280K bss, 13752K reserved, 0K cma-reserved, 1048576K highmem)
Link: https://lkml.kernel.org/r/20201101170454.9567-11-rppt@kernel.org
Signed-off-by: Mike Rapoport <rppt@linux.ibm.com>
Cc: Alexey Dobriyan <adobriyan@gmail.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Geert Uytterhoeven <geert@linux-m68k.org>
Cc: Greg Ungerer <gerg@linux-m68k.org>
Cc: John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: Matt Turner <mattst88@gmail.com>
Cc: Meelis Roos <mroos@linux.ee>
Cc: Michael Schmitz <schmitzmic@gmail.com>
Cc: Russell King <linux@armlinux.org.uk>
Cc: Tony Luck <tony.luck@intel.com>
Cc: Vineet Gupta <vgupta@synopsys.com>
Cc: Will Deacon <will@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2020-12-15 06:10:04 +03:00
|
|
|
|
|
|
|
#else /* CONFIG_HIGHMEM */
|
|
|
|
/* pfn_valid() uses this when FLATMEM=y and HIGHMEM=n */
|
|
|
|
max_mapnr = max_low_pfn - min_low_pfn;
|
|
|
|
|
|
|
|
#endif /* CONFIG_HIGHMEM */
|
2020-06-04 01:58:03 +03:00
|
|
|
|
|
|
|
free_area_init(max_zone_pfn);
|
2013-01-18 13:42:20 +04:00
|
|
|
}
|
|
|
|
|
2020-08-28 19:39:02 +03:00
|
|
|
static void __init highmem_init(void)
|
2013-01-18 13:42:20 +04:00
|
|
|
{
|
2015-10-28 16:36:10 +03:00
|
|
|
#ifdef CONFIG_HIGHMEM
|
|
|
|
unsigned long tmp;
|
|
|
|
|
2021-11-05 23:43:19 +03:00
|
|
|
memblock_phys_free(high_mem_start, high_mem_sz);
|
2016-04-18 08:19:56 +03:00
|
|
|
for (tmp = min_high_pfn; tmp < max_high_pfn; tmp++)
|
2015-10-28 16:36:10 +03:00
|
|
|
free_highmem_page(pfn_to_page(tmp));
|
|
|
|
#endif
|
2020-08-28 19:39:02 +03:00
|
|
|
}
|
2015-10-28 16:36:10 +03:00
|
|
|
|
2020-08-28 19:39:02 +03:00
|
|
|
/*
|
|
|
|
* mem_init - initializes memory
|
|
|
|
*
|
|
|
|
* Frees up bootmem
|
|
|
|
* Calculates and displays memory available/used
|
|
|
|
*/
|
|
|
|
void __init mem_init(void)
|
|
|
|
{
|
2018-10-31 01:09:30 +03:00
|
|
|
memblock_free_all();
|
2020-08-28 19:39:02 +03:00
|
|
|
highmem_init();
|
2021-08-12 22:54:43 +03:00
|
|
|
|
|
|
|
BUILD_BUG_ON((PTRS_PER_PGD * sizeof(pgd_t)) > PAGE_SIZE);
|
2020-10-02 01:46:42 +03:00
|
|
|
BUILD_BUG_ON((PTRS_PER_PUD * sizeof(pud_t)) > PAGE_SIZE);
|
2020-10-01 04:58:50 +03:00
|
|
|
BUILD_BUG_ON((PTRS_PER_PMD * sizeof(pmd_t)) > PAGE_SIZE);
|
2021-08-12 22:54:43 +03:00
|
|
|
BUILD_BUG_ON((PTRS_PER_PTE * sizeof(pte_t)) > PAGE_SIZE);
|
2013-01-18 13:42:20 +04:00
|
|
|
}
|
arc: use FLATMEM with freeing of unused memory map instead of DISCONTIGMEM
Currently ARC uses DISCONTIGMEM to cope with sparse physical memory address
space on systems with 2 memory banks. While DISCONTIGMEM avoids wasting
memory on unpopulated memory map, it adds both memory and CPU overhead
relatively to FLATMEM. Moreover, DISCONTINGMEM is generally considered
deprecated.
The obvious replacement for DISCONTIGMEM would be SPARSEMEM, but it is also
less efficient than FLATMEM in pfn_to_page() and page_to_pfn() conversions.
Besides it requires tuning of SECTION_SIZE which is not trivial for
possible ARC memory configuration.
Since the memory map for both banks is always allocated from the "lowmem"
bank, it is possible to use FLATMEM for two-bank configuration and simply
free the unused hole in the memory map. All is required for that is to
provide ARC-specific pfn_valid() that will take into account actual
physical memory configuration and define HAVE_ARCH_PFN_VALID.
The resulting kernel image configured with defconfig + HIGHMEM=y is
smaller:
$ size a/vmlinux b/vmlinux
text data bss dec hex filename
4673503 1245456 279756 6198715 5e95bb a/vmlinux
4658706 1246864 279756 6185326 5e616e b/vmlinux
$ ./scripts/bloat-o-meter a/vmlinux b/vmlinux
add/remove: 28/30 grow/shrink: 42/399 up/down: 10986/-29025 (-18039)
...
Total: Before=4709315, After = 4691276, chg -0.38%
Booting nSIM with haps_ns.dts results in the following memory usage
reports:
a:
Memory: 1559104K/1572864K available (3531K kernel code, 595K rwdata, 752K rodata, 136K init, 275K bss, 13760K reserved, 0K cma-reserved, 1048576K highmem)
b:
Memory: 1559112K/1572864K available (3519K kernel code, 594K rwdata, 752K rodata, 136K init, 280K bss, 13752K reserved, 0K cma-reserved, 1048576K highmem)
Link: https://lkml.kernel.org/r/20201101170454.9567-11-rppt@kernel.org
Signed-off-by: Mike Rapoport <rppt@linux.ibm.com>
Cc: Alexey Dobriyan <adobriyan@gmail.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Geert Uytterhoeven <geert@linux-m68k.org>
Cc: Greg Ungerer <gerg@linux-m68k.org>
Cc: John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: Matt Turner <mattst88@gmail.com>
Cc: Meelis Roos <mroos@linux.ee>
Cc: Michael Schmitz <schmitzmic@gmail.com>
Cc: Russell King <linux@armlinux.org.uk>
Cc: Tony Luck <tony.luck@intel.com>
Cc: Vineet Gupta <vgupta@synopsys.com>
Cc: Will Deacon <will@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2020-12-15 06:10:04 +03:00
|
|
|
|
|
|
|
#ifdef CONFIG_HIGHMEM
|
|
|
|
int pfn_valid(unsigned long pfn)
|
|
|
|
{
|
|
|
|
return (pfn >= min_high_pfn && pfn <= max_high_pfn) ||
|
|
|
|
(pfn >= min_low_pfn && pfn <= max_low_pfn);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(pfn_valid);
|
|
|
|
#endif
|