From b1aff6378f662ffc493b4d2d0cb0b7c8ebba495b Mon Sep 17 00:00:00 2001 From: Matheus Date: Tue, 24 Sep 2024 23:25:53 -0300 Subject: [PATCH] vmm: on anonymous copy-on-write, just map the page if refcount is 1 --- kernel-src/mm/vmm.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/kernel-src/mm/vmm.c b/kernel-src/mm/vmm.c index 92d95cd5..aa90068e 100644 --- a/kernel-src/mm/vmm.c +++ b/kernel-src/mm/vmm.c @@ -615,12 +615,15 @@ bool vmm_pagefault(void *addr, bool user, int actions) { } } else if (arch_mmu_iswritable(current_vmm_context()->pagetable, addr) == false) { // page present but not writeable in the page tables - void *oldphys = arch_mmu_getphysical(current_vmm_context()->pagetable, addr); - if ((range->flags & VMM_FLAGS_FILE) && (range->flags & VMM_FLAGS_SHARED)) { - // shared file, remap it as writable + page_t *oldpage = pmm_getpage(oldphys); + + if ( ((range->flags & VMM_FLAGS_FILE) && (range->flags & VMM_FLAGS_SHARED)) || + ((range->flags & VMM_FLAGS_FILE) == 0 && oldpage->refcount == 1)) { + // shared file or anon with refcount == 1, remap it as writable + arch_mmu_remap(current_vmm_context()->pagetable, oldphys, addr, range->mmuflags); - if (vfs_iscacheable(range->vnode)) { + if ((range->flags & VMM_FLAGS_FILE) && vfs_iscacheable(range->vnode)) { // and if its a cache page, mark it as dirty VOP_LOCK(range->vnode); vmmcache_makedirty(pmm_getpage(oldphys));