From 8717e78918ba071e981cab23440acd0f7142dc35 Mon Sep 17 00:00:00 2001 From: Idan Horowitz Date: Sun, 10 Jul 2022 17:58:02 +0300 Subject: [PATCH] Kernel: Stop committing pages for COW of uncommitted pages on sys$fork Uncommitted pages (shared zero pages) can not contain any existing data and can not be modified, so there's no point to committing a bunch of extra pages to cover for them in the forked child. --- Kernel/Memory/AnonymousVMObject.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Kernel/Memory/AnonymousVMObject.cpp b/Kernel/Memory/AnonymousVMObject.cpp index 59a7ead9d3..f20410c6c3 100644 --- a/Kernel/Memory/AnonymousVMObject.cpp +++ b/Kernel/Memory/AnonymousVMObject.cpp @@ -31,7 +31,14 @@ ErrorOr> AnonymousVMObject::try_clone() // commit the number of pages that we need to potentially allocate // so that the parent is still guaranteed to be able to have all // non-volatile memory available. - size_t new_cow_pages_needed = page_count(); + size_t new_cow_pages_needed = 0; + for (auto const& page : m_physical_pages) { + if (!page->is_shared_zero_page()) + ++new_cow_pages_needed; + } + + if (new_cow_pages_needed == 0) + return TRY(try_create_with_size(size(), AllocationStrategy::None)); dbgln_if(COMMIT_DEBUG, "Cloning {:p}, need {} committed cow pages", this, new_cow_pages_needed);