vmm: reduce number of page faults on anonymous page in

This commit is contained in:
Matheus
2026-04-17 20:48:45 -03:00
parent 3dfb6b5a8c
commit e121029500
+22 -4
View File
@@ -639,16 +639,34 @@ bool vmm_pagefault(void *addr, bool user, int actions) {
} }
} }
} else { } else {
// anonymous memory. map the zero'd page status = true;
status = arch_mmu_map(current_vmm_context()->pagetable, zeropage, addr, range->mmuflags & ~ARCH_MMU_FLAGS_WRITE); // anonymous memory.
if (!status) { if (range->mmuflags & ARCH_MMU_FLAGS_WRITE) {
// writeable range: allocate a new page, zero it and map it
void *new_page = pmm_allocpage(PMM_SECTION_DEFAULT);
if (new_page == NULL) {
printf("vmm: out of memory to allocate page to satisfy anonymous page-in (sending SIGBUS)\n");
signal_signalthread(current_thread(), SIGBUS, true);
goto cleanup;
}
memset(MAKE_HHDM(new_page), 0, PAGE_SIZE);
if (!arch_mmu_map(current_vmm_context()->pagetable, new_page, addr, range->mmuflags)) {
printf("vmm: out of memory to map page (sending SIGBUS)\n");
signal_signalthread(current_thread(), SIGBUS, true);
pmm_release(new_page);
}
} else {
// read-only range: map a shared zero page
if (!arch_mmu_map(current_vmm_context()->pagetable, zeropage, addr, range->mmuflags)) {
printf("vmm: out of memory to map zero page into address space (sending SIGBUS)\n"); printf("vmm: out of memory to map zero page into address space (sending SIGBUS)\n");
signal_signalthread(current_thread(), SIGBUS, true); signal_signalthread(current_thread(), SIGBUS, true);
status = true;
} else { } else {
pmm_hold(zeropage); pmm_hold(zeropage);
} }
} }
}
} else if (arch_mmu_iswritable(current_vmm_context()->pagetable, addr) == false) { } else if (arch_mmu_iswritable(current_vmm_context()->pagetable, addr) == false) {
// page present but not writeable in the page tables // page present but not writeable in the page tables
void *oldphys = arch_mmu_getphysical(current_vmm_context()->pagetable, addr); void *oldphys = arch_mmu_getphysical(current_vmm_context()->pagetable, addr);