From bce510bf6ff14ccd86507e560e734cb56d754b20 Mon Sep 17 00:00:00 2001 From: Liav A <51659396+supercomputer7@users.noreply.github.com> Date: Fri, 8 Nov 2019 23:39:29 +0200 Subject: Kernel: Fix the search method of free userspace physical pages (#742) Now the userspace page allocator will search through physical regions, and stop the search as it finds an available page. Also remove an "address of" sign since we don't need that when counting size of physical regions --- Kernel/VM/MemoryManager.cpp | 17 +++++++++++------ Kernel/VM/MemoryManager.h | 1 + 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/Kernel/VM/MemoryManager.cpp b/Kernel/VM/MemoryManager.cpp index 39fa0ad3c6..885cdbd19f 100644 --- a/Kernel/VM/MemoryManager.cpp +++ b/Kernel/VM/MemoryManager.cpp @@ -144,7 +144,7 @@ void MemoryManager::initialize_paging() } else { if (region.is_null() || region_is_super || region->upper().offset(PAGE_SIZE) != addr) { m_user_physical_regions.append(PhysicalRegion::create(addr, addr)); - region = &m_user_physical_regions.last(); + region = m_user_physical_regions.last(); region_is_super = false; } else { region->expand(region->lower(), addr); @@ -386,16 +386,21 @@ void MemoryManager::deallocate_user_physical_page(PhysicalPage&& page) ASSERT_NOT_REACHED(); } -RefPtr MemoryManager::allocate_user_physical_page(ShouldZeroFill should_zero_fill) +RefPtr MemoryManager::find_free_user_physical_page() { - InterruptDisabler disabler; RefPtr page; - for (auto& region : m_user_physical_regions) { page = region.take_free_page(false); - if (page.is_null()) - continue; + if (!page.is_null()) + break; } + return page; +} + +RefPtr MemoryManager::allocate_user_physical_page(ShouldZeroFill should_zero_fill) +{ + InterruptDisabler disabler; + RefPtr page = find_free_user_physical_page(); if (!page) { if (m_user_physical_regions.is_empty()) { diff --git a/Kernel/VM/MemoryManager.h b/Kernel/VM/MemoryManager.h index 9a3ffd1018..399d0f1502 100644 --- a/Kernel/VM/MemoryManager.h +++ b/Kernel/VM/MemoryManager.h @@ -103,6 +103,7 @@ private: static Region* region_from_vaddr(VirtualAddress); + RefPtr find_free_user_physical_page(); u8* quickmap_page(PhysicalPage&); void unquickmap_page(); -- cgit v1.2.3