char release[6]; /* kernel release number */
char version[6]; /* kernel version number */
int vm_allocated_bytes; /* allocated by kernel to load vm */
- int kernel_allocated_bytes; /* used by kernel */
+ int kernel_allocated_bytes; /* used by kernel */
+ int kernel_allocated_bytes_dynamic; /* used by kernel (runtime) */
} kinfo_t;
#endif
}
}
-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;
mmap->addr += ARM_PAGE_SIZE;
mmap->len -= ARM_PAGE_SIZE;
+ cbi->kernel_allocated_bytes_dynamic += ARM_PAGE_SIZE;
+
return addr;
}
#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;
* 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);
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;
}
assert(lowest != EMPTY);
cut_memmap(cbi, lowest, len);
+ cbi->kernel_allocated_bytes_dynamic += len;
return lowest;
}
mmap->len -= I386_PAGE_SIZE;
+ cbi->kernel_allocated_bytes_dynamic += I386_PAGE_SIZE;
+
return mmap->addr + mmap->len;
}
* 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);
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;
return mem;
}
+void mem_add_total_pages(int pages)
+{
+ total_pages += pages;
+}
+
/*===========================================================================*
* free_mem *
*===========================================================================*/
static struct memory mem_chunks[NR_MEMS];
static struct boot_image *ip;
extern void __minix_init(void);
+ multiboot_module_t *mod;
+ vir_bytes kern_dyn, kern_static;
#if SANITYCHECKS
incheck = nocheck = 0;
init_proc(VM_PROC_NR);
pt_init();
+ /* The kernel's freelist does not include boot-time modules; let
+ * the allocator know that the total memory is bigger.
+ */
+ for (mod = &kernel_boot_info.module_list[0];
+ mod < &kernel_boot_info.module_list[kernel_boot_info.mods_with_kernel-1]; mod++) {
+ phys_bytes len = mod->mod_end-mod->mod_start+1;
+ len = roundup(len, VM_PAGE_SIZE);
+ mem_add_total_pages(len/VM_PAGE_SIZE);
+ }
+
+ kern_dyn = kernel_boot_info.kernel_allocated_bytes_dynamic;
+ kern_static = kernel_boot_info.kernel_allocated_bytes;
+ kern_static = roundup(kern_static, VM_PAGE_SIZE);
+ mem_add_total_pages((kern_dyn + kern_static)/VM_PAGE_SIZE);
+
/* Give these processes their own page table. */
for (ip = &kernel_boot_info.boot_procs[0];
ip < &kernel_boot_info.boot_procs[NR_BOOT_PROCS]; ip++) {
int usedpages_add_f(phys_bytes phys, phys_bytes len, char *file, int
line);
void free_mem(phys_clicks base, phys_clicks clicks);
+void mem_add_total_pages(int pages);
#define usedpages_add(a, l) usedpages_add_f(a, l, __FILE__, __LINE__)
void mem_init(struct memory *chunks);
void get_usage_info_kernel(struct vm_usage_info *vui)
{
memset(vui, 0, sizeof(*vui));
- vui->vui_total = kernel_boot_info.kernel_allocated_bytes;
+ vui->vui_total = kernel_boot_info.kernel_allocated_bytes +
+ kernel_boot_info.kernel_allocated_bytes_dynamic;
}
static void get_usage_info_vm(struct vm_usage_info *vui)