kernel: Rewrite guarded_heap.

Compared to the old kernel guarded heap, this new one:

 * Uses VMTranslationMap and related APIs directly, rather than
   indirectly through the "protection cookie" system. This means
   those custom APIs, which nothing else except the guarded heap
   used, can now be dropped.

 * Does not allocate vm_pages for guard pages, and frees vm_pages
   when not in use. This means that DISABLE_MEMORY_REUSE is much
   more usable now, as it only does not reuse virtual memory,
   allowing for much longer-running systems.

 * Uses trees to manage meta chunks. This avoids unbounded growth
   of the meta chunk count, especially under DISABLE_MEMORY_REUSE.

 * Handles page faults directly and prints information about the
   fault address/allocation automatically.

The system still boots and runs fine with this new guarded heap,
including under USE...FOR_OBJECT_CACHE.

Change-Id: If85e5689a47088790287990c881364fcde4cc76d
Reviewed-on: https://review.haiku-os.org/c/haiku/+/9705
Reviewed-by: waddlesplash <[email protected]>
This commit is contained in:
Augustin Cavalier
2025-10-31 02:36:19 +00:00
committed by waddlesplash
parent 90fa6d12f0
commit d36a3e286b
5 changed files with 1029 additions and 1128 deletions
-1
View File
@@ -31,7 +31,6 @@ KernelMergeObject kernel_core.o :
cpu.cpp cpu.cpp
DPC.cpp DPC.cpp
elf.cpp elf.cpp
guarded_heap.cpp
heap.cpp heap.cpp
image.cpp image.cpp
interrupts.cpp interrupts.cpp
+1
View File
@@ -24,6 +24,7 @@ KernelMergeObject kernel_debug.o :
font_big.cpp font_big.cpp
frame_buffer_console.cpp frame_buffer_console.cpp
gdb.cpp gdb.cpp
guarded_heap.cpp
safemode_settings.cpp safemode_settings.cpp
system_profiler.cpp system_profiler.cpp
tracing.cpp tracing.cpp
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+1 -1
View File
@@ -3992,7 +3992,7 @@ vm_init(kernel_args* args)
// allocate areas to represent stuff that already exists // allocate areas to represent stuff that already exists
#if USE_DEBUG_HEAP_FOR_MALLOC || USE_GUARDED_HEAP_FOR_MALLOC #if USE_DEBUG_HEAP_FOR_MALLOC
address = (void*)ROUNDDOWN(heapBase, B_PAGE_SIZE); address = (void*)ROUNDDOWN(heapBase, B_PAGE_SIZE);
create_area("kernel heap", &address, B_EXACT_ADDRESS, heapSize, create_area("kernel heap", &address, B_EXACT_ADDRESS, heapSize,
B_ALREADY_WIRED, B_KERNEL_READ_AREA | B_KERNEL_WRITE_AREA); B_ALREADY_WIRED, B_KERNEL_READ_AREA | B_KERNEL_WRITE_AREA);