vmm: on anonymous copy-on-write, just map the page if refcount is 1

This commit is contained in:
Matheus
2024-09-24 23:25:53 -03:00
parent 0585eff9a2
commit b1aff6378f
+7 -4
View File
@@ -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));