1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 13:27:35 +00:00

Kernel: Implement lazy committed page allocation

By designating a committed page pool we can guarantee to have physical
pages available for lazy allocation in mappings. However, when forking
we will overcommit. The assumption is that worst-case it's better for
the fork to die due to insufficient physical memory on COW access than
the parent that created the region. If a fork wants to ensure that all
memory is available (trigger a commit) then it can use madvise.

This also means that fork now can gracefully fail if we don't have
enough physical pages available.
This commit is contained in:
Tom 2020-09-04 21:12:25 -06:00 committed by Andreas Kling
parent e21cc4cff6
commit b2a52f6208
20 changed files with 329 additions and 67 deletions

View file

@ -110,6 +110,9 @@ public:
Yes
};
bool commit_user_physical_pages(size_t);
void uncommit_user_physical_pages(size_t);
NonnullRefPtr<PhysicalPage> allocate_committed_user_physical_page(ShouldZeroFill = ShouldZeroFill::Yes);
RefPtr<PhysicalPage> allocate_user_physical_page(ShouldZeroFill = ShouldZeroFill::Yes, bool* did_purge = nullptr);
RefPtr<PhysicalPage> allocate_supervisor_physical_page();
NonnullRefPtrVector<PhysicalPage> allocate_contiguous_supervisor_physical_pages(size_t size);
@ -155,6 +158,7 @@ public:
void dump_kernel_regions();
PhysicalPage& shared_zero_page() { return *m_shared_zero_page; }
PhysicalPage& lazy_committed_page() { return *m_lazy_committed_page; }
PageDirectory& kernel_page_directory() { return *m_kernel_page_directory; }
@ -185,7 +189,7 @@ private:
static Region* find_region_from_vaddr(VirtualAddress);
RefPtr<PhysicalPage> find_free_user_physical_page();
RefPtr<PhysicalPage> find_free_user_physical_page(bool);
u8* quickmap_page(PhysicalPage&);
void unquickmap_page();
@ -200,9 +204,12 @@ private:
RefPtr<PhysicalPage> m_low_page_table;
RefPtr<PhysicalPage> m_shared_zero_page;
RefPtr<PhysicalPage> m_lazy_committed_page;
unsigned m_user_physical_pages { 0 };
unsigned m_user_physical_pages_used { 0 };
unsigned m_user_physical_pages_committed { 0 };
unsigned m_user_physical_pages_uncommitted { 0 };
unsigned m_super_physical_pages { 0 };
unsigned m_super_physical_pages_used { 0 };
@ -250,4 +257,9 @@ inline bool PhysicalPage::is_shared_zero_page() const
return this == &MM.shared_zero_page();
}
inline bool PhysicalPage::is_lazy_committed_page() const
{
return this == &MM.lazy_committed_page();
}
}