vm: implement lazy-attach cow-duplication of vm-objects attached to a controller
This commit is contained in:
+14
-5
@@ -6,6 +6,7 @@
|
||||
#include <kernel/printk.h>
|
||||
#include <kernel/sched.h>
|
||||
#include <kernel/task.h>
|
||||
#include <kernel/thread.h>
|
||||
#include <kernel/util.h>
|
||||
#include <kernel/vm-controller.h>
|
||||
#include <kernel/vm-object.h>
|
||||
@@ -1502,6 +1503,17 @@ static kern_status_t request_missing_page(
|
||||
vm_object_lock(object);
|
||||
address_space_unlock(region);
|
||||
|
||||
kern_status_t status = KERN_OK;
|
||||
|
||||
if (object->vo_flags & VMO_LAZY_ATTACH) {
|
||||
status = vm_object_attach_cow(object, irq_flags);
|
||||
}
|
||||
|
||||
if (status != KERN_OK) {
|
||||
vm_object_unlock_irqrestore(object, *irq_flags);
|
||||
return status;
|
||||
}
|
||||
|
||||
struct vm_page *pg = vm_object_get_page(
|
||||
object,
|
||||
object_offset,
|
||||
@@ -1515,7 +1527,7 @@ static kern_status_t request_missing_page(
|
||||
|
||||
/* now: `region` is unlocked, and `object` is locked */
|
||||
|
||||
kern_status_t status = pmap_add(
|
||||
status = pmap_add(
|
||||
region->s_pmap,
|
||||
addr,
|
||||
vm_page_get_pfn(pg),
|
||||
@@ -1550,9 +1562,6 @@ static kern_status_t handle_cow_access(
|
||||
}
|
||||
|
||||
tracek("cow access %zx", addr);
|
||||
if (area->vma_object->vo_ctrl) {
|
||||
panic("COW on controlled vm-object");
|
||||
}
|
||||
|
||||
off_t object_offset = addr - area->vma_base + area->vma_object_offset;
|
||||
vm_object_lock(area->vma_object);
|
||||
@@ -1663,7 +1672,7 @@ kern_status_t address_space_demand_map(
|
||||
address_space_lock_irqsave(region, &irq_flags);
|
||||
|
||||
const enum pmap_fault_flags cow_flags
|
||||
= PMAP_FAULT_WRITE | PMAP_FAULT_PRESENT | PMAP_FAULT_USER;
|
||||
= PMAP_FAULT_WRITE | PMAP_FAULT_PRESENT;
|
||||
|
||||
if ((flags & cow_flags) == cow_flags) {
|
||||
return handle_cow_access(region, addr, flags, &irq_flags);
|
||||
|
||||
Reference in New Issue
Block a user