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

Kernel: Release some clean file-backed memory when starved for pages

Until now, our only backup plan when running out of physical pages
was to try and purge volatile memory. If that didn't work out, we just
hung userspace out to dry with an ENOMEM.

This patch improves the situation by also considering clean, file-backed
pages (that we could page back in from disk).

This could be better in many ways, but it already allows us to boot to
WindowServer with 256 MiB of RAM. :^)
This commit is contained in:
Andreas Kling 2022-08-14 21:46:08 +02:00
parent 92556e07d3
commit 9e9924115f

View file

@ -929,6 +929,20 @@ ErrorOr<NonnullRefPtr<PhysicalPage>> MemoryManager::allocate_physical_page(Shoul
}
return IterationDecision::Continue;
});
// Second, we look for a file-backed VMObject with clean pages.
for_each_vmobject([&](auto& vmobject) {
if (!vmobject.is_inode())
return IterationDecision::Continue;
auto& inode_vmobject = static_cast<InodeVMObject&>(vmobject);
// FIXME: It seems excessive to release *all* clean pages from the inode when we only need one.
if (auto released_page_count = inode_vmobject.release_all_clean_pages()) {
dbgln("MM: Clean inode release saved the day! Released {} pages from InodeVMObject", released_page_count);
page = find_free_physical_page(false);
VERIFY(page);
return IterationDecision::Break;
}
return IterationDecision::Continue;
});
if (!page) {
dmesgln("MM: no physical pages available");
return ENOMEM;