1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 12:28:12 +00:00

Kernel: Detach AnonymousVMObject from shared COW pages set once emptied

We currently overcommit for COW when forking a process and cloning its
memory regions. Both the parent and child process share a set of.
committed COW pages.

If there's COW sharing across more than two processeses within a lineage
(e.g parent, child & grandchild), it's possible to exhaust these pages.
When the shared set is emptied, the next COW fault in each process must
detach from the shared set and fall back to on demand allocation.

This patch makes sure that we detach from the shared set once we
discover it to be empty (during COW fault handling). This fixes an issue
where we'd try to allocate from an exhausted shared set while building
GNU binutils inside SerenityOS.
This commit is contained in:
Andreas Kling 2021-08-05 15:33:26 +02:00
parent 89a9ae7d0c
commit 843d0d0d15

View file

@ -307,15 +307,14 @@ PageFaultResponse AnonymousVMObject::handle_cow_fault(size_t page_index, Virtual
auto& page_slot = physical_pages()[page_index];
// If we were sharing committed COW pages with another process, and the other process
// has exhausted the supply, we can stop counting the shared pages.
if (m_shared_committed_cow_pages && m_shared_committed_cow_pages->is_empty())
m_shared_committed_cow_pages = nullptr;
if (page_slot->ref_count() == 1) {
dbgln_if(PAGE_FAULT_DEBUG, " >> It's a COW page but nobody is sharing it anymore. Remap r/w");
set_should_cow(page_index, false);
// If we were sharing committed COW pages with another process, and the other process
// has exhausted the supply, we can stop counting the shared pages.
if (m_shared_committed_cow_pages && m_shared_committed_cow_pages->is_empty())
m_shared_committed_cow_pages = nullptr;
return PageFaultResponse::Continue;
}