Retrieved article excerpt
Open article · Retrieved 2026-11-04T17:24:13.943667+00:00
*[Henry Zhu](https://maknee.github.io/) and [Vimarsh Sathia](https://vimarsh.me/)*
# GPU Checkpointing
GPU checkpointing lets an application save its GPU state and later pick up where it left off. This gives us more flexibility in how we run application on top of GPUs. An inference service can release them during quiet periods and resume when traffic returns [Modal: Serverless GPU scaling](https://modal.com/blog/truly-serverless-gpus)
[Doubleword: Faster SGLang cold starts](https://blog.doubleword.ai/fast-sglang-starts)
[Cedana: GPU checkpointing and migration with CRIU](https://cedana.com/blog/criu-gpu-checkpointing/) .
We wanted to see how far we could push GPU checkpointing and restore out of curiousity and to learn a couple things along the way. We began with the `cuda-checkpoint` implementation on a B300 and spend some time understanding how it works and to understand where the bottlenecks lay. Then we’ll try different ideas to make it faster and see what did and didn’t work.
*Time reduction with optimizations checkpointing and restoring GLM5.3 on vLLM (Lower is better)*
# gVisor
`cuda-checkpoint` is often paired with another program such as `CRIU`[CRIU: GPU checkpointing](https://www.criu.org/GPU_Checkpointing) or `gVisor`[gVisor: GPU checkpoint/restore](https://gvisor.dev/docs/user_guide/checkpoint_restore/#gpu-checkpointrestore)
[Modal: Memory snapshots with gVisor](https://modal.com/blog/mem-snapshots)
[Modal: GPU memory snapshots](https://modal.com/blog/gpu-mem-snapshots) to fully serialize the gpu resource and the application itself to disk. Often, one will hear about `sandboxing` or `snapshotting` with these types of applications.
*Checkpoint and restore times GLM-5.3 on vLLM in gVisor for checkpointing and restoring an entire image. We want to show how well optimized cuda-checkpoint runs against the stock implementation under various gVisor flags. **We do not claim any speedups in gVisor itself**. People may find the graphs for the various flags useful*
We observe a possible 2x speedup by running this version of cuda-checkpoint.
*Takeaways/TLDR*
- Tuning is difficult. There’s many types of hardware and system configurations.
- Hardware makes a difference for application performance where sometimes copies can be 3x faster on one platform.
- The configuration of the number of threads and buffers difficult as host copy speeds must match up to the PCIE copy speeds.
- It’s hard to predict performance without tools. Always have some benchmarks and traces to understand what is going on.
- NUMA affects performance (up to 2x the performance) due to memory being allocated on a different socket
- The two application specific bottlenecks of `cuda-checkpoint` are memory allocation and the number of buffers and threads used for copying data to and from the GPU.
- Find opporunities in parallelize operations
On this page
☰ Contents
# How to use cuda-checkpoint
Checkpointing and restoring a CUDA process each take two steps:
*Overview of checkpointing*
To checkpoint, we first **lock** the process’s CUDA activity, preventing new work and waiting for existing work to finish. We then **checkpoint** its GPU state into host memory and release its GPU resourcesAlthough releasing the GPU resources is not necessary for checkpointing, it allows other resource-hungry applications to run on the GPU
In between, another GPU application can utilized the free’d up resources.
To bring it back, we **restore** the GPU resources and copy the saved data back to GPU memory. Finally, we **unlock** the process’s CUDA activity so it can submit work again.
NVIDIA’s `cuda-checkpoint` tool exposes these four operations through a simple command-line interfaceThis cli communicates using a custom protocol to a cuda process over a pipe. It is a thin wrapper, but impacts latency as shown later:
```
ps aux | grep (your gpu application)
cuda-checkpoint --action lock --pid $PID
cuda-checkpoint --action checkpoint --pid $PID
cuda-checkpoint --action restore --pid $PID
cuda-checkpoint --action unlock --pid $PID
```
And this is how it interacts in action:
*Lock, checkpoint, restore, and unlock lifecycle*
The API is very similar:
```
pid_t pid = getpid();
CUcheckpointLockArgs lock_args{0};
cuCheckpointProcessLock(pid, &lock_args);
CUcheckpointCheckpointArgs ckpt_args{0};
cuCheckpointProcessCheckpoint(pid, &ckpt_args);
CUcheckpointRestoreArgs rest_args{0};
cuCheckpointProcessRestore(pid, &rest_args);
CUcheckpointUnlockArgs unlock_args{0};
cuCheckpointProcessUnlock(pid, &unlock_args);
CUprocessState st;
cuCheckpointProcessGetState(pid, &st);
if (st == CU_PROCESS_STATE_CHECKPOINTED) {
// ...
}
```
This tool only stores the checkpoint image to CPU memory.
## Existing work
Fergus Finn at Doubleword made a ~9 GB checkpoint-and-restore benchmark on an RTX 4090 nearly 4× faster, cutting the time from 4.5 seconds to 1.2 seconds. The improvements came from avoiding repeated CLI initialization, enabling huge pages, preallocating the host buffer, and deferring its cleanup[Reverse-engineering NVIDIA’s cuda-checkpoint for faster cold starts](https://blog.doubleword.ai/what-happens-when-you-checkpoint-a-cuda-process). We’ll explore these techniques in more detail, tracing the driver’s internals to explain why they help and which bottlenecks they address. We’ll also apply some of them ourselves and see that the optimizations with CLI, huge pages and preallocating host buffers are useful.
*Checkpoint-and-restore optimizations (Image source: [Fergus Finn / Doubleword](https://blog.doubleword.ai/what-happens-when-you-checkpoint-a-cuda-process))*
## What’s happening in cuda-checkpoint?
We’ll dig into libcudaNVIDIA’s user-space CUDA driver to see what’s happening underneath the hood during each step. We want to observe where the time goes through tracesEach perfetto trace shows a vLLM instance running on two B300s running GLM5-3 flash (~347GB in total). Each GPU instance holds around half the memory (~172GB) and we are checkpointing both gpus, each referred to as a rank.
Setup
| Setup | Component | Specification |
| --- | --- | --- |
| Host | Number of nodes | 1 |
| | GPU | 8 × NVIDIA B300 SXM6 AC |
| | PCIe | Gen6 x16; one link per GPU |
| | NUMA | GPUs 0–3 on node 0; GPUs 4–7 on node 1 |
| | CPU | 2 × Intel Xeon Platinum 8559C; 48 cores per socket |
| | Memory | 4 TB; 1 TiB container limit; no swap |
| | Driver | 580.95.05 |
| Workload | Model | GLM-5.3-flash |
| | Runtime | vLLM; tensor parallelism 2 |
| | GPUs | 0 and 1 for every run |
| Checkpoint | Per rank | 172.74 GB through the capture ring |
| | Driver image per rank | 173.85 GB including about 1.1 GB on the native driver path |
| Restore | Per rank | 173.8 GB |
**Note** Every optimization arm ran as an untraced / traced, although it didn’t make much of a difference with tracing on.
We run GLM-5.3-flash with vLLM 0.30.0 on GPUs 0 and 1 of one B300 host. Tensor parallelism is 2, so each GPU has a worker process, called a rank. We use eager execution, an 8,192-token context limit, and an 8 GiB KV cache per GPU.
```
CUDA_VISIBLE_DEVICES=0,1 python -m vllm.entrypoints.openai.api_server \
--model /path/to/GLM-5.3-flash \
--tensor-parallel-size 2 \
--enforce-eager \
--max-model-len 8192 \
--kv-cache-memory-bytes 8589934592
Generation settings go in each request:
{"temperature": 0, "seed": 1234, "max_tokens": 128}
```
We run some requests to see if vLLM is running. The benchmark controller waits until vLLM reports no running or queued requests. The controller starts `cuda-checkpoint --action lock --pid <worker-pid>` for both ranks in parallel and waits for both calls to finish. It does the same for `checkpoint`, `restore`, and `unlock`, in that order. After each cycle, it sends the same three requests and checks that their answers and token IDs match those recorded before checkpointing.
Our tracing tool uses Frida to attach function-entry and function-return hooks inside both vLLM workers. It also instruments each `cuda-checkpoint` process, so we can see the CLI’s setup and request alongside the work inside the target worker. The hooks record driver operations and CPU calls such as `mmap` and `memcpy`. We add GPU counters from NVML, sampled at a target interval of 100 ms, and CPU, memory, and page-fault counters from `/proc`.
These traces and counters get aggregated into a single perfetto trace output.
cuda-checkpoint on GLM 5.3 TP=2 on vLLM Perfetto trace · checkpoint-baseline.pftrace [Open in Perfetto ↗](https://ui.perfetto.dev/#!/?url=https%3A%2F%2Fraw.githubusercontent.com%2FMaknee%2Fmaknee.github.io%2Fmaster%2Fassets%2Fimages%2Fposts%2F2026-09-21%2Ftraces%2Fblog%2Fcheckpoint%2Fcheckpoint-baseline.pftrace) Load here 0% [↓](https://raw.githubusercontent.com/Maknee/maknee.github.io/master/assets/images/posts/2026-09-21/traces/blog/checkpoint/checkpoint-baseline.pftrace "Download the trace") ⋯ Always load traces here automatically
Loading preview…
*Perfetto dump of GLM5.3 (Rank 0) TP=2 running on vllm*
We can see how much time spent locking, checkpointing, restoring and unlocking. Clearly, checkpointing and restoring take up most of the time, so let’s zoom into checkpointing.
*Breakdown of EngineCheckpoint*
The checkpointing profile has three main phases: setup, copying, and cleanup. Copying takes up the most of the time. Even with the theorical PCIE max bandwidth of 64GB/s on the machine, that would take at least ~2.5s to checkpoint 172GB
*Breakdown of copying*
It’s interesting tha `mmap` is taking longer than copying. We’ll revisit this later once we piece everything together.
*Two staging buffers*
The copying path allocates a large host buffer with `mmap` and two pinned staging buffersEach staging buffer is 2 MB with small pushbuffers for executing the copies. This large buffer holds the final checkpoint image.
The staging buffers appears to alternate in a double-buffering scheme: while the GPU copies data into one, the CPU copies data from the other into the final checkpoint buffer:
*Double buffering copies from the GPU*
The GPU’s DMA engine transfers data from VRAM into one staging buffer while the CPU copies data from the other into the final checkpoint buffer allocated with `mmap`.
So now that we understand the individual parts, taking a step back, we can stitch a more complete pictureI haven’t explained the restore, but intuitively, it should reverse operations of checkpointing:
*A more complete picture given our understanding of the trace*
How does the engine know what to copy?
And how does the engine know what to copy? By walking memory manager’s blocks and copying its contents from GPU memory to CPU memory.
*Double buffering copies from the GPU*
Each block tracks its checkpoint state. During checkpointing, its physical GPU memory is freed while its virtual address is preserved. On restore, newly allocated GPU memory is mapped back to that addressOne possible reason for keeping the checkpoint in host memory is to leave full-process serialization to CRIU, which can save the driver’s bookkeeping alongside the rest of the process’s CPU-side state.
## Reasoning cuda-checkpoint’s design
*Breakdown of copying*
Let’s dig into why `cuda-checkpoint` is slow. We have two areas of the checkpoint taking up a good chunk of time.
`mmap` is called with `mmap(address, total, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED | MAP_POPULATE, -1, 0);`.
The fourth argument includes `MAP_POPULATE`"Populate (prefault) page tables for a mapping. For a file mapping, this causes read-ahead on the file. This will help to reduce blocking on page faults later" - [man pages](https://man7.org/linux/man-pages/man2/mmap.2.html)</span> will go ahead and tell the OS to touch every page to page fault. Allocating 173GB of memory twice takes a while.""
*Highlighting PCIE bandwidth*
On this B300 node, the theoretical maximum bandwidth of a one way PCIE transfer is 64GB/