-
-
Notifications
You must be signed in to change notification settings - Fork 4
Memory Management
kazah-png edited this page Jul 11, 2026
·
3 revisions
NyxOS uses a layered memory strategy: bitmap physical allocator, 4-level paging, kernel heap, and slab caches.
See also: Architecture, Boot Process, Process Management, Security
Bitmap tracking each 4 KB page, up to 512 MB max RAM. alloc_page() / free_page().
PML4 → PDPT → PD → PT → 4 KB page. Higher-half kernel at PML4[511]. Identity-mapped first 64 MB.
-
Demand paging: PTE bit 9 (
PTE_DEMAND) — allocate zeroed page on first touch via #PF handler -
Copy-on-write: PTE bit 10 (
PTE_COW) — private copy on write fault via #PF handler (used byfork(), see Process Management) - NX bit: Non-executable user stack/data pages
- CR0.WP: Supervisor writes to read-only pages fault (required for COW)
-
vm_handle_fault: resolves user page faults (demand, COW, file-backed mmap slice, lazy sbrk heap) -
vm_protect_range: rewrites present-page flags formprotect(writable per PROT_WRITE, NX unless PROT_EXEC)
-
mmap (
mmap.c): anonymous MAP_PRIVATE with demand-zero pages; file-backed snapshots into per-VMA buffers (copied from file offset) -
mprotect: change protection of mapped ranges (updates both present PTEs and VMA prot) -
munmap: free present pages (refcount-aware) and drop VMAs; file buffers freed with the VMA -
fork COW:
clone_page_directory_cow+vm_handle_fault— shared until first write (see Process Management) - Lazy sbrk: break moves without allocating; pages materialise on first touch via the #PF handler
16 MB heap with free-list, header/footer metadata, coalescing. kmalloc/kfree with slab fallback.
Fixed-size caches: 8, 16, 32, 64, 128, 256, 512, 1024 bytes. kmalloc falls back to heap when no slab fits.
Contact: uselessalter on Discord | nyxos@inbox.lv | GitHub