From 12300b7d0b1b3735bb1c413ee5d8ac22163ac385 Mon Sep 17 00:00:00 2001 From: Idan Horowitz Date: Sat, 27 Aug 2022 19:00:57 +0300 Subject: [PATCH] Kernel: Dump OOM debug info after releasing the MM global data lock Otherwise we would be holding the MM global data lock and the Process address space locks in reversed order to the rest of the system, which can lead to deadlocks. --- Kernel/Memory/MemoryManager.cpp | 41 +++++++++++++++++---------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/Kernel/Memory/MemoryManager.cpp b/Kernel/Memory/MemoryManager.cpp index 5d108e26bf..4db696a92e 100644 --- a/Kernel/Memory/MemoryManager.cpp +++ b/Kernel/Memory/MemoryManager.cpp @@ -829,28 +829,9 @@ ErrorOr> MemoryManager::allocate_kernel_region_with_vmobje ErrorOr MemoryManager::commit_physical_pages(size_t page_count) { VERIFY(page_count > 0); - return m_global_data.with([&](auto& global_data) -> ErrorOr { + auto result = m_global_data.with([&](auto& global_data) -> ErrorOr { if (global_data.system_memory_info.physical_pages_uncommitted < page_count) { dbgln("MM: Unable to commit {} pages, have only {}", page_count, global_data.system_memory_info.physical_pages_uncommitted); - - Process::for_each([&](Process const& process) { - size_t amount_resident = 0; - size_t amount_shared = 0; - size_t amount_virtual = 0; - process.address_space().with([&](auto& space) { - amount_resident = space->amount_resident(); - amount_shared = space->amount_shared(); - amount_virtual = space->amount_virtual(); - }); - dbgln("{}({}) resident:{}, shared:{}, virtual:{}", - process.name(), - process.pid(), - amount_resident / PAGE_SIZE, - amount_shared / PAGE_SIZE, - amount_virtual / PAGE_SIZE); - return IterationDecision::Continue; - }); - return ENOMEM; } @@ -858,6 +839,26 @@ ErrorOr MemoryManager::commit_physical_pages(size_t pa global_data.system_memory_info.physical_pages_committed += page_count; return CommittedPhysicalPageSet { {}, page_count }; }); + if (result.is_error()) { + Process::for_each([&](Process const& process) { + size_t amount_resident = 0; + size_t amount_shared = 0; + size_t amount_virtual = 0; + process.address_space().with([&](auto& space) { + amount_resident = space->amount_resident(); + amount_shared = space->amount_shared(); + amount_virtual = space->amount_virtual(); + }); + dbgln("{}({}) resident:{}, shared:{}, virtual:{}", + process.name(), + process.pid(), + amount_resident / PAGE_SIZE, + amount_shared / PAGE_SIZE, + amount_virtual / PAGE_SIZE); + return IterationDecision::Continue; + }); + } + return result; } void MemoryManager::uncommit_physical_pages(Badge, size_t page_count)