From 7fe40633235d864c63e144295226426e456aed64 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sat, 3 Nov 2018 23:20:49 +0100 Subject: [PATCH] Region::clone() should share the zone if it's read-only. This avoids copying the .text and .rodata segments in fork(). The next step is copy-on-write support for the writable regions. --- Kernel/MemoryManager.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Kernel/MemoryManager.cpp b/Kernel/MemoryManager.cpp index 7dd4cd6cb5..8ab31a64e3 100644 --- a/Kernel/MemoryManager.cpp +++ b/Kernel/MemoryManager.cpp @@ -428,6 +428,10 @@ RetainPtr Region::clone() InterruptDisabler disabler; KernelPagingScope pagingScope; + if (is_readable && !is_writable) { + // Create a new region backed by the same zone. + return adopt(*new Region(linearAddress, size, zone.copyRef(), String(name), is_readable, is_writable)); + } // FIXME: Implement COW regions. auto clone_zone = MM.createZone(zone->size()); auto clone_region = adopt(*new Region(linearAddress, size, move(clone_zone), String(name), is_readable, is_writable));