From 3ec54fafdeff07d58562bfe65d1320193f03e124 Mon Sep 17 00:00:00 2001 From: apio Date: Mon, 27 Feb 2023 12:55:15 +0100 Subject: [PATCH] x86_64/MMU: Do not allocate level 1 page tables for huge page entries This would leak memory, since we would never end up using them. --- kernel/src/arch/x86_64/MMU.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/kernel/src/arch/x86_64/MMU.cpp b/kernel/src/arch/x86_64/MMU.cpp index 760508c4..cc91b6c3 100644 --- a/kernel/src/arch/x86_64/MMU.cpp +++ b/kernel/src/arch/x86_64/MMU.cpp @@ -212,11 +212,16 @@ namespace MMU auto& l2 = l2_entry(l3, virt); if (!l2.present) { - const u64 addr = TRY(MemoryManager::alloc_frame()); l2.present = true; - l2.set_address(addr); - memset(&page_table(l2), 0, ARCH_PAGE_SIZE); + + if (use_huge_pages == UseHugePages::No) + { + const u64 addr = TRY(MemoryManager::alloc_frame()); + l2.set_address(addr); + memset(&page_table(l2), 0, ARCH_PAGE_SIZE); + } } + if (flags & Flags::ReadWrite) l2.read_write = true; if (flags & Flags::User) l2.user = true;