sandbox: vm: add page splitting, merging, and allocation

This commit is contained in:
2023-02-01 15:03:42 +00:00
parent 4cb30737fb
commit af49d47ba8
4 changed files with 218 additions and 0 deletions

View File

@@ -174,6 +174,24 @@ int memory_test(void)
printf("all pages:\n");
print_all_pages();
vm_page_t *pg = vm_page_alloc(VM_PAGE_128K, 0);
printf("allocated 128K at 0x%lx\n", vm_page_get_paddr(pg));
vm_page_t *a, *b;
if (vm_page_split(pg, &a, &b) == 0) {
printf("split page into two 64K pages at 0x%lx and 0x%lx:\n", vm_page_get_paddr(a), vm_page_get_paddr(b));
assert(a->p_flags & VM_PAGE_HEAD);
assert(b->p_flags & VM_PAGE_HEAD);
size_t nr_frames = vm_page_order_to_pages(VM_PAGE_128K);
for (size_t i = 0; i < nr_frames; i++) {
printf(" 0x%lx: order:%u, flags:0x%x\n", vm_page_get_paddr(a + i), a[i].p_order, a[i].p_flags);
assert(a[i].p_flags & VM_PAGE_HUGE);
assert((a[i].p_flags & VM_PAGE_RESERVED) == 0);
}
}
munmap(system_memory, MB_TO_BYTES(MEMORY_SIZE_MB));
return 0;
}