Skip to content

Commit d6ef18f

Browse files
committed
Kernel: Don't hog the MM lock while unmapping regions
We were holding the MM lock across all of the region unmapping code. This was previously necessary since the quickmaps used during unmapping required holding the MM lock. Now that it's no longer necessary, we can leave the MM lock alone here.
1 parent dc9d2c1 commit d6ef18f

File tree

3 files changed

+5
-8
lines changed

3 files changed

+5
-8
lines changed

Kernel/Memory/AddressSpace.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -341,10 +341,9 @@ void AddressSpace::remove_all_regions(Badge<Process>)
341341
VERIFY(Thread::current() == g_finalizer);
342342
{
343343
SpinlockLocker pd_locker(m_page_directory->get_lock());
344-
SpinlockLocker mm_locker(s_mm_lock);
345344
m_region_tree.with([&](auto& region_tree) {
346345
for (auto& region : region_tree.regions())
347-
region.unmap_with_locks_held(ShouldFlushTLB::No, pd_locker, mm_locker);
346+
region.unmap_with_locks_held(ShouldFlushTLB::No, pd_locker);
348347
});
349348
}
350349

Kernel/Memory/Region.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,7 @@ Region::~Region()
7070
if (!is_readable() && !is_writable() && !is_executable()) {
7171
// If the region is "PROT_NONE", we didn't map it in the first place.
7272
} else {
73-
SpinlockLocker mm_locker(s_mm_lock);
74-
unmap_with_locks_held(ShouldFlushTLB::Yes, pd_locker, mm_locker);
73+
unmap_with_locks_held(ShouldFlushTLB::Yes, pd_locker);
7574
VERIFY(!m_page_directory);
7675
}
7776
}
@@ -268,11 +267,10 @@ void Region::unmap(ShouldFlushTLB should_flush_tlb)
268267
if (!m_page_directory)
269268
return;
270269
SpinlockLocker pd_locker(m_page_directory->get_lock());
271-
SpinlockLocker mm_locker(s_mm_lock);
272-
unmap_with_locks_held(should_flush_tlb, pd_locker, mm_locker);
270+
unmap_with_locks_held(should_flush_tlb, pd_locker);
273271
}
274272

275-
void Region::unmap_with_locks_held(ShouldFlushTLB should_flush_tlb, SpinlockLocker<RecursiveSpinlock>&, SpinlockLocker<RecursiveSpinlock>&)
273+
void Region::unmap_with_locks_held(ShouldFlushTLB should_flush_tlb, SpinlockLocker<RecursiveSpinlock>&)
276274
{
277275
if (!m_page_directory)
278276
return;

Kernel/Memory/Region.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ class Region final
183183
void set_page_directory(PageDirectory&);
184184
ErrorOr<void> map(PageDirectory&, ShouldFlushTLB = ShouldFlushTLB::Yes);
185185
void unmap(ShouldFlushTLB = ShouldFlushTLB::Yes);
186-
void unmap_with_locks_held(ShouldFlushTLB, SpinlockLocker<RecursiveSpinlock>& pd_locker, SpinlockLocker<RecursiveSpinlock>& mm_locker);
186+
void unmap_with_locks_held(ShouldFlushTLB, SpinlockLocker<RecursiveSpinlock>& pd_locker);
187187

188188
void remap();
189189

0 commit comments

Comments
 (0)