impove memory accounting

. the total amount of memory in the system didn't include the memory
	  used by the boot-time modules and some dynamic allocation by the
	  kernel at boot time (to map in VM). especially apparent on our
	  ARM board with 'only' 512MB of memory and a huge ramdisk.
	. also: *add* the VM loaded module to the freelist after it has
	  been allocated for & mapped in instead of cutting it *out* of the
	  freelist! so we get a few more MB free..

Change-Id: If37ac32b21c9d38610830e21421264da4f20bc4f
This commit is contained in:
Ben Gras
2013-02-08 19:11:42 +01:00
parent d1df256de9
commit 3bc6d7df06
11 changed files with 40 additions and 26 deletions

View File

@@ -67,26 +67,6 @@ void cut_memmap(kinfo_t *cbi, phys_bytes start, phys_bytes end)
}
}
phys_bytes alloc_lowest(kinfo_t *cbi, phys_bytes len)
{
/* Allocate the lowest physical page we have. */
int m;
#define EMPTY 0xffffffff
phys_bytes lowest = EMPTY;
assert(len > 0);
len = roundup(len, ARM_PAGE_SIZE);
assert(kernel_may_alloc);
for(m = 0; m < cbi->mmap_size; m++) {
if(cbi->memmap[m].len < len) continue;
if(cbi->memmap[m].addr < lowest) lowest = cbi->memmap[m].addr;
}
assert(lowest != EMPTY);
cut_memmap(cbi, lowest, len);
return lowest;
}
void add_memmap(kinfo_t *cbi, u64_t addr, u64_t len)
{
int m;
@@ -157,6 +137,8 @@ phys_bytes pg_alloc_page(kinfo_t *cbi)
mmap->addr += ARM_PAGE_SIZE;
mmap->len -= ARM_PAGE_SIZE;
cbi->kernel_allocated_bytes_dynamic += ARM_PAGE_SIZE;
return addr;
}

View File

@@ -106,8 +106,8 @@ int overlaps(multiboot_module_t *mod, int n, int cmp_mod)
#define MB_PARAM_MOD 0x96000000
#define MB_MODS_ALIGN 0x00800000 /* 8 MB */
#define MB_MODS_SIZE 0x00004000 /* 16 KB */
#define MB_MMAP_START MB_MODS_BASE
#define MB_MMAP_SIZE 0x10000000 /* 256 MB */
#define MB_MMAP_START 0x80000000
#define MB_MMAP_SIZE 0x20000000 /* 512 MB */
multiboot_module_t mb_modlist[MB_MODS_NR];
multiboot_memory_map_t mb_memmap;
@@ -204,6 +204,7 @@ void get_parameters(u32_t ebx, kinfo_t *cbi)
* still needed but will be freed after bootstrapping.
*/
kinfo.kernel_allocated_bytes = (phys_bytes) &_kern_size;
kinfo.kernel_allocated_bytes -= cbi->bootstrap_len;
assert(!(cbi->bootstrap_start % ARM_PAGE_SIZE));
cbi->bootstrap_len = rounddown(cbi->bootstrap_len, ARM_PAGE_SIZE);

View File

@@ -151,7 +151,8 @@ void arch_boot_proc(struct boot_image *ip, struct proc *rp)
arch_proc_init(rp, execi.pc, kinfo.user_sp - 3*4, ip->proc_name);
/* Free VM blob that was just copied into existence. */
cut_memmap(&kinfo, mod->mod_start, mod->mod_end);
add_memmap(&kinfo, mod->mod_start, mod->mod_end-mod->mod_start);
mod->mod_end = mod->mod_start = 0;
/* Remember them */
kinfo.vm_allocated_bytes = alloc_for_vm;

View File

@@ -81,6 +81,7 @@ phys_bytes alloc_lowest(kinfo_t *cbi, phys_bytes len)
}
assert(lowest != EMPTY);
cut_memmap(cbi, lowest, len);
cbi->kernel_allocated_bytes_dynamic += len;
return lowest;
}
@@ -152,6 +153,8 @@ phys_bytes pg_alloc_page(kinfo_t *cbi)
mmap->len -= I386_PAGE_SIZE;
cbi->kernel_allocated_bytes_dynamic += I386_PAGE_SIZE;
return mmap->addr + mmap->len;
}

View File

@@ -164,6 +164,7 @@ void get_parameters(u32_t ebx, kinfo_t *cbi)
* still needed but will be freed after bootstrapping.
*/
kinfo.kernel_allocated_bytes = (phys_bytes) &_kern_size;
kinfo.kernel_allocated_bytes -= cbi->bootstrap_len;
assert(!(cbi->bootstrap_start % I386_PAGE_SIZE));
cbi->bootstrap_len = rounddown(cbi->bootstrap_len, I386_PAGE_SIZE);

View File

@@ -428,7 +428,8 @@ void arch_boot_proc(struct boot_image *ip, struct proc *rp)
arch_proc_init(rp, execi.pc, kinfo.user_sp - 3*4, ip->proc_name);
/* Free VM blob that was just copied into existence. */
cut_memmap(&kinfo, mod->mod_start, mod->mod_end);
add_memmap(&kinfo, mod->mod_start, mod->mod_end-mod->mod_start);
mod->mod_end = mod->mod_start = 0;
/* Remember them */
kinfo.vm_allocated_bytes = alloc_for_vm;