Repository navigation
BooleOS 0.23.0 - Phase 23: process memory release
Don't want to compile? Download booleos-0.23.0.zip: it has the bootable ISO, a blank disk image and a README.txt. All you need is QEMU; the exact command is in README.txt.
Changes
Added
- A process's page directory and page tables are freed when it exits (Phase 23-B). Until now
process_exit()released the user data pages (since Phase 21) but kept the page directory and every per-process page table, 3 to 4 pages per process, so eachrun,fork()andexec()that ended took memory out of the pool for good. The newvmm_destroy_directory()inkernel/memory/vmm.cdoes the whole teardown in one interrupt-off section:- If the directory being freed is the one loaded in CR3, it loads the kernel directory first. That directory has the same PDE 0 and 1 (the identity map of 0–8 MB), so a process that is exiting itself keeps running on its static kernel stack until
scheduler_yield(), and only loses its user mapping. - For each PDE from 2 up with
VMM_USER, it drops one reference to every present user page and frees the page table. A page still shared copy-on-write with another process stays allocated until its last holder lets go. - It frees the directory page.
- PDE 0 and 1 point at the two static kernel page tables, which every directory shares; they are never touched, and a PDE without
VMM_USERis skipped. The kernel directory itself and 0 are refused. - There is no zombie state and no deferred reaper, because the kernel stack is a static per-slot array and nothing else needs to outlive the exit.
process_exit()copies and zeroescr3, frees the directory and marks the slot unused in the same section, so a second exit of the same process finds the slot unused and does nothing. - A process killed while blocked on
waitpid, a pipe or an ATA command is never scheduled again, so nothing walks its freed directory.
- If the directory being freed is the one loaded in CR3, it loads the kernel directory first. That directory has the same PDE 0 and 1 (the identity map of 0–8 MB), so a process that is exiting itself keeps running on its static kernel stack until
- selftest tests 33 and 34 (34 total, was 32): 30
fork()+exit cycles (each child forces a copy-on-write copy) and 20exec()+exit cycles ofcatmust leave the free PMM page count exactly where it was. pmm_free_page()of a page that is not allocated (already free, or out of range) printspmm: ERROR free of a page that is not allocated (double free?): 0x...on the serial port. It used to return without a word. Nothing else changes in that case.- Documentation: "Freeing a process's address space" and "Double frees" in
docs/memory.md, "Exit and the CR3 in use" indocs/scheduler.md, tests 33 and 34 indocs/testing.md.
Changed
fork()andexec()failure paths (ELF load, user stack, no free slot) free the half-built directory, its page tables and the pages already mapped. They leaked them before.sys_kill()of the caller's own pid now leaves the CPU likesys_exit(). It used to return to user mode, which only worked because the directory leaked.- ROADMAP.md: Phase 23 and sub-phases 23-A to 23-C are marked done. The earlier note that Phase 23 would fix the heap/identity-map design was wrong: the fixed 256 KB kernel heap, the 192 KB limit on FAT16 programs that follows from it, and the way the kernel reaches physical frames only through the 0–8 MB identity map were not touched. That work has no phase scheduled and has to happen before the DOOM port (Phase 31). ROADMAP.md,
PROGRESS.mdanddocs/memory.mdsay so now. docs/kernel.md,docs/testing.md,docs/security.mdanddocs/pipes.mdno longer describe the directory leak as present, anddocs/kernel.mdpoints at Phase 28 (not 23) for syscall deprecation.tools/prev/now holds the v0.22.1 snapshot (kernel + ramfs built from thev0.22.1tag in a clean worktree), so the "previous release" GRUB entry of this version is v0.22.1.kernel/version.his0.23.0, phase23"process memory release"; the README banner and phase table follow.
Known issues
- Four older problems are recorded in
docs/TODO.mdand not fixed. The first, seen while validating this release: after killingselftestwith Ctrl+C during its "file create" test, the kernel heap shrank by 44 bytes (229344 B to 229300 B) and stayed there; the cause is not known. The other three were found while doing this work: a process killed mid ATA command leaves a stale waiter pointer inkernel/drivers/ata.c(it can wake the wrong process if the slot is reused, and the ATA gate is never released if the process held it); a child reserved byfork()orSYS_EXEC_PIPEstays blocked forever if its parent is killed before making it ready;elf_load()would leak a frame if two segments of a program shared a page, which no program in the tree does.
Full history: CHANGELOG.md