From 46a1903f8d92d78a29789c7f4c5600baf5583046 Mon Sep 17 00:00:00 2001 From: Bananymous Date: Wed, 20 May 2026 02:46:50 +0300 Subject: [PATCH] Kernel: Use per cpu fast page for PMM --- kernel/kernel/Memory/PhysicalRange.cpp | 27 +++++++++++++------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/kernel/kernel/Memory/PhysicalRange.cpp b/kernel/kernel/Memory/PhysicalRange.cpp index 9c763c39..5755be60 100644 --- a/kernel/kernel/Memory/PhysicalRange.cpp +++ b/kernel/kernel/Memory/PhysicalRange.cpp @@ -21,8 +21,8 @@ namespace Kernel const size_t bitmap_page_count = BAN::Math::div_round_up(m_page_count, bits_per_page); for (size_t i = 0; i < bitmap_page_count; i++) { - PageTable::with_fast_page(paddr + i * PAGE_SIZE, [] { - memset(PageTable::fast_page_as_ptr(), 0, PAGE_SIZE); + PageTable::with_per_cpu_fast_page(paddr + i * PAGE_SIZE, [](void* addr) { + memset(addr, 0, PAGE_SIZE); }); } @@ -40,15 +40,15 @@ namespace Kernel BAN::Optional page_matched_bit; const paddr_t current_paddr = m_paddr + i * PAGE_SIZE; - PageTable::with_fast_page(current_paddr, [&page_matched_bit] { + PageTable::with_per_cpu_fast_page(current_paddr, [&page_matched_bit](void* addr) { for (size_t j = 0; j < PAGE_SIZE / sizeof(size_t); j++) { static_assert(sizeof(size_t) == sizeof(long)); - const size_t current = PageTable::fast_page_as_sized(j); + auto& current = static_cast(addr)[j]; if (current == BAN::numeric_limits::max()) continue; const int ctz = __builtin_ctzl(~current); - PageTable::fast_page_as_sized(j) = current | (static_cast(1) << ctz); + current |= static_cast(1) << ctz; page_matched_bit = j * sizeof(size_t) * 8 + ctz; return; } @@ -75,15 +75,14 @@ namespace Kernel const size_t paddr_index = (paddr - m_paddr) / PAGE_SIZE; - PageTable::with_fast_page(m_paddr + paddr_index / bits_per_page * PAGE_SIZE, [paddr_index] { + PageTable::with_per_cpu_fast_page(m_paddr + paddr_index / bits_per_page * PAGE_SIZE, [paddr_index] (void* addr) { const size_t bitmap_bit = paddr_index % bits_per_page; const size_t byte = bitmap_bit / 8; const size_t bit = bitmap_bit % 8; - volatile uint8_t& bitmap_byte = PageTable::fast_page_as_sized(byte); + uint8_t& bitmap_byte = static_cast(addr)[byte]; ASSERT(bitmap_byte & (1u << bit)); - - bitmap_byte = bitmap_byte & ~(1u << bit); + bitmap_byte &= ~(1u << bit); }); m_free_pages++; @@ -103,8 +102,8 @@ namespace Kernel const size_t bit = bit_index % 8; uint8_t current; - PageTable::with_fast_page(m_paddr + page_index * PAGE_SIZE, [¤t, byte] { - current = PageTable::fast_page_as_sized(byte); + PageTable::with_per_cpu_fast_page(m_paddr + page_index * PAGE_SIZE, [¤t, byte](void* addr) { + current = static_cast(addr)[byte]; }); return current & (1u << bit); @@ -117,9 +116,9 @@ namespace Kernel const size_t bit_index = buffer_bit % bits_per_page; const size_t byte = bit_index / 8; const size_t bit = bit_index % 8; - PageTable::with_fast_page(m_paddr + page_index * PAGE_SIZE, [byte, bit] { - volatile uint8_t& current = PageTable::fast_page_as_sized(byte); - current = current | (1u << bit); + PageTable::with_per_cpu_fast_page(m_paddr + page_index * PAGE_SIZE, [byte, bit](void* addr) { + uint8_t& current = static_cast(addr)[byte]; + current |= 1u << bit; }); };