summaryrefslogtreecommitdiff
path: root/Kernel
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2022-01-12 13:48:43 +0100
committerAndreas Kling <kling@serenityos.org>2022-01-12 14:52:47 +0100
commit2323cdd91419ba2bad419f62acdbbca259f6bd45 (patch)
tree5bd1311415fa6feefd1524c4215d4f79f8baf016 /Kernel
parenta702b6ec428ce8c899c2b2cdea979012ee435c9c (diff)
downloadserenity-2323cdd91419ba2bad419f62acdbbca259f6bd45.zip
Kernel: Do less unnecessary work when tearing down process address space
When deleting an entire AddressSpace, we don't need to do TLB flushes at all (since the entire page directory is going away anyway). We also don't need to deallocate VM ranges one by one, since the entire VM range allocator will be deleted anyway.
Diffstat (limited to 'Kernel')
-rw-r--r--Kernel/Memory/AddressSpace.cpp3
-rw-r--r--Kernel/Memory/Region.cpp5
-rw-r--r--Kernel/Memory/Region.h2
3 files changed, 7 insertions, 3 deletions
diff --git a/Kernel/Memory/AddressSpace.cpp b/Kernel/Memory/AddressSpace.cpp
index d275561b4e..dbda1324e1 100644
--- a/Kernel/Memory/AddressSpace.cpp
+++ b/Kernel/Memory/AddressSpace.cpp
@@ -320,7 +320,10 @@ void AddressSpace::dump_regions()
void AddressSpace::remove_all_regions(Badge<Process>)
{
+ VERIFY(Thread::current() == g_finalizer);
SpinlockLocker lock(m_lock);
+ for (auto& region : m_regions)
+ (*region).unmap(Region::ShouldDeallocateVirtualRange::No, ShouldFlushTLB::No);
m_regions.clear();
}
diff --git a/Kernel/Memory/Region.cpp b/Kernel/Memory/Region.cpp
index c503c0dbed..3c3a2fd83f 100644
--- a/Kernel/Memory/Region.cpp
+++ b/Kernel/Memory/Region.cpp
@@ -234,7 +234,7 @@ bool Region::remap_vmobject_page(size_t page_index, bool with_flush)
return success;
}
-void Region::unmap(ShouldDeallocateVirtualRange deallocate_range)
+void Region::unmap(ShouldDeallocateVirtualRange deallocate_range, ShouldFlushTLB should_flush_tlb)
{
if (!m_page_directory)
return;
@@ -245,7 +245,8 @@ void Region::unmap(ShouldDeallocateVirtualRange deallocate_range)
auto vaddr = vaddr_from_page_index(i);
MM.release_pte(*m_page_directory, vaddr, i == count - 1 ? MemoryManager::IsLastPTERelease::Yes : MemoryManager::IsLastPTERelease::No);
}
- MemoryManager::flush_tlb(m_page_directory, vaddr(), page_count());
+ if (should_flush_tlb == ShouldFlushTLB::Yes)
+ MemoryManager::flush_tlb(m_page_directory, vaddr(), page_count());
if (deallocate_range == ShouldDeallocateVirtualRange::Yes) {
m_page_directory->range_allocator().deallocate(range());
}
diff --git a/Kernel/Memory/Region.h b/Kernel/Memory/Region.h
index 7571456ca3..5ca89bfd53 100644
--- a/Kernel/Memory/Region.h
+++ b/Kernel/Memory/Region.h
@@ -178,7 +178,7 @@ public:
No,
Yes,
};
- void unmap(ShouldDeallocateVirtualRange = ShouldDeallocateVirtualRange::Yes);
+ void unmap(ShouldDeallocateVirtualRange, ShouldFlushTLB = ShouldFlushTLB::Yes);
void remap();