feature/memory-allocation-optimization
develop
PMM Rewrite:
VMM Correctness Fixes:
LMM Rewrite:
Hardening:
Observability:
Files changed:
PMM Rewrite: - Replace ~8KB record array with compact bitmaps (PhysPresent/PhysAlloc/PhysScanned, 128B each) - Add PhysOwner[0..1023] for per-block ownership tracking - new_block: O(1) amortised via NextFreeHint + dword-level BSF scan, returns 0 as OOM sentinel - free_block: O(1) direct bit clear with double-free detection - alloc_block: validates PhysPresent and PhysAlloc bits before allocation - Add pmm_free_blocks/pmm_total_blocks stats functions VMM Correctness Fixes: - Fix free_page block extraction (Address SHR 10, was using raw Address field) - Fix invlpg operand (use virtual address, was passing PDE index) - Clear PDE entry on free_page before returning block to PMM - Remove map_page double-write (delegate to map_page_ex only) - Add OOM propagation (new_page returns false if PMM returns 0) - Fix missing pop_trace in new_page error path LMM Rewrite: - Replace per-entry record array with bitmap allocator (93% vs 43% page efficiency) - Layout: Header(24B) + Bitmap(64512B) + Padding + Data at 0x10000 - SIZE_PREFIX=16 for 16-byte aligned returns (SSE MOVAPS requirement) - Next-fit bitmap scan with roving hint (NextFree) and dword-level fast skip - Large alloc sentinel (LARGE_ALLOC_MAGIC=$FFFFFFFE) so kfree detects klalloc'd memory - Implement klfree (was previously a no-op - pages could never be returned) - Implement try_release_page (return fully-free heap pages to VMM/PMM) - Fix interrupt safety: stack-balanced pushfd/cli/pop + restore_if (sti only) Fixes Bad TSS caused by popfd restoring dangerous EFLAGS bits (NT, IOPL) - Zero memory via rep stosd instead of byte-by-byte loop Hardening: - kalloc OOM now triggers BSOD instead of returning nil (90% of callers don't check) - Double-free detection in kfree (verify bitmap bits set before clearing) - Guard bytes ({$IFDEF DEBUG_LMM}): $DEADBEEF sentinel for buffer overrun detection - kpalloc: bounds check (block >= 1024 -> GPF) + syslog MMIO mapping audit log Observability: - Add MEMINFO command as src/prog/meminfo.pas (moved from inline kernel.pas) - Displays multiboot memory, PMM block stats, LMM heap stats - Register via progmanager.pas following standard prog pattern Files changed: - src/pmemorymanager.pas - src/vmemorymanager.pas - src/lmemorymanager.pas - src/kernel.pas - src/progmanager.pas - src/prog/meminfo.pas
8b4335768b
f427b7bcc7
No dependencies set.
The note is not visible to the blocked user.
PMM Rewrite:
(PhysPresent/PhysAlloc/PhysScanned, 128B each)
returns 0 as OOM sentinel
VMM Correctness Fixes:
raw Address field)
LMM Rewrite:
(93% vs 43% page efficiency)
fast skip
klalloc'd memory
be returned)
restore_if (sti only)
Fixes Bad TSS caused by popfd restoring dangerous EFLAGS bits (NT, IOPL)
Hardening:
(90% of callers don't check)
Observability:
Files changed:
PMM Rewrite: - Replace ~8KB record array with compact bitmaps (PhysPresent/PhysAlloc/PhysScanned, 128B each) - Add PhysOwner[0..1023] for per-block ownership tracking - new_block: O(1) amortised via NextFreeHint + dword-level BSF scan, returns 0 as OOM sentinel - free_block: O(1) direct bit clear with double-free detection - alloc_block: validates PhysPresent and PhysAlloc bits before allocation - Add pmm_free_blocks/pmm_total_blocks stats functions VMM Correctness Fixes: - Fix free_page block extraction (Address SHR 10, was using raw Address field) - Fix invlpg operand (use virtual address, was passing PDE index) - Clear PDE entry on free_page before returning block to PMM - Remove map_page double-write (delegate to map_page_ex only) - Add OOM propagation (new_page returns false if PMM returns 0) - Fix missing pop_trace in new_page error path LMM Rewrite: - Replace per-entry record array with bitmap allocator (93% vs 43% page efficiency) - Layout: Header(24B) + Bitmap(64512B) + Padding + Data at 0x10000 - SIZE_PREFIX=16 for 16-byte aligned returns (SSE MOVAPS requirement) - Next-fit bitmap scan with roving hint (NextFree) and dword-level fast skip - Large alloc sentinel (LARGE_ALLOC_MAGIC=$FFFFFFFE) so kfree detects klalloc'd memory - Implement klfree (was previously a no-op - pages could never be returned) - Implement try_release_page (return fully-free heap pages to VMM/PMM) - Fix interrupt safety: stack-balanced pushfd/cli/pop + restore_if (sti only) Fixes Bad TSS caused by popfd restoring dangerous EFLAGS bits (NT, IOPL) - Zero memory via rep stosd instead of byte-by-byte loop Hardening: - kalloc OOM now triggers BSOD instead of returning nil (90% of callers don't check) - Double-free detection in kfree (verify bitmap bits set before clearing) - Guard bytes ({$IFDEF DEBUG_LMM}): $DEADBEEF sentinel for buffer overrun detection - kpalloc: bounds check (block >= 1024 -> GPF) + syslog MMIO mapping audit log Observability: - Add MEMINFO command as src/prog/meminfo.pas (moved from inline kernel.pas) - Displays multiboot memory, PMM block stats, LMM heap stats - Register via progmanager.pas following standard prog pattern Files changed: - src/pmemorymanager.pas - src/vmemorymanager.pas - src/lmemorymanager.pas - src/kernel.pas - src/progmanager.pas - src/prog/meminfo.pas8b4335768btof427b7bcc7