LLAM v3.0.1

Architecture

Edit pageReport a problemLast modified: 03 December 2026

This page summarizes the implementation boundaries. The public contract remains the headers under include/llam/; internal file names and layouts are not ABI.

On this page

N:M model

LLAM is a user-level N:M thread scheduler. Portable tasks share OS workers and processor capacity; native-affine tasks retain a dedicated native worker. Each task has its own stack. Cooperative transfers can stay in user space, while qualified asynchronous capture uses the platform's kernel transport.

Unit What it is
Task A void (*)(void *) function with its own guarded fiber stack.
Processor (P) Owns scheduler queues, timers, and allocation state, retained in shard storage. Compatibility workers normally keep their home P. Registered managed workers (Ms) acquire and return P execution leases, so a P is not permanently tied to one native M.
Node A platform I/O backend: an io_uring ring on Linux, a kqueue fd on macOS, or an IOCP port on Windows, plus watch tables, submit queues, and control queues. Shards submit I/O requests to nodes, and nodes complete requests back to the owning shard's task.

The ordinary and managed constructors default to ASYNC_REQUIRED: LLVM-qualified C runs with native asynchronous preemption after loaded-image validation and a probe on every selected OS thread. A captured portable continuation can resume on a compatible peer M with a fresh P execution lease. Native-affine tasks retain a dedicated M, and local executor tasks retain their shared M. The ASYNC_REQUIRED policy refuses metadata-free legacy tasks, and ASYNC_AUTO runs them on a separate compatibility P. See the managed C guide.

Cooperative portable continuations can move between Ms while a runtime C API is on their stack. Internal scheduler and errno cursors use read-only lookups that opaque calls invalidate, with compiler fences preserving that property under LTO. Blocking and sleep entry safepoints resolve worker state in a fresh C activation. Shared scheduler publication still uses its own locks and atomics. Handoff scopes belong to the task owning the suspended C frame, so moving that frame to another M does not decrement a different thread's hint or affect a peer G. Runnable-queue transfers validate ownership before removing the source entry and commit the destination under the same lock. A concurrent shutdown cannot discard the entry between those steps. Later execution still needs a fresh execution or STOPPING-drain grant. Compatibility Ms with no admitted legacy tasks defer empty P claims for the existing 100 microsecond retry period. Native service, pending resource maintenance and shutdown draining remain active; late admission publishes its catalog reference before queueing the task.

Explicit *_compat constructors retain request-based boundary and safepoint preemption, so their legacy C loops still require LLAM calls or explicit polls. The separate expert Windows API continues to accept explicitly caller-certified PE intervals under its process fail-fast contract.

Boundary map

LLAM is organized around explicit runtime handles. The legacy process-default runtime is still available, but embedding hosts should use llam_runtime_create(), llam_runtime_spawn_ex(), llam_runtime_run_handle(), and llam_runtime_destroy().

Host processwrong ownerstale or forgeddestroy conflict

C application or embedding host

Public C ABI
include/llam

explicit runtime-handle lifecycle
create / spawn_ex / run_handle / destroy

process-default wrappers
init / spawn / run / shutdown

runtime-owned object APIs
channels / mutexes / condvars / cancel / groups

scheduler-safe I/O APIs
read / write / accept / connect / poll / owned buffers

runtime A

runtime B

default runtime
llam_runtime_default()

process-wide public handle tables
family tags / sealed generations / owner tags

EXDEV

EINVAL

EBUSY

Each of those runtimes, including the default one, owns its own state:

each runtime owns

scheduler shards
lease / worker lifecycle
task registry / metrics / trace

processor cells
CPU / locality / logical I/O route
allocator / local stack caches
queues / timers / online / wake

I/O nodes
submit queues / control queues
watch tables / fd identity

blocking compensation
opaque helper + blocking pool

runtime-wide stack fallback
blocking-pool allocations

watchdog + autotune
stall safety / worker scaling / handoff budget

diagnostics
stats JSON / runtime dumps / trace rings

The optional broker puts a process boundary between untrusted clients and a trusted runtime:

optional broker processboundarycontrol messagesoptional private ring

untrusted client process

Unix socket or
Windows named pipe

trusted LLAM broker
runtime + MAC keys + registries

broker-owned
data-plane ring

Runtime ownership

Every runtime-aware object is owner-tagged when it becomes public. Managed use from another runtime fails with EXDEV before any wait queue or payload is touched. Consumed or stale public handles fail with EINVAL; live public operations can hold active pins that make destroy paths fail with EBUSY instead of racing reclamation.

Explicit runtimes own scheduler shards, processor cells, I/O nodes, active allocation caches, blocking workers, and live tasks. Processor cells own the scheduler wake descriptor and pending word; I/O nodes keep their own backend wake resources. Process-wide reusable storage is allowed only after the object is owner-poisoned; acquisition restamps the current runtime before a new public handle is returned.

Public handle slot tables are process-wide family registries with sealed generations, and each object carries an owner-runtime tag. Together they reject stale handles and cross-runtime misuse, but they are not a process sandbox. A public call follows these checks:

Step What happens On failure
1 Decode the opaque handle: family, slot, and sealed generation. -1 with EINVAL: forged
2 Look up the family registry: slot object, internal epoch, and affine seal. Object storage stays untouched until this passes. -1 with EINVAL: stale, consumed, or forged
3 Pin the active public operation, or fast-claim a join or detach. -1 with EBUSY: destroy in progress or active-operation conflict
4 Check that the object's owner runtime matches the current or explicit runtime. -1 with EXDEV
5 Perform the operation: wait, wake, I/O, or release.
6 Drop the active pin and publish the wake or final state.

Some families, such as cancellation tokens, check the owner tag before they pin.

These in-process handles harden misuse and use-after-free. They are not a cryptographic sandbox; broker tokens carry the MAC, rights, subject, and revocation epoch. See Security model.

Source map

Area Path Holds
Public API include/llam/ Public headers. platform.h covers fd, HANDLE, and sockaddr portability.
Lifecycle and tasks src/core/lifecycle/, src/core/task/ Lifecycle, spawn, join, and owner routing for the default wrappers.
Scheduler src/core/sched/, src/engine/scheduler/ Run queues, timers, wake, and cooperative preemption safepoints.
Watchdog src/engine/watchdog/ Stall safety, worker scaling, shard rehome, and request-based preemption.
Public handles src/core/registry/ Family tags, sealed generations, active operations, and stale-handle rejection.
Synchronization src/core/sync/, src/core/wait/ Mutex, condition, channel, select, cancellation, and their wake contracts.
Broker src/core/broker/ Capability tokens, grants, and revocation, with transport/ for local sockets and named pipes and ring/ for private shared rings.
Diagnostics src/core/debug/ State dumps, JSON stats, and watchdog reports.
Context switch src/asm/, src/core/context/ Platform context switch and asynchronous capture.
Caches src/core/memory/ Slabs for tasks, wait nodes, timer nodes, I/O requests, and buffers.
I/O API src/io/api/, src/io/buffer/ Read, write, accept, connect, and poll; owned-buffer registry, aligned allocation, and release-after-shutdown rules.
I/O engine src/io/engine/ Runtime-owned node selection: direct path, asynchronous submit, and fallback.
Backends src/io/linux/, src/io/darwin/, src/io/windows/ io_uring, kqueue, and IOCP. See I/O nodes.
Shared watches src/io/watch/ Lookup, queues, waiters, migration, and cancel and timeout races.
↑↓ Navigate↵ Openesc CloseSearching the 3.0.1 docs