SchOS/include
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Nexoniarz c98bdf0019 kmem: a slab allocator, and what the fixed tables actually cost
Gate 0's last structural row. kernel/core/kmem.c: slabs are pages from
kalloc() with a header at the front, and free objects hold the free list in
their own first eight bytes.

That last detail is the whole design. **An object carries no header and
freeing performs no search**: the page base of any object *is* its slab, and
the slab names its cache. It is also exactly why an object cannot exceed a
page, which matters below.

Two interfaces. kmem_cache_create/alloc/free for a subsystem with one kind of
thing -- it gets its own line in /proc/slab, which is most of why naming it is
worth the argument -- and kmalloc/kmfree over power-of-two classes from 16 to
2048 for code with no single type to build a cache around. Each cache keeps
partial and full lists; a slab that empties goes straight back to kalloc()
rather than being kept, so /proc/slab never overstates what is held.

`make kmem-test` asserts the bookkeeping on the build machine. Same arrangement
as schfs-objtest, and for the same reason: slab lists, free-list threading, the
page-to-cache lookup and whether pages actually come back are all things that
can be wrong without a kernel to be wrong in. 26 checks, including one that a
permissive allocator cannot pass -- write a distinct pattern through 512
objects and read them all back, because two objects sharing storage shows up
there and nowhere else.

One bug the test found immediately: kmem_max_obj() returned the raw page
remainder, which kmem_cache_create() then rounded *up* past its own limit. The
largest legal size was reported as illegal.

**It does not do what the register said it would.** The claim was that every
fixed table exists to work around kalloc. Measured:

    struct proc    10656    NPROC 128     larger than a page
    struct socket   4928    NSOCK 32      larger than a page
    struct buf      4272    NBUF 256      larger than a page
    struct inode     280    NINODE 200    a cache, bounded on purpose
    struct device    120    NDEVICE 32    3.8 KB, never hit
    struct file       48    NFILE 512     24 KB, never hit

The three largest cannot go in a page-backed slab whatever it does. NINODE is
a cache and is meant to be bounded. NFILE and NDEVICE are small enough that
their tables are rounding errors and their ceilings have never been reached.
Freeing the big ones needs a contiguous multi-page allocator, which is a
different thing and is not written. That is now in the register and in
docs/architecture/kernel.md rather than left as a claim nobody checked.

What it does fix is real, and was measured rather than assumed:

  - **A pipe is 640 bytes and came from a whole 4096-byte page.** Every `|` in
    a shell command burned three and a half kilobytes it never touched. Six
    pipes per page now, and /proc/slab shows the page going back when they
    close.
  - **procread() built its answer in a 2048-byte array on the kernel stack**,
    under a comment that had warned about exactly that since it was written --
    it stayed a local because a whole page for 2 KB felt worse, and kmalloc is
    the answer that was missing. Its frame is 64 bytes now instead of ~2100.
  - procfs's other generator took a page from kalloc for the same 2 KB.

Verified on a boot: /proc/slab tracks pipe and kmalloc-2048 through real
pipelines, allocs and frees balance, and $(), ps, time, readlink, sigtest and
rename are all still green with no traps.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-22 09:32:06 +02:00
..
asm.h Initial commit: Schunix as it stands before the SchOS rename 2026-08-09 13:47:01 +02:00
buf.h Raise the disk ceiling: 64-bit blocks, no FSSIZE panic, LBA48 2026-08-10 18:50:31 +02:00
config_sinit.h Initial commit: Schunix as it stands before the SchOS rename 2026-08-09 13:47:01 +02:00
date.h Initial commit: Schunix as it stands before the SchOS rename 2026-08-09 13:47:01 +02:00
dbg.h debugger: D5, the network transport -- and the plan closes 2026-09-14 15:33:53 +02:00
defs.h proc: real CPU time, a tty number, and an exe that is a symlink 2026-09-22 02:45:00 +02:00
device.h docs: four directories, and a rule for when a thing leaves the roadmap 2026-09-12 17:13:35 +02:00
display.h Initial commit: Schunix as it stands before the SchOS rename 2026-08-09 13:47:01 +02:00
dma.h dma: the 4 MB cap was the refusal, not the arena 2026-09-14 22:52:20 +02:00
elf.h Initial commit: Schunix as it stands before the SchOS rename 2026-08-09 13:47:01 +02:00
errno.h schfs: a format version policy, and refusing is not falling back 2026-09-12 17:13:59 +02:00
fb.h Rename Schunix to SchOS; the kernel becomes SchIFT 2026-08-09 14:09:59 +02:00
fcntl.h Rename Schunix to SchOS; the kernel becomes SchIFT 2026-08-09 14:09:59 +02:00
file.h fs: devtmpfs, so /dev is generated rather than written to a disk 2026-09-12 20:18:30 +02:00
font.h Rename Schunix to SchOS; the kernel becomes SchIFT 2026-08-09 14:09:59 +02:00
fs.h init survives stray signals; commands are 4-34x faster 2026-08-09 15:54:05 +02:00
fsstat.h fs: timestamps come from the clock, and /proc/fsstat says how full the tables are 2026-09-12 17:14:14 +02:00
gfx.h font: the console draws outlines now, and a byte could not have held Ą 2026-09-20 00:35:34 +02:00
input.h usb-hid: bind an absolute pointer, and plumb EV_ABS through 2026-08-10 18:27:01 +02:00
ioperm.h ldls: a second driver, and everything it found 2026-09-14 15:20:07 +02:00
irq.h hybrid: interrupts to userspace, and a crashed driver that stays crashed 2026-09-13 18:11:00 +02:00
kbd.h kbd: three layouts, and the arrow keys were sitting on top of UTF-8 2026-09-20 01:09:32 +02:00
keymap.h kbd: three layouts, and the arrow keys were sitting on top of UTF-8 2026-09-20 01:09:32 +02:00
klog.h debugger: D5, the network transport -- and the plan closes 2026-09-14 15:33:53 +02:00
kmem.h kmem: a slab allocator, and what the fixed tables actually cost 2026-09-22 09:32:06 +02:00
logo.h docs: a branding folder, and the three marks are not interchangeable 2026-09-12 18:19:09 +02:00
memlayout.h Free every usable memory region, not one contiguous run 2026-08-09 20:03:51 +02:00
mmu.h Initial commit: Schunix as it stands before the SchOS rename 2026-08-09 13:47:01 +02:00
mp.h Initial commit: Schunix as it stands before the SchOS rename 2026-08-09 13:47:01 +02:00
netdev.h net: a frame wakes the stack, instead of waiting for the clock 2026-09-12 17:23:46 +02:00
netuser.h ldls: L4 was free after all, and the plan closes 2026-09-14 13:37:04 +02:00
param.h kstack: 3736 of 4096 bytes, measured, and the AP got a page it did not own 2026-09-21 21:05:15 +02:00
pci.h hybrid: the GPU driver now runs in userspace 2026-09-13 18:27:41 +02:00
pciuser.h hybrid: the GPU driver now runs in userspace 2026-09-13 18:27:41 +02:00
posix.h signal: the return trampoline was Linux-only, and a test that proves the rest 2026-09-21 23:56:34 +02:00
proc.h proc: real CPU time, a tty number, and an exe that is a symlink 2026-09-22 02:45:00 +02:00
qr.h docs: four directories, and a rule for when a thing leaves the roadmap 2026-09-12 17:13:35 +02:00
sbuf.h debugger: D5, the network transport -- and the plan closes 2026-09-14 15:33:53 +02:00
schboot.h boot/uefi: the memory map the kernel gets is the one the firmware agreed to 2026-08-11 11:42:22 +02:00
schfs.h schfs: records at arbitrary offsets are packed, and the compiler is told 2026-09-12 17:56:36 +02:00
schinit.h hybrid: the driver is killed, and the driver comes back 2026-09-14 00:05:43 +02:00
sleeplock.h Initial commit: Schunix as it stands before the SchOS rename 2026-08-09 13:47:01 +02:00
socket.h debugger: D5, the network transport -- and the plan closes 2026-09-14 15:33:53 +02:00
spinlock.h Initial commit: Schunix as it stands before the SchOS rename 2026-08-09 13:47:01 +02:00
stat.h Initial commit: Schunix as it stands before the SchOS rename 2026-08-09 13:47:01 +02:00
syscall.h Initial commit: Schunix as it stands before the SchOS rename 2026-08-09 13:47:01 +02:00
text.h Initial commit: Schunix as it stands before the SchOS rename 2026-08-09 13:47:01 +02:00
theme.h gfx: the console and the crash screen stop drawing on a driver by name 2026-08-15 17:04:10 +02:00
traps.h Initial commit: Schunix as it stands before the SchOS rename 2026-08-09 13:47:01 +02:00
ttf.h Initial commit: Schunix as it stands before the SchOS rename 2026-08-09 13:47:01 +02:00
types.h Initial commit: Schunix as it stands before the SchOS rename 2026-08-09 13:47:01 +02:00
uaccess.h Rename Schunix to SchOS; the kernel becomes SchIFT 2026-08-09 14:09:59 +02:00
usb.h usb-hid: bind an absolute pointer, and plumb EV_ABS through 2026-08-10 18:27:01 +02:00
user.h signal: the return trampoline was Linux-only, and a test that proves the rest 2026-09-21 23:56:34 +02:00
virtio.h hybrid: a modeset, from a process 2026-09-14 01:36:05 +02:00
vt.h font: the console draws outlines now, and a byte could not have held Ą 2026-09-20 00:35:34 +02:00
x86.h schfs: the commit barrier, reflink, and attributes with an index over them 2026-08-15 16:02:02 +02:00