SchOS/docs
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
..
architecture kmem: a slab allocator, and what the fixed tables actually cost 2026-09-22 09:32:06 +02:00
branding branding: one mark, and PSOGM draws it 2026-09-21 21:35:58 +02:00
guides docs: the tree moved and the documentation did not 2026-09-13 20:05:06 +02:00
history zsh: two more cache answers that claimed capabilities SchOS lacks 2026-09-22 00:36:48 +02:00
plan kmem: a slab allocator, and what the fixed tables actually cost 2026-09-22 09:32:06 +02:00
Website branding: one mark, and PSOGM draws it 2026-09-21 21:35:58 +02:00
licensing.md userland: 268 applets, an editor, names that resolve, and a web server 2026-09-14 19:24:55 +02:00
README.md branding: one mark, and PSOGM draws it 2026-09-21 21:35:58 +02:00

SchOS documentation

Four kinds of document, kept in four directories, because they answer four different questions and go stale at four different rates.

architecture/ What SchOS is Present tense. Describes what is built and working.
plan/ What SchOS will be Future tense. Everything here is unbuilt.
guides/ How to work on it Imperative. Build it, test it, add to it.
history/ Why it is the way it is Past tense. Bugs whose cause is not visible from the fix.

Plus two that belong to no category and apply to everything: licensing.md — read it before copying anyone else's code in — and branding/, which holds the marks and the rules for using them.


The rule that keeps this from rotting

When something is finished, it moves from plan/ to architecture/ and is rewritten as a description of the thing rather than a record of building it.

A completed item is not a ticked checkbox. A ticked checkbox says the work happened; it does not say what the work produced, and six months later the checkbox is the only thing left and it explains nothing.

So finishing a piece of work has three steps, and the third is not optional:

  1. The code works and is tested.
  2. The plan entry is deleted.
  3. A description exists in architecture/ written for somebody who was not there — what it does, what shape it has, what it costs, and what it still does not do.

This is not bookkeeping. The tree has already proved it necessary: the network stack was finished, verified end to end, and for a month afterwards the only description of it anywhere was a checkbox in a roadmap, four levels of indentation deep, written in the past tense of somebody arguing for the work rather than explaining the result.

The "what it does not do" section is the one that pays. Every description in architecture/ ends with one. A document that only lists a subsystem's strengths is marketing, and the reader who most needs the document is the one about to trip over a limitation nobody wrote down.


Start here

New to the tree → architecture/README.md, the system layer by layer, then guides/layout.md for where the files are.

Trying to build it → guides/building.md.

Wondering what happens next → plan/1.0.md, which is the finish line and the register of everything half-built. Then plan/README.md for the order.

About to start something new → the register, first. Nothing new starts while it has rows in it, and a row leaves only by being finished or deleted.

Something is broken and it feels familiar → history/. There is a good chance it is in there.


architecture/ — what SchOS is

README The system, layer by layer. Read first.
boot.md Firmware to the first userspace process.
kernel.md SchIFT: memory, processes, scheduling, traps, signals, SMP.
syscalls.md The call table, and the Linux personality that lets real software run.
filesystem.md The VFS, the buffer cache, procfs, mounts.
schfs.md SchFS: the copy-on-write root filesystem.
devices.md The device model, driver binding, the class vtables.
usb.md xHCI, the USB core, and the class drivers.
graphics.md Framebuffer, text rendering, console, and the crash screen.
terminals.md The six virtual terminals, and how one is switched to.
networking.md Drivers, lwIP, sockets — Unix and INET.
init.md schinit, PID 1 as a role, and the job manifests.

plan/ — what SchOS will be

README The three current decisions and the order they happen in.
1.0.md The finish line, and the freeze. What 1.0 contains, what is deferred, and the register of every half-built thing in the tree.
foundations.md The kernel work everything else is blocked on.
wayland.md The GUI stack, and what gets deleted to make room.
hybrid.md Moving drivers out of the kernel.
schapi.md The long-term API layering, and the compatibility promise.
roadmap.md Everything else still open.

guides/ — how to work on it

building.md Prerequisites and the build, per host.
testing.md The harnesses, and what each one actually proves.
layout.md Repository map, and how to add a program or a port.
adding-a-driver.md Writing one, binding it, publishing its class vtable.

branding/ — the marks

README Shift, the one mark: what it is for, the colour rule, why an icon and a mascot were removed, and why a raster is committed next to its SVG.

history/ — why it is the way it is

README What belongs in here and what does not.
kernel.md Bugs whose cause was nowhere near their symptom.
schfs.md The filesystem's own, from the same period as its design.
moving-to-linux.md The Windows-to-Fedora move, kept for the parts that recur.

Writing one of these

Four conventions, all of them observable in the existing files:

State the cost. Every design choice gave something up. A document that does not say what is a document that will be argued with later by somebody who only sees the downside.

Prefer the measured number to the remembered one. "500 of 3565 files carry the advertising clause" is worth more than "some do", and it was worth the minute it took to count.

Write down the bug that shaped it. Half the non-obvious code in this tree is non-obvious because something failed once. If a design is strange, the strangeness is load-bearing and the reader deserves to know why before changing it.

No dates in headings. A date in a heading turns a description into a changelog, and the description is the thing with a long life. Dates belong in history/, where they mean something.