mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-05-28 05:52:53 +00:00
Kernel: Simplify VMObject locking & page fault handlers
This patch greatly simplifies VMObject locking by doing two things: 1. Giving VMObject an IntrusiveList of all its mapping Region objects. 2. Removing VMObject::m_paging_lock in favor of VMObject::m_lock Before (1), VMObject::for_each_region() was forced to acquire the global MM lock (since it worked by walking MemoryManager's list of all regions and checking for regions that pointed to itself.) With each VMObject having its own list of Regions, VMObject's own m_lock is all we need. Before (2), page fault handlers used a separate mutex for preventing overlapping work. This design required multiple temporary unlocks and was generally extremely hard to reason about. Instead, page fault handlers now use VMObject's own m_lock as well.
This commit is contained in:
parent
64babcaa83
commit
082ed6f417
Notes:
sideshowbarker
2024-07-18 08:30:11 +09:00
Author: https://github.com/awesomekling
Commit: 082ed6f417
10 changed files with 116 additions and 155 deletions
|
@ -684,7 +684,6 @@ Region* MemoryManager::find_region_from_vaddr(VirtualAddress vaddr)
|
|||
PageFaultResponse MemoryManager::handle_page_fault(PageFault const& fault)
|
||||
{
|
||||
VERIFY_INTERRUPTS_DISABLED();
|
||||
ScopedSpinLock lock(s_mm_lock);
|
||||
if (Processor::current().in_irq()) {
|
||||
dbgln("CPU[{}] BUG! Page fault while handling IRQ! code={}, vaddr={}, irq level: {}",
|
||||
Processor::id(), fault.code(), fault.vaddr(), Processor::current().in_irq());
|
||||
|
@ -696,8 +695,7 @@ PageFaultResponse MemoryManager::handle_page_fault(PageFault const& fault)
|
|||
if (!region) {
|
||||
return PageFaultResponse::ShouldCrash;
|
||||
}
|
||||
|
||||
return region->handle_fault(fault, lock);
|
||||
return region->handle_fault(fault);
|
||||
}
|
||||
|
||||
OwnPtr<Region> MemoryManager::allocate_contiguous_kernel_region(size_t size, StringView name, Region::Access access, Region::Cacheable cacheable)
|
||||
|
@ -878,7 +876,7 @@ RefPtr<PhysicalPage> MemoryManager::allocate_user_physical_page(ShouldZeroFill s
|
|||
for_each_vmobject([&](auto& vmobject) {
|
||||
if (!vmobject.is_anonymous())
|
||||
return IterationDecision::Continue;
|
||||
int purged_page_count = static_cast<AnonymousVMObject&>(vmobject).purge_with_interrupts_disabled({});
|
||||
int purged_page_count = static_cast<AnonymousVMObject&>(vmobject).purge();
|
||||
if (purged_page_count) {
|
||||
dbgln("MM: Purge saved the day! Purged {} pages from AnonymousVMObject", purged_page_count);
|
||||
page = find_free_user_physical_page(false);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue