summaryrefslogtreecommitdiff
path: root/Kernel/VM/MemoryManager.cpp
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-02-15 13:12:02 +0100
committerAndreas Kling <kling@serenityos.org>2020-02-15 13:17:40 +0100
commitc624d3875ecfdcb77ea2cd69ff40a3a933da33d3 (patch)
treeda36ea358878eea370a847eb857b5dddb273e144 /Kernel/VM/MemoryManager.cpp
parenta4d857e3c5e2040309613256f12c2de348d2b9ba (diff)
downloadserenity-c624d3875ecfdcb77ea2cd69ff40a3a933da33d3.zip
Kernel: Use a shared physical page for zero-filled pages until written
This patch adds a globally shared zero-filled PhysicalPage that will be mapped into every slot of every zero-filled AnonymousVMObject until that page is written to, achieving CoW-like zero-filled pages. Initial testing show that this doesn't actually achieve any sharing yet but it seems like a good design regardless, since it may reduce the number of page faults taken by programs. If you look at the refcount of MM.shared_zero_page() it will have quite a high refcount, but that's just because everything maps it everywhere. If you want to see the "real" refcount, you can build with the MAP_SHARED_ZERO_PAGE_LAZILY flag, and we'll defer mapping of the shared zero page until the first NP read fault. I've left this behavior behind a flag for future testing of this code.
Diffstat (limited to 'Kernel/VM/MemoryManager.cpp')
-rw-r--r--Kernel/VM/MemoryManager.cpp4
1 files changed, 3 insertions, 1 deletions
diff --git a/Kernel/VM/MemoryManager.cpp b/Kernel/VM/MemoryManager.cpp
index 8573f52561..a4433ed036 100644
--- a/Kernel/VM/MemoryManager.cpp
+++ b/Kernel/VM/MemoryManager.cpp
@@ -53,6 +53,8 @@ MemoryManager::MemoryManager()
write_cr3(kernel_page_directory().cr3());
setup_low_identity_mapping();
protect_kernel_image();
+
+ m_shared_zero_page = allocate_user_physical_page();
}
MemoryManager::~MemoryManager()
@@ -297,7 +299,7 @@ OwnPtr<Region> MemoryManager::allocate_kernel_region(size_t size, const StringVi
region = Region::create_user_accessible(range, name, access, cacheable);
else
region = Region::create_kernel_only(range, name, access, cacheable);
- region->set_page_directory(kernel_page_directory());
+ region->map(kernel_page_directory());
if (should_commit)
region->commit();
return region;