Repository navigation
3 Memory Management
Relevant source files
- src/kernel/E820Store.zig
- src/kernel/bitmap.zig
- src/kernel/memory.zig
- src/kernel/page_allocator.zig
- src/kernel/panic.zig
- src/kernel/pic.zig
This section provides a high-level overview of the memory management subsystem in CadenzaOS. The memory architecture bridges early-boot physical memory discovery with higher-half virtual memory mapping, bitmap-based frame allocation, and dynamic 4-level page table management src/kernel/memory.zig1-21src/kernel/frame_allocator.zig1-16.
Because this is a parent page, low-level implementation details are summarized briefly here and delegated to specialized child pages:
- For E820 bootloader map parsing and region discovery, see E820 Memory Map.
- For frame tracking, bitmap management, and contiguous allocation, see Frame Allocator and Bitmap.
- For virtual address translation,
mapPage, and page-level allocation, see Paging and Page Allocation.
Sources: src/kernel/memory.zig1-21src/kernel/frame_allocator.zig1-16
CadenzaOS organizes memory around a higher-half direct map. The kernel code and data structures are mapped into virtual addresses starting at 0xFFFFFF8000000000 (KERNEL_OFFSET), allowing straightforward translation between physical and virtual addresses src/kernel/memory.zig20-35.

Sources: src/kernel/memory.zig1-35src/kernel/frame_allocator.zig32-136
The foundational layer of memory management relies on the BIOS/UEFI E820 memory map collected during early boot stages. The kernel reads this table via E820Store.zig to discover available RAM, reserved memory ranges, and unusable hardware regions src/kernel/E820Store.zig1-57.
For detailed information on parsing routines, E820Store.zig, and diagnostic tools such as e820_test, refer to E820 Memory Map.
Sources: src/kernel/E820Store.zig1-57
Once usable physical memory regions are identified, the frame allocator tracks individual 4 KiB physical frames src/kernel/bitmap.zig1-30. The subsystem utilizes a bitmap structure (bitmap.zig) to record allocated and free frames, initialising all memory as reserved and subsequently carving out usable regions src/kernel/bitmap.zig75-107.
For detailed information on frame tracking, contiguous block allocation, and bitmap manipulation, refer to Frame Allocator and Bitmap.
Sources: src/kernel/bitmap.zig1-107src/kernel/frame_allocator.zig32-136
Virtual memory in CadenzaOS is managed via x86_64 4-level paging (PML4 -> PDPT -> PD -> PT -> Page) src/kernel/memory.zig129-136. The core memory module (memory.zig) provides address translation helpers (physToVirt, virtToPhys) and the dynamic page mapping function mapPage, which allocates missing intermediate table structures on demand using the bitmap frame allocator src/kernel/memory.zig27-160.

Sources: src/kernel/memory.zig95-202
For detailed discussions on mapPage, page allocators, and kernel fault panic handling, refer to Paging and Page Allocation.
Sources: src/kernel/memory.zig95-202src/kernel/page_allocator.zig1-50
- Overview
- Getting Started and Build System
- Kernel Configuration and Global State
- Project Governance and Contributing
- Boot and Early Kernel Initialization
- Bootloader Stages and Linking
- kmain Boot Sequence
- Splash Screen and Branding
- Interrupts, Scheduling, and Syscalls
- IDT, PIC, APIC and IRQ Stubs
- Scheduler and Task Lifecycle
- System Call Interface
- Demonstration Tasks
- CodaFS Filesystem and Storage
- On-Disk Format and Operations
- Space Manager and Block Devices
- Binary Format and Program Loading
- Shell, Terminal, and Display
- Shell Command Pipeline
- Terminal, Input Devices and Prompts
- Display: VGA, Framebuffer, Console and Serial