████████╗ ██████╗ ██████╗ ██████╗ ███████╗ ██████╗██╗ ██╗███████╗██████╗
╚══██╔══╝██╔═══██╗██╔══██╗██╔═══██╗██╔════╝██╔════╝██║ ██║██╔════╝██╔══██╗
██║ ██║ ██║██████╔╝██║ ██║███████╗██║ ███████║█████╗ ██║ ██║
██║ ██║ ██║██╔═══╝ ██║ ██║╚════██║██║ ██╔══██║██╔══╝ ██║ ██║
██║ ╚██████╔╝██║ ╚██████╔╝███████║╚██████╗██║ ██║███████╗██████╔╝
╚═╝ ╚═════╝ ╚═╝ ╚═════╝ ╚══════╝ ╚═════╝╚═╝ ╚═╝╚══════╝╚═════╝
Deterministic, Topology-Aware Contract Enforcement for Linux Workloads
- Overview
- The Problem
- Use Cases
- How It Differs from Other Tools
- The Solution
- Key Features
- System Requirements
- Installation
- Quick Start
- Usage
- REST API
- Contract Schema Reference
- Configuration
- Roadmap
- License
TopoSched is a machine-local execution runtime that serves as the precise link between hardware capabilities and workload requirements. Unlike general-purpose schedulers that focus on fairness, TopoSched acts as a strict contract enforcer, ensuring that a workload's CPU, Memory, and I/O needs are met physically on the machine, or the workload is rejected.
Important
TopoSched is designed to fail early. It strictly rejects a workload rather than allowing it to run with degraded performance.
Modern servers are not simple pools of identical resources. A 128-core AMD EPYC or Intel Xeon server contains:
- Multiple NUMA nodes: Memory access latency varies 2-3x depending on which CPU accesses which memory bank
- L3 cache domains (CCDs/CCXs): Cores sharing an L3 cache communicate 10x faster than cores on different cache domains
- PCIe topology: NVMe drives and network cards have affinity to specific CPU sockets; accessing them from the "wrong" socket adds latency
- CXL memory tiers: New servers have mixed DRAM and CXL-attached memory with different performance characteristics
The Linux kernel scheduler optimizes for fairness and throughput, not for predictable performance. It makes no guarantees about:
- Which NUMA node allocates memory for a process
- Whether a latency-critical thread shares cache with a noisy neighbor
- Whether an I/O-heavy workload runs on a CPU near its NVMe device
This results in:
| Problem | Symptom | Business Impact |
|---|---|---|
| NUMA thrashing | Process on Node 0, memory on Node 1 | 30-50% throughput loss, P99 latency spikes |
| Cache pollution | Latency-critical job shares L3 with batch job | Tail latency 5-10x worse |
| I/O locality loss | CPU far from NVMe PCIe root | 20% lower IOPS, higher CPU usage |
| Silent degradation | App runs, but slower than expected | Debugging nightmare, SLA violations |
Manual pinning (numactl, taskset) requires operators to understand hardware topology and manually specify CPU masks. This approach does not scale, breaks when hardware changes, and provides no runtime enforcement.
Kubernetes Topology Manager operates at pod scheduling time but does not enforce placement after the pod starts. It also cannot express complex constraints like "avoid sharing L3 cache" or "place near this NVMe device."
Container runtimes (Docker, containerd) can set CPU affinity via cgroups, but they have no awareness of NUMA, cache topology, or I/O device locality.
TopoSched is designed for workloads where hardware placement directly impacts performance or correctness:
Financial trading applications require deterministic sub-microsecond latency. TopoSched ensures the trading engine runs on dedicated cores with local memory, isolated from kernel threads and other processes.
Database performance depends heavily on memory locality. TopoSched places database processes on NUMA-local memory and pins buffer pool allocations to specific memory nodes.
ML inference servers benefit from CPU cache locality for model weights. TopoSched ensures inference threads share L3 cache for faster data sharing.
Scientific computing workloads (CFD, molecular dynamics) require predictable memory bandwidth. TopoSched enforces strict NUMA binding and prevents memory interleaving.
Media processing pipelines require consistent latency. TopoSched isolates encoder/decoder threads from system noise.
When multiple customers share a physical server, TopoSched enforces hard boundaries between workloads at the hardware level, not just cgroups.
TopoSched is not a task queue, job scheduler, or container orchestrator. It operates at a different layer:
| Tool | What It Does | Scope |
|---|---|---|
| Celery / RQ / Sidekiq | Distributed task queues for async job execution | Application-level job dispatch |
| Kubernetes / Nomad | Container orchestration across a cluster | Cluster-wide pod placement |
| Slurm / PBS | HPC batch job scheduling | Multi-node job allocation |
| systemd | Service lifecycle management | Process supervision |
| TopoSched | Hardware-aware process placement and enforcement | Single-machine hardware contract |
vs. Celery/Task Queues: Celery distributes Python functions across workers. TopoSched does not manage application tasks; it ensures that whatever process runs on the machine (including Celery workers) gets the right CPUs, memory nodes, and I/O locality.
vs. Kubernetes: Kubernetes decides which machine runs a pod. TopoSched decides, on that machine, which exact CPUs and memory nodes the pod uses, and enforces it continuously.
vs. numactl/taskset: These are one-shot CLI tools. TopoSched provides contracts, runtime enforcement, violation detection, and an API for orchestrator integration.
vs. cgroups alone: Cgroups limit resources but do not understand topology. Assigning a container to CPUs 0-7 means nothing if CPUs 0-3 are on NUMA node 0 and CPUs 4-7 are on NUMA node 1.
TopoSched solves this by:
- Modeling the Machine: Creating an immutable, high-fidelity snapshot of CPUs, caches, NUMA, and devices at startup.
- Defining Intent: Workloads declare requirements via a strict JSON/YAML contract (e.g., "4 cores, exclusive, same L3 cache, local NUMA memory").
- Deterministic Placement: An integer-based scoring algorithm finds the optimal placement. Identical hardware + identical contract = identical placement, every time.
- Kernel Enforcement: TopoSched applies
sched_setaffinity,set_mempolicy, cgroup v2, and namespace isolation to enforce the contract. - Continuous Monitoring: A runtime watchdog detects and responds to violations (e.g., a process escaping its CPU affinity).
- Contract-Based Execution: Workloads declare requirements explicitly via JSON or YAML contracts.
- Real Process Execution: Directly launches workloads via
fork/execwith enforced resource bounds. - Multi-Tenant Isolation: Optional Linux namespace isolation (PID, IPC, NET, etc.) for secure multi-tenancy.
- Topology Discovery: Automatic detection of NUMA nodes, CCDs, Cache Groups, and CXL memory devices.
- Deterministic Placement: Identical hardware + identical contract = identical placement, every time.
- Continuous Monitoring: Runtime watchdog detects and alerts on CPU/memory affinity violations.
- Advanced Features: Priority-based admission control, CXL memory tier awareness, and perf/eBPF monitoring hooks.
- Attach Mode: Analyze existing, running processes (e.g., systemd services) for placement diagnostics.
- Daemon Mode: REST API server for integration with orchestrators (Kubernetes, Kueue, Slurm).
- Systemd Ready: Drop-in service unit provided for production deployments.
| Feature | Minimum Kernel | Recommended | Notes |
|---|---|---|---|
| Core Functionality | 5.10+ | 6.1+ | Basic cgroup v2, CPU affinity, memory policy |
| cgroup v2 | 5.8+ | 6.1+ | Must be mounted at /sys/fs/cgroup |
| CXL Memory | 6.0+ | 6.5+ | CXL 2.0 device discovery via sysfs |
| eBPF Tracing | 5.15+ | 6.1+ | BTF support for scheduler tracing |
| perf_event_open | 4.0+ | 5.10+ | Hardware performance counter access |
- Architecture: x86_64 (AMD64) with NUMA support
- Memory: Minimum 256 MB RAM (TopoSched overhead < 200 MB under load)
- Storage: Read access to
/sys/devices/system/,/proc/,/sys/fs/cgroup/
TopoSched requires the following Linux capabilities for full functionality:
| Capability | Purpose |
|---|---|
CAP_SYS_NICE |
CPU affinity manipulation via sched_setaffinity |
CAP_SYS_RESOURCE |
cgroup configuration and memory policy enforcement |
CAP_PERFMON |
(Optional) Hardware performance counter sampling |
Note
The daemon can run as a non-root user with specific capabilities granted. The provided systemd unit file configures these capabilities automatically.
- Runtime: glibc 2.31+, cgroup v2 filesystem
- Build: Rust 1.75+ (2021 edition)
# Clone the repository
git clone https://github.com/ankitkpandey1/topoSched.git
cd topoSched
# Build release binary
cargo build --release
# Install
sudo cp target/release/toposched /usr/local/bin/
sudo mkdir -p /var/log/toposchedsudo cp contrib/toposched.service /etc/systemd/system/
sudo systemctl daemon-reload
sudo systemctl enable --now toposched# Check version
toposched version
# Dump discovered topology
toposched topologyThis example demonstrates running a high-performance Redis instance with:
- 2 dedicated cores
- Exclusive L3 cache access
- 4GB of strictly local memory
version: 1
cpu:
cores: 2
sharing: exclusive # No other process on these cores
smt_policy: avoid # Avoid HyperThreads
cache_affinity: strict # Must not share L3 cache
memory:
bytes: 4GB # Human-readable size notation
locality: strict # Memory MUST be on the same NUMA node
allocation: pre_fault # Allocate all memory upfront
hugepages: optional
concurrency:
model: multi_threaded
expected_threads: 2
expected_processes: 1
oversubscription: forbid
io:
disk_class: any
device_path: ""
device_provenance: auto
nvme_of_behavior: local
io_isolation: best_effort
namespaces: # Optional isolation
pid: isolate
ipc: isolate
policy:
on_violation: kill
fail_on_start_violation: true
queue_ttl_seconds: 60# Launch redis-server inside the customized environment
# Note: '--' separates TopoSched arguments from the command
toposched run --contract redis.yaml -- /usr/bin/redis-server# Check the placement decision for a specific job
toposched explain <job-id>Executes a workload with strict physical resource enforcement:
toposched run --contract <file> -- <command> [args...]
# Examples:
toposched run --contract postgres.yaml -- /usr/bin/postgres -D /data
toposched run -c myapp.json -- ./my-latency-critical-app --port 8080Analyzes a running process against the machine topology. Useful for debugging performance issues:
# Find PID of a slow process
pid=$(pgrep mysqld)
# Attach and analyze
toposched attach --pid $pidOutput includes:
- Current CPU Affinity Mask
- Primary NUMA Node residency
- Memory distribution (pages per node)
- Thread count
Starts the HTTP API server for programmatic integration:
toposched daemon --bind 0.0.0.0:9090Outputs the discovered system topology as JSON:
toposched topologyThe daemon mode exposes a JSON-based REST API over HTTP.
Base URL: http://127.0.0.1:9090/
| Action | Request Body | Description |
|---|---|---|
allocate |
{"action": "allocate", "job_id": "...", "contract": {...}} |
Reserve resources for a job |
release |
{"action": "release", "job_id": "..."} |
Release a reservation |
get_topology |
{"action": "get_topology"} |
Retrieve the machine topology snapshot |
get_queue_state |
{"action": "get_queue_state"} |
Get admission queue status |
get_reservation |
{"action": "get_reservation", "job_id": "..."} |
Query a specific reservation |
curl -X POST http://127.0.0.1:9090/ \
-H "Content-Type: application/json" \
-d '{
"action": "allocate",
"job_id": "redis-001",
"contract": {
"version": 1,
"cpu": {"cores": 2, "sharing": "exclusive", "smt_policy": "avoid", "cache_affinity": "ignore"},
"memory": {"bytes": 1073741824, "locality": "any", "allocation": "first_touch", "hugepages": "optional"},
"concurrency": {"model": "single_process", "expected_threads": 1, "expected_processes": 1, "oversubscription": "allow"},
"io": {"disk_class": "any", "device_path": "", "device_provenance": "auto", "nvme_of_behavior": "local", "io_isolation": "best_effort"},
"policy": {"on_violation": "report_only", "fail_on_start_violation": false, "queue_ttl_seconds": 3600}
}
}'Success:
{
"status": "success",
"data": {
"id": "res-abcd1234",
"cpus": [0, 1],
"numa_nodes": [0]
}
}Error:
{
"status": "error",
"message": "No feasible allocation found that satisfies the contract"
}The contract is the heart of TopoSched. It supports JSON and YAML formats.
| Field | Type | Values | Description |
|---|---|---|---|
cores |
int |
1+ | Number of physical cores required |
sharing |
enum |
exclusive, prefer_exclusive, shared |
Core sharing policy |
smt_policy |
enum |
avoid, allow, require |
SMT/HyperThreading policy |
cache_affinity |
enum |
strict, prefer, ignore |
L3 cache isolation policy |
bandwidth |
object |
{"max": "80000 100000"} |
(Optional) CPU cgroup bandwidth limit |
| Field | Type | Values | Description |
|---|---|---|---|
bytes |
u64/string |
1073741824, "4GB", "512MB" |
Memory size (supports human-readable notation) |
locality |
enum |
strict, prefer_local, any |
NUMA locality requirement |
allocation |
enum |
reserve_only, first_touch, pre_fault |
Memory allocation strategy |
hugepages |
enum |
forbid, optional, require |
Huge pages policy |
tier |
enum |
dram, cxl, any |
(Optional) Memory tier preference |
| Field | Type | Values | Description |
|---|---|---|---|
model |
enum |
single_process, multi_threaded, multi_process |
Concurrency model |
expected_threads |
int |
1+ | Expected thread count |
expected_processes |
int |
1+ | Expected process count |
oversubscription |
enum |
forbid, allow |
Whether oversubscription is allowed |
| Field | Type | Values | Description |
|---|---|---|---|
disk_class |
enum |
local_nvme, network, any |
Storage class requirement |
device_path |
string |
/dev/nvme0n1 |
Explicit device path (optional) |
device_provenance |
enum |
auto, operator_asserted, conservative |
Device provenance trust level |
nvme_of_behavior |
enum |
local, remote, require_explicit |
NVMe-oF classification |
io_isolation |
enum |
best_effort, strict |
IO isolation level |
| Field | Type | Values | Description |
|---|---|---|---|
pid |
enum |
host, isolate |
PID namespace isolation |
ipc |
enum |
host, isolate |
IPC namespace isolation |
net |
enum |
host, isolate |
Network namespace isolation |
user |
enum |
host, isolate |
User namespace isolation |
uts |
enum |
host, isolate |
UTS namespace isolation |
cgroup |
enum |
host, isolate |
Cgroup namespace isolation |
| Field | Type | Values | Description |
|---|---|---|---|
on_violation |
enum |
kill, pause, report_only |
Action on runtime violation |
fail_on_start_violation |
bool |
true, false |
Fail if constraints cannot be met at start |
queue_ttl_seconds |
int |
0+ | Time-to-live in admission queue (0 = no queueing) |
TopoSched is configurable via CLI flags, environment variables, and internal defaults.
| Flag | Description | Example |
|---|---|---|
--contract, -c |
Path to contract file (JSON or YAML) | --contract redis.yaml |
-- |
Separator between TopoSched args and command | -- /usr/bin/redis-server |
| Flag | Description | Default |
|---|---|---|
--bind, -b |
API server bind address | 127.0.0.1:9090 |
| Flag | Description | Example |
|---|---|---|
--pid, -p |
Process ID to analyze | --pid 1234 |
| Path | Purpose | Configurable |
|---|---|---|
/sys/fs/cgroup/toposched/ |
Cgroup hierarchy for managed processes | Hardcoded |
/var/log/toposched/decisions.log |
Decision audit log | Hardcoded |
/sys/devices/system/cpu/ |
CPU topology discovery | Kernel sysfs |
/sys/devices/system/node/ |
NUMA topology discovery | Kernel sysfs |
/sys/bus/cxl/devices/ |
CXL memory device discovery | Kernel sysfs |
When running in daemon mode, the API server uses these settings:
| Parameter | Default | Description |
|---|---|---|
| Bind Address | 127.0.0.1:9090 |
Set via --bind flag |
| Max Connections | 100 |
Maximum concurrent connections |
The runtime violation watchdog uses these parameters (currently internal defaults):
| Parameter | Default | Description |
|---|---|---|
| CPU Check Interval | 1 second |
How often to verify CPU affinity |
| Memory Check Interval | 5 seconds |
How often to verify memory locality |
| Violation Threshold | 3 |
Consecutive violations before action |
| Kill on Violation | true |
Whether to terminate violating processes |
The placement engine uses weighted scoring with these coefficients:
| Coefficient | Default | Purpose |
|---|---|---|
| Alpha (α) | 100 |
Remote memory access penalty |
| Beta (β) | 20 |
Cache conflict penalty |
| Gamma (γ) | 50 |
SMT sibling contention penalty |
| Delta (δ) | 10 |
Fragmentation penalty |
| Epsilon (ε) | 5 |
Future blocking penalty |
| Zeta (ζ) | 200 |
Unknown device provenance penalty |
Scoring formula:
score = α×remote_memory + β×cache_conflict + γ×smt_conflict
+ δ×fragmentation + ε×future_blocking + ζ×provenance
Lower scores indicate better placements. Identical scores are resolved by deterministic tie-breaking (lowest NUMA node ID, then lowest core ID, then job ID).
Copyright 2026 Ankit Kumar Pandey.
Licensed under the Apache License, Version 2.0. See LICENSE for details.