diff options
author | Andreas Kling <kling@serenityos.org> | 2022-01-12 14:32:21 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-01-12 14:52:47 +0100 |
commit | d8206c105947d0dd12e7431b9d35509f8e62735a (patch) | |
tree | 2d8fa70b6bff60c4464e5de27a28984caa074f81 /Kernel/Memory/Region.cpp | |
parent | 2323cdd91419ba2bad419f62acdbbca259f6bd45 (diff) | |
download | serenity-d8206c105947d0dd12e7431b9d35509f8e62735a.zip |
Kernel: Don't release/relock spinlocks repeatedly during space teardown
Grab the page directory and MM locks once at the start of address space
teardown, then hold onto them across all the region unmapping work.
Diffstat (limited to 'Kernel/Memory/Region.cpp')
-rw-r--r-- | Kernel/Memory/Region.cpp | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/Kernel/Memory/Region.cpp b/Kernel/Memory/Region.cpp index 3c3a2fd83f..76e31d7406 100644 --- a/Kernel/Memory/Region.cpp +++ b/Kernel/Memory/Region.cpp @@ -234,12 +234,19 @@ bool Region::remap_vmobject_page(size_t page_index, bool with_flush) return success; } -void Region::unmap(ShouldDeallocateVirtualRange deallocate_range, ShouldFlushTLB should_flush_tlb) +void Region::unmap(ShouldDeallocateVirtualRange should_deallocate_range, ShouldFlushTLB should_flush_tlb) +{ + if (!m_page_directory) + return; + SpinlockLocker pd_locker(m_page_directory->get_lock()); + SpinlockLocker mm_locker(s_mm_lock); + unmap_with_locks_held(should_deallocate_range, should_flush_tlb, pd_locker, mm_locker); +} + +void Region::unmap_with_locks_held(ShouldDeallocateVirtualRange deallocate_range, ShouldFlushTLB should_flush_tlb, SpinlockLocker<RecursiveSpinlock>&, SpinlockLocker<RecursiveSpinlock>&) { if (!m_page_directory) return; - SpinlockLocker page_lock(m_page_directory->get_lock()); - SpinlockLocker lock(s_mm_lock); size_t count = page_count(); for (size_t i = 0; i < count; ++i) { auto vaddr = vaddr_from_page_index(i); |