1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 18:47:34 +00:00

Kernel: Release page tables when no longer needed

When unmapping regions, check if page tables can be freed.

This is a follow-up change for #3254.
This commit is contained in:
Tom 2020-08-27 21:29:17 -06:00 committed by Andreas Kling
parent 88319b188e
commit 67dbb56444
5 changed files with 50 additions and 7 deletions

View file

@ -266,10 +266,10 @@ void Region::unmap(ShouldDeallocateVirtualMemoryRange deallocate_range)
{
ScopedSpinLock lock(s_mm_lock);
ASSERT(m_page_directory);
for (size_t i = 0; i < page_count(); ++i) {
size_t count = page_count();
for (size_t i = 0; i < count; ++i) {
auto vaddr = vaddr_from_page_index(i);
auto& pte = MM.ensure_pte(*m_page_directory, vaddr);
pte.clear();
MM.release_pte(*m_page_directory, vaddr, i == count - 1);
#ifdef MM_DEBUG
auto* page = physical_page(i);
dbg() << "MM: >> Unmapped " << vaddr << " => P" << String::format("%p", page ? page->paddr().get() : 0) << " <<";