Phase 05/Moving bytes between GPUs and nodes/Linux, containers and GPU plumbing
PHASE 05 · Moving bytes between GPUs and nodes

Linux, containers and GPU plumbing

0%
8 h6 subtopics3 lessons · 2 required
In plain English

Every inference server is a Linux process inside a container on a machine with a GPU, and when it misbehaves the cause is often in that plumbing rather than in the model. Think of the GPU as an expensive machine tool on a factory floor: the model is the job, but whether the job runs well also depends on the power supply (the driver), the room it is bolted into (the container), who else is allowed on the floor (cgroups and namespaces), and how fast parts arrive from the warehouse (the filesystem and network). This topic teaches the handful of operating-system ideas an inference engineer actually uses: what a process and a thread are to the scheduler, how virtual memory and the page cache decide whether a 15 GB model loads in five seconds or fifty, what a container really is (a few kernel features, not a virtual machine), how a CUDA program inside a container reaches the GPU, and why a cold start takes as long as it does.

Why it matters

Eight of the forty-six postings ask for Linux internals outright and several more describe debugging work (hung NCCL, mysterious latency, "CUDA driver version is insufficient") that is impossible without them. Container cold start and model load time are also the dominant cost in autoscaling: you cannot reason about scale-to-zero or fast replicas without knowing where the seconds go.

Hiring signal

Modal's inference runtime posting asks for "strong Linux systems knowledge, particularly processes, virtual memory, filesystems, system calls, scheduling, namespaces, cgroups, and signals" and wants container startup, checkpoint and restore made dramatically faster; Anthropic's performance engineer role expects you to debug kernel-level network latency spikes in a containerized environment.

Skills this topic builds, with the number of the 46 analysed job postings that ask for each. Companies asking: Anthropic, Baseten, Cerebras, Cohere, CoreWeave, Crusoe, Databricks, ElevenLabs, Fireworks, Modal, nvidia, OpenAI, Perplexity, Poolside, Thinking Machines, Together AI, xAI.See all skills →

Learning objectives

  • Explain processes, threads, the CFS scheduler and signals well enough to read a stuck inference server's state with standard tools.
  • Predict model-load time from page-cache state, storage bandwidth and pinned-memory behaviour, and measure it.
  • Build a minimal container by hand with namespaces and cgroups and run a model server inside it.
  • Trace how a CUDA call inside a container reaches the GPU driver, and diagnose driver/runtime version mismatches.
  • Decompose a container cold start into image pull, unpack, process start, library load and model load, with numbers.

Key concepts

Process and thread
A process owns an address space; threads share it. GPU runtimes spawn helper threads, and Python's GIL makes the distinction matter for serving loops.
Virtual memory and page cache
Files read from disk stay cached in RAM; a "warm" model load is a memory copy, a "cold" one is bound by storage bandwidth.
Pinned (page-locked) memory
Host memory the kernel promises not to page out, required for asynchronous, DMA-driven host-to-GPU copies.
Namespaces
Kernel feature that gives a process its own view of PIDs, mounts, network and hostname; the isolation half of a container.
cgroups
Kernel feature that limits and accounts CPU, memory and devices for a group of processes; the resource half of a container.
Device node and driver
/dev/nvidia* files are the user-space door to the kernel driver; the CUDA runtime in your container must be compatible with the host driver.
NVIDIA Container Toolkit
The hook that mounts the host driver libraries and device nodes into a container so CUDA works without installing a driver inside the image.
Cold start
The time from "start replica" to "first token served", dominated by image pull, shared-library loading and model weight loading.
Checkpoint/restore (CRIU)
Snapshotting a running process's memory so a later start can skip initialisation; what Modal-style platforms use to cut cold starts.

Subtopics

  1. 1. Processes, threads, scheduling and signals

    /proc, ps, top, strace and py-spy as the tools; CFS basics; why SIGTERM handling and thread state matter for graceful shutdown of a serving process.

  2. 2. Virtual memory, the page cache and model loading

    mmap versus read, page-cache warmth, safetensors memory-mapping, pinned memory for host-to-device copies, hugepages.

  3. 3. What a container is

    Namespaces plus cgroups plus an overlay filesystem; how Docker and containerd compose them; what gVisor and Firecracker add.

  4. 4. The GPU path through a container

    Kernel driver, device nodes, the NVIDIA Container Toolkit and CDI, driver versus CUDA runtime compatibility, nvidia-smi inside versus outside.

  5. 5. The network path and where kernel bypass fits

    Socket to NIC through the kernel stack; interrupts and softirqs as a latency source; why RDMA, GPUDirect and DPDK skip the kernel.

  6. 6. Cold start anatomy and snapshotting

    Image layers and lazy pulling, shared-library loading, CUDA context creation, weight loading; CRIU and GPU-aware snapshot/restore.

Resources

documentation
video

Hands-on lessons

L1

Measure where model-load time goes

CPU · your Macscript90 minrequired

Goal · Produce a table of cold versus warm load times for a 1-3 GB model and explain each number with page-cache and bandwidth measurements.

  1. 1In a Linux VM or Docker container on your Mac (or a free Colab CPU runtime), download a safetensors model of 1-3 GB (for example Qwen2.5-0.5B or TinyLlama).
  2. 2Measure storage read bandwidth with dd or fio on the same disk; record MB/s.
  3. 3Drop the page cache (echo 3 > /proc/sys/vm/drop_caches as root, or restart the container) and time a cold load with transformers; then time a second, warm load.
  4. 4Use vmtouch or fincore to show how much of the file is cached before and after each load.
  5. 5Repeat the cold load with safetensors memory-mapping versus a plain torch.load of the same weights converted to .bin; compare.
  6. 6Record peak RSS with /usr/bin/time -v for each variant and explain the difference between mmap and read.
  7. 7Write the table and a paragraph predicting the cold load time for a 15 GB model on the same disk.
Deliverable
A markdown table of cold/warm load times, bandwidth, cached bytes and RSS for each variant plus the 15 GB prediction.
Check
Cold load time is within 30 percent of file_size / measured_disk_bandwidth; warm load is at least 3x faster than cold; fincore shows the file fully cached after the first load.
L2

Build a container by hand and run a model server in it

CPU · your Macscript120 minrequired

Goal · Run a small OpenAI-compatible model server inside a "container" you assembled from namespaces, cgroups and a chroot, with a memory limit that you can see enforced.

  1. 1In a Linux VM (Lima, Multipass or a privileged Docker container works), create a root filesystem directory from a minimal image (debootstrap or docker export of python:3.11-slim).
  2. 2Use unshare --pid --mount --uts --net --fork with chroot to start a shell inside it; set a hostname and mount /proc; confirm ps shows only your processes.
  3. 3Create a cgroup v2 under /sys/fs/cgroup with memory.max set to 1.5 GB and move your shell's PID into it.
  4. 4Inside, start a tiny model server (for example llama-cpp-python or a transformers FastAPI app with a 0.5B model) and curl it from the host namespace via a veth pair or by sharing the network namespace.
  5. 5Lower memory.max below the model's RSS and observe the OOM kill in dmesg and memory.events; raise it and restart.
  6. 6Send SIGTERM and observe whether the server shuts down gracefully; add a handler if it does not.
  7. 7Compare each manual step with the equivalent docker run flags in a short table.
Deliverable
A shell script that reproduces the container, the OOM evidence from memory.events, and the manual-step-to-docker-flag table.
Check
ps inside the namespace shows PID 1 as your shell; memory.events shows oom_kill 1 after the limit is lowered; the server answers a chat completion from outside.
L3

Trace the GPU path and anatomise a cold start

Colab T4 · freeexperiment90 minoptional

Goal · Explain, with timestamps, how a CUDA program reaches the T4 from inside the Colab container and where a vLLM-style cold start spends its time.

  1. 1In Colab, list /dev/nvidia* and the mounted driver libraries (ldconfig -p | grep nvidia); compare nvidia-smi's driver version with torch.version.cuda and explain the compatibility rule.
  2. 2Run strace -f -e trace=openat,ioctl -o trace.txt python -c "import torch; torch.zeros(1).cuda()" and count opens of libcuda and ioctl calls on /dev/nvidia*; identify the CUDA context creation.
  3. 3Time import torch, first CUDA call, model weight load and first generation separately for a 0.5-1B model with time.perf_counter.
  4. 4Use py-spy dump or record on the loading process to attribute time between shared-library loading, Python imports and weight copying.
  5. 5Read the CRIU GPU-support notes and the Modal cold-start quotes in research/jobs and write a half page on which of your measured stages a snapshot/restore would remove.
Deliverable
A stage-by-stage cold-start timeline with a short explanation of the driver path and a snapshot/restore analysis.
Check
You can name the four stages with times that sum to within 10 percent of the end-to-end measurement, and the ioctl count on /dev/nvidia* is nonzero and explained.
Fallback
Without a GPU, run the strace and timing on CPU-only torch and note which steps (CUDA context, driver ioctls) are absent.

Build your own

Build your own container runtime

PythonCPU · your Mac~8 h

A few hundred lines of Python that create namespaces, an overlayfs rootfs from an OCI image, cgroups v2 limits and a veth network, then run a model server inside it and explain where its cold start goes.

The real thing: github.com/opencontainers/runc ↗

How you know a stage passes

Namespaces and cgroups need Linux, so run everything inside an Ubuntu VM on the Mac (Lima or multipass; Colab does not grant CAP_SYS_ADMIN). Each stage has a `tests/sN.sh` that runs `sudo mini run ...`, inspects /proc, /sys/fs/cgroup and the network, and exits non-zero on any failed check; `make test` runs them all in order. Stage 5 adds an HTTP check against the server inside the container.

Stages, in order. Each one leaves you with something that runs.0/7
  1. 01namespaces and chroot
    `mini run <rootfs> <cmd>` forks, calls unshare for PID, mount, UTS and IPC, mounts a fresh /proc, sets the hostname, chroots into an extracted Alpine rootfs and execs the command.
    test · Inside, `ps` shows your command as PID 1, `hostname` prints the container name and `ls /` is the Alpine tree; outside, the same process is visible under a different PID in `ps aux`.
  2. 02an OCI image as an overlayfs rootfs
    `mini pull` fetches image layers with skopeo, and each container gets an overlayfs mount with the layers as lowerdirs and a private upperdir.
    test · Two containers from the same image share the lower layers (`du -sh` of the images directory does not grow when the second starts); a file written in one is absent in the other; removing the upperdir removes all container state.
  3. 03cgroups v2 memory and CPU limits
    Each container gets /sys/fs/cgroup/mini/<id> with memory.max and cpu.max set from flags, and the child PID is written to cgroup.procs before exec.
    test · A Python loop allocating 600 MB under --memory 512m is killed and memory.events shows oom_kill 1; a busy loop under --cpus 0.5 shows 50 percent (plus or minus 5) in `top` on the host.
  4. 04a network namespace with a bridge
    A veth pair joins the container to a host bridge with an address from a small pool, NAT via nftables gives it Internet access, and --publish forwards a host port.
    test · `curl http://localhost:8000/healthz` from the host reaches the container; `pip download` inside the container succeeds; `ip netns` lists the container namespace.
  5. 05a model server inside
    Run your Phase 3 GPT-2 FastAPI server from a bind-mounted source directory with the Hugging Face cache mounted read-only, under a 2 GB memory limit.
    test · A completion request through the published port returns tokens; `strace -e openat` shows the weights opened under the read-only mount; memory.peak is recorded in the README and is below the limit.
  6. 06the GPU path, as a plan
    A --gpu flag performs what nvidia-container-toolkit does (bind-mount libcuda and libnvidia-ml, create /dev/nvidia* nodes, allow them in the cgroup device controller) when the files exist, and otherwise prints the exact mount and device plan.
    test · On the GPU-less VM `mini run --gpu --dry-run` exits 0 and the printed plan contains /dev/nvidiactl, /dev/nvidia-uvm, /dev/nvidia0 and libcuda.so.1; a unit test checks the list against the toolkit's documented set.
  7. 07cold start anatomy
    A --timeline flag timestamps namespace setup, rootfs mount, interpreter start, weight load and first token, and prints the breakdown for a cold and a warm run.
    test · The five phases sum to within 5 percent of the end-to-end time; the warm run's weight-load phase is at least 2x faster and the README attributes the difference to the page cache using `free` or vmtouch output.

Knowledge check

QWhy is the second load of a model file much faster than the first on the same machine?

The first load pulled the file from disk into the page cache; the second reads from RAM, so it is bounded by memory bandwidth rather than storage.

QWhat two kernel features together make up a container, and which one enforces a memory limit?

Namespaces (isolation of PIDs, mounts, network) and cgroups (resource limits and accounting); cgroups enforce memory.max.

QYou see "CUDA driver version is insufficient for CUDA runtime version" inside a container. Where is the fix?

On the host; the container's CUDA runtime is newer than the host kernel driver, and the driver cannot be upgraded from inside the container.

QWhy does pinned host memory speed up host-to-device copies?

The kernel guarantees the pages stay resident, so the GPU's DMA engine can copy directly and asynchronously without a staging copy.

QName three stages of a model-server cold start that a process snapshot/restore could skip.

Python and shared-library import, CUDA context creation, and model weight loading into host memory (and, with GPU-aware restore, into device memory).

Completion

  • All 6 subtopics marked done
  • All 2 required lessons done
  • All six subtopics marked completed.
  • Lessons l1 and l2 deliverables saved with checks passing.
  • Can explain a container to a colleague using only the words namespace, cgroup and overlay filesystem.
Topic progress is derived; it reaches 100% when both checks above pass.Next recommended topic →