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

Kernel: When physical page allocation fails, try to purge something

Instead of panicking right away when we run out of physical pages,
we now try to find a PurgeableVMObject with some volatile pages in it.
If we find one, we purge that entire object and steal one of its pages.

This makes it possible for the kernel to keep going instead of dying.
Very cool. :^)
This commit is contained in:
Andreas Kling 2019-12-26 11:45:36 +01:00
parent dafd715743
commit c1f8291ce4
3 changed files with 36 additions and 3 deletions

View file

@ -9,6 +9,7 @@
#include <Kernel/VM/AnonymousVMObject.h>
#include <Kernel/VM/InodeVMObject.h>
#include <Kernel/VM/MemoryManager.h>
#include <Kernel/VM/PurgeableVMObject.h>
//#define MM_DEBUG
//#define PAGE_FAULT_DEBUG
@ -424,9 +425,25 @@ RefPtr<PhysicalPage> MemoryManager::allocate_user_physical_page(ShouldZeroFill s
kprintf("MM: no user physical regions available (?)\n");
}
kprintf("MM: no user physical pages available\n");
ASSERT_NOT_REACHED();
return {};
for_each_vmobject([&](auto& vmobject) {
if (vmobject.is_purgeable()) {
auto& purgeable_vmobject = static_cast<PurgeableVMObject&>(vmobject);
int purged_page_count = purgeable_vmobject.purge_with_interrupts_disabled({});
if (purged_page_count) {
kprintf("MM: Purge saved the day! Purged %d pages from PurgeableVMObject{%p}\n", purged_page_count, &purgeable_vmobject);
page = find_free_user_physical_page();
ASSERT(page);
return IterationDecision::Break;
}
}
return IterationDecision::Continue;
});
if (!page) {
kprintf("MM: no user physical pages available\n");
ASSERT_NOT_REACHED();
return {};
}
}
#ifdef MM_DEBUG