[GH-ISSUE #83] kernel (ppc): srv boot sizes the buffer map from RAM and can use most of the 1GB kernel address space #76

Closed
opened 2026-11-03 22:04:13 -07:00 by gitea-mirror · 0 comments
Owner

Originally created by @raynorpat on GitHub (Oct 30, 2026).
Original GitHub issue: https://github.com/RhapsodiOS/RhapsodiOS/issues/83

Summary

On ppc, booting with the srv boot argument makes buffer_map_sizer() (src/kernel-7/machdep/ppc/unix_startup.c, MACH_NBC path) give the buffer cache half of RAM. Above about 470MB that reserves roughly 700MB of the kernel's 1GB address space for the buffer map. Together with the zone map, about 830MB is gone before anything else is allocated.

Details

The ppc kernel address space is 0x4000–0x3ffff000 (mach/ppc/vm_param.h), about 1GB, separate from user space. buffer_map_sizer() returns nbuf * MAXBSIZE + niobuf * MAXPHYSIO, which startup() carves out of kernel_map.

With srv set and mem_size > 64MB:

  • bufpages = atop(mem_size) / 2, capped at 60000 pages, which is 234MB of 4KB pages. The cap is reached at about 470MB of RAM.
  • nbuf = bufpages + 64 = 60064, at MAXBSIZE (8192) each: about 469MB of address space.
  • niobuf = bufpages / (MAXPHYSIO / page_size) = 3750, at MAXPHYS (64KB) each: about 234MB.
  • That is about 703MB for the buffer map.
  • zone_map_sizer() adds mem_size / 4, at most 128MB, on ppc.

That leaves under 200MB for everything else in kernel_map, and less once the kernel image is counted: kalloc and kmem_alloc, kernel stacks, the mbuf map and driver allocations. Without srv the cache is 3% of RAM (about 180MB of address space at 2GB), which is fine.

Expected failure

A server-mode boot on a ppc machine with 512MB or more of RAM may fail at boot or run out of kernel_map space under load: kernel stack, mbuf or driver allocations fail, or allocation panics. Not reproduced yet; found by reading the code.

Suggested fix

Bound the server-mode buffer cache by the kernel address space rather than RAM. For example, cap bufpages so buffer_map_sizer() stays under a fixed share of VM_MAX_KERNEL_ADDRESS - VM_MIN_KERNEL_ADDRESS. Then confirm a 1GB and a 2GB QEMU mac99 boot with srv=1.

Originally created by @raynorpat on GitHub (Oct 30, 2026). Original GitHub issue: https://github.com/RhapsodiOS/RhapsodiOS/issues/83 ## Summary On ppc, booting with the `srv` boot argument makes `buffer_map_sizer()` (`src/kernel-7/machdep/ppc/unix_startup.c`, `MACH_NBC` path) give the buffer cache half of RAM. Above about 470MB that reserves roughly 700MB of the kernel's 1GB address space for the buffer map. Together with the zone map, about 830MB is gone before anything else is allocated. ## Details The ppc kernel address space is `0x4000`–`0x3ffff000` (`mach/ppc/vm_param.h`), about 1GB, separate from user space. `buffer_map_sizer()` returns `nbuf * MAXBSIZE + niobuf * MAXPHYSIO`, which `startup()` carves out of `kernel_map`. With `srv` set and `mem_size > 64MB`: - `bufpages = atop(mem_size) / 2`, capped at 60000 pages, which is 234MB of 4KB pages. The cap is reached at about 470MB of RAM. - `nbuf = bufpages + 64` = 60064, at `MAXBSIZE` (8192) each: about 469MB of address space. - `niobuf = bufpages / (MAXPHYSIO / page_size)` = 3750, at `MAXPHYS` (64KB) each: about 234MB. - That is about 703MB for the buffer map. - `zone_map_sizer()` adds `mem_size / 4`, at most 128MB, on ppc. That leaves under 200MB for everything else in `kernel_map`, and less once the kernel image is counted: `kalloc` and `kmem_alloc`, kernel stacks, the mbuf map and driver allocations. Without `srv` the cache is 3% of RAM (about 180MB of address space at 2GB), which is fine. ## Expected failure A server-mode boot on a ppc machine with 512MB or more of RAM may fail at boot or run out of `kernel_map` space under load: kernel stack, mbuf or driver allocations fail, or allocation panics. **Not reproduced yet**; found by reading the code. ## Suggested fix Bound the server-mode buffer cache by the kernel address space rather than RAM. For example, cap `bufpages` so `buffer_map_sizer()` stays under a fixed share of `VM_MAX_KERNEL_ADDRESS - VM_MIN_KERNEL_ADDRESS`. Then confirm a 1GB and a 2GB QEMU mac99 boot with `srv=1`.
gitea-mirror 2026-11-03 22:04:13 -07:00
  • closed this issue
  • added the
    bug
    label
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github-starred/RhapsodiOS#76
No description provided.