Commit 6db015e4 authored by Nicolas Pitre's avatar Nicolas Pitre Committed by Russell King

[ARM] mem_init() cleanups

Make free_area() arguments pfn based, and return number of freed pages.
This will simplify highmem initialization later.

Also, codepages, datapages and initpages are actually codesize, datasize
and initsize.
Signed-off-by: default avatarNicolas Pitre <nico@marvell.com>
Signed-off-by: default avatarRussell King <rmk+kernel@arm.linux.org.uk>
parent a1bbaec0
...@@ -394,20 +394,22 @@ void __init bootmem_init(void) ...@@ -394,20 +394,22 @@ void __init bootmem_init(void)
max_pfn = max_low_pfn = memend_pfn - PHYS_PFN_OFFSET; max_pfn = max_low_pfn = memend_pfn - PHYS_PFN_OFFSET;
} }
static inline void free_area(unsigned long addr, unsigned long end, char *s) static inline int free_area(unsigned long pfn, unsigned long end, char *s)
{ {
unsigned int size = (end - addr) >> 10; unsigned int pages = 0, size = (end - pfn) << (PAGE_SHIFT - 10);
for (; addr < end; addr += PAGE_SIZE) { for (; pfn < end; pfn++) {
struct page *page = virt_to_page(addr); struct page *page = pfn_to_page(pfn);
ClearPageReserved(page); ClearPageReserved(page);
init_page_count(page); init_page_count(page);
free_page(addr); __free_page(page);
totalram_pages++; pages++;
} }
if (size && s) if (size && s)
printk(KERN_INFO "Freeing %s memory: %dK\n", s, size); printk(KERN_INFO "Freeing %s memory: %dK\n", s, size);
return pages;
} }
static inline void static inline void
...@@ -478,13 +480,9 @@ static void __init free_unused_memmap_node(int node, struct meminfo *mi) ...@@ -478,13 +480,9 @@ static void __init free_unused_memmap_node(int node, struct meminfo *mi)
*/ */
void __init mem_init(void) void __init mem_init(void)
{ {
unsigned int codepages, datapages, initpages; unsigned int codesize, datasize, initsize;
int i, node; int i, node;
codepages = &_etext - &_text;
datapages = &_end - &__data_start;
initpages = &__init_end - &__init_begin;
#ifndef CONFIG_DISCONTIGMEM #ifndef CONFIG_DISCONTIGMEM
max_mapnr = virt_to_page(high_memory) - mem_map; max_mapnr = virt_to_page(high_memory) - mem_map;
#endif #endif
...@@ -501,7 +499,8 @@ void __init mem_init(void) ...@@ -501,7 +499,8 @@ void __init mem_init(void)
#ifdef CONFIG_SA1111 #ifdef CONFIG_SA1111
/* now that our DMA memory is actually so designated, we can free it */ /* now that our DMA memory is actually so designated, we can free it */
free_area(PAGE_OFFSET, (unsigned long)swapper_pg_dir, NULL); totalram_pages += free_area(PHYS_PFN_OFFSET,
__phys_to_pfn(__pa(swapper_pg_dir)), NULL);
#endif #endif
/* /*
...@@ -509,18 +508,21 @@ void __init mem_init(void) ...@@ -509,18 +508,21 @@ void __init mem_init(void)
* real number of pages we have in this system * real number of pages we have in this system
*/ */
printk(KERN_INFO "Memory:"); printk(KERN_INFO "Memory:");
num_physpages = 0; num_physpages = 0;
for (i = 0; i < meminfo.nr_banks; i++) { for (i = 0; i < meminfo.nr_banks; i++) {
num_physpages += bank_pfn_size(&meminfo.bank[i]); num_physpages += bank_pfn_size(&meminfo.bank[i]);
printk(" %ldMB", bank_phys_size(&meminfo.bank[i]) >> 20); printk(" %ldMB", bank_phys_size(&meminfo.bank[i]) >> 20);
} }
printk(" = %luMB total\n", num_physpages >> (20 - PAGE_SHIFT)); printk(" = %luMB total\n", num_physpages >> (20 - PAGE_SHIFT));
codesize = &_etext - &_text;
datasize = &_end - &__data_start;
initsize = &__init_end - &__init_begin;
printk(KERN_NOTICE "Memory: %luKB available (%dK code, " printk(KERN_NOTICE "Memory: %luKB available (%dK code, "
"%dK data, %dK init)\n", "%dK data, %dK init)\n",
(unsigned long) nr_free_pages() << (PAGE_SHIFT-10), (unsigned long) nr_free_pages() << (PAGE_SHIFT-10),
codepages >> 10, datapages >> 10, initpages >> 10); codesize >> 10, datasize >> 10, initsize >> 10);
if (PAGE_SIZE >= 16384 && num_physpages <= 128) { if (PAGE_SIZE >= 16384 && num_physpages <= 128) {
extern int sysctl_overcommit_memory; extern int sysctl_overcommit_memory;
...@@ -535,11 +537,10 @@ void __init mem_init(void) ...@@ -535,11 +537,10 @@ void __init mem_init(void)
void free_initmem(void) void free_initmem(void)
{ {
if (!machine_is_integrator() && !machine_is_cintegrator()) { if (!machine_is_integrator() && !machine_is_cintegrator())
free_area((unsigned long)(&__init_begin), totalram_pages += free_area(__phys_to_pfn(__pa(&__init_begin)),
(unsigned long)(&__init_end), __phys_to_pfn(__pa(&__init_end)),
"init"); "init");
}
} }
#ifdef CONFIG_BLK_DEV_INITRD #ifdef CONFIG_BLK_DEV_INITRD
...@@ -549,7 +550,9 @@ static int keep_initrd; ...@@ -549,7 +550,9 @@ static int keep_initrd;
void free_initrd_mem(unsigned long start, unsigned long end) void free_initrd_mem(unsigned long start, unsigned long end)
{ {
if (!keep_initrd) if (!keep_initrd)
free_area(start, end, "initrd"); totalram_pages += free_area(__phys_to_pfn(__pa(start)),
__phys_to_pfn(__pa(end)),
"initrd");
} }
static int __init keepinitrd_setup(char *__unused) static int __init keepinitrd_setup(char *__unused)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment