Repository navigation
Description
Reduce pod startup latency and foreground page-loading delays
We are working on reducing the time from an incoming request to a usable application, including page-loading delays after background restore. There are two workstreams. I'm not sure if there is any work
1. Move more initialization into pod prewarming
Pod prewarming is already implemented in our orchestration layer. We want to move as much initialization as possible out of the request path.
In particular, we want to prepare a sandbox using --no-root-container before checkpoint files are available, and provide those files later when restoring the application container. This would allow sandbox preparation and checkpoint fetching to happen in parallel.
Related work and discussion: PR #15551.
2. Prioritize demand-driven page loading during background restore
Applications should be able to load pages they currently need without unnecessary delays from speculative background reads. We propose addressing this in two separate changes.
2a. Fix scheduling stalls when reader capacity is available
AsyncPagesFileLoad.main() currently calls:
apfl.ar.Wait(completions[:0], 1 /* minCompletions */)whenever reads are in flight, even if the reader still has spare capacity. New demand-driven requests cannot interrupt this wait.
We reproduced this on master with the following sequence:
- Use a reader with capacity for two concurrent reads.
- Start a main MemoryFile read and deliberately block it.
- Register another MemoryFile and access one of its unloaded pages.
The access enters the priority queue but cannot complete until the unrelated main MemoryFile read is released, despite one reader slot remaining available.
Expected behavior: newly requested pages should be eligible for submission whenever reader capacity is available, without waiting for an unrelated read to complete.
2b. Reserve reader capacity for demand-driven reads
After fixing the scheduling issue, limit the number of slots occupied by speculative background reads so they cannot consume all reader capacity.
Background read sizes or total in-flight bytes may also need bounds to reduce interference with demand-driven reads. Background loading should continue making progress while giving application accesses priority.
These changes should be evaluated separately: the first fixes a scheduling issue; the second introduces a policy for sharing I/O capacity between application demand and background loading.
Looking further ahead, could we use profiles collected from production workloads to automatically identify which memory pages the application is likely to need first, and prioritize loading those pages during restore? This could help load the initial working set before the application faults on it, reducing stalls while the remaining pages load in the background.
Is anyone already working on these areas? If so, could you share the current progress and any related issues, PRs, or design discussions? I'd like to understand what's already underway and where I can help.
Is this feature related to a specific bug?
No response
Do you have a specific solution in mind?
No response
Activity
EtiennePerot commentedon Oct 15, 2026
Regarding (1), is there anything else that needs to be implemented beyond what's already in-flight as PRs?
Regarding (2), no one is looking at this right now but I agree we need better heuristics than the current way to prioritize background page loading. It's not clear to me that we should do aggressive background loading at all if not needed by the application. The current background-loading pattern was optimized around restoring inference servers with large GPU memory footprints, which need to be restored serially into GPU VRAM, hence the linear left-to-right scan. It's not the best pattern for most applications.
IMO should definitely have a knob here that at least supports the "aggressive linear scan" strategy (today's behavior) and the "do nothing unless a fault happens" strategy (the other extreme end of the spectrum, i.e. full lazy-loading). There are probably legitimate strategies that exist in the middle of that spectrum worth experimenting with, but creating that spectrum seems like the right first step to begin with.
jingyugao commentedon Oct 15, 2026
@EtiennePerot Thanks, that makes sense. Here is how our prewarming works and why passing the checkpoint later helps.
(1) Prewarming and deferred checkpoint binding
We keep a pool of unassigned Pods. A resume request claims a compatible Pod and supplies its checkpoint; the application does not run while waiting in the pool.
Today, our adapter prepares the sandbox with
runsc create, then holds sandboxstartuntil the checkpoint is available and replaces it withrunsc restore.The pause container is the sandbox's root container. Its start is part of
RunPodSandbox, which kubelet waits for before creating application containers. Our wait therefore leaves application-container preparation on the request path.With no-root and deferred checkpoint binding, we can finish the empty sandbox stage without a checkpoint, let kubelet create the application container, and wait at application start instead:
flowchart TD subgraph Current A[Prewarm sandbox] --> B[Wait at sandbox start] B -->|Request + checkpoint| C[Return from RunPodSandbox] C --> D[Create application container] D --> E[Start / restore application] end subgraph Deferred F[Prepare no-root sandbox without checkpoint] --> G[Return from RunPodSandbox] G --> H[Create application container] H --> I[Wait at application start] I -->|Request + checkpoint| J[Restore application] endWe implemented this on top of #15551 in this branch. Our Pods currently have one application container; with several, blocking the first start would prevent kubelet from reaching later containers and needs further handling.
We compared three configurations on a real k3s node with systrap, with 30 samples each in balanced, shuffled order:
Deferred binding saved another 64.6 ms over no-root alone and was faster in 29/30 paired rounds. No-root alone showed an 18.6 ms median reduction, but that comparison was too noisy to claim a stable gain. The overall reduction was about 83 ms this run and 62 ms in an earlier run.
These are preliminary results with the same runsc binary and image, cached checkpoints, background restore, and an 8 MiB probe limited to 0.5 CPU / 128 MiB. Both no-root configurations used the same checkpoint. Timing ends after restored-memory validation and a response-file write; it excludes checkpoint download and the application API/controller path, and is not an HTTP benchmark.
(2) Start with fully lazy page loading
I agree with first adding an option to disable speculative background reads and load pages only on access. The application could warm itself with representative requests or by touching its working set before accepting traffic.
Over time, we could collect access profiles and bring useful strategies into gVisor, including bounded read-ahead and automatically choosing which pages to load first from production profiles. The foreground scheduling stall can be fixed independently.
jingyugao commentedon Oct 16, 2026
Following up on (2): our k8s experiments support starting with an explicit demand-only page-loading mode. We would like to pursue this instead of rate-limiting internal speculative reads as proposed in #15721. Pages would still load on demand; optional prefetch would be controlled independently by orchestration.
We tested master
0e89e080against a local demand-only variant, using a real Codex app-server workload on k8s/systrap. The Pod also contained an idle process holding 500 MiB of fully written anonymous memory;pages.imgwas 561.4 MiB. There were no Pod CPU or memory requests/limits.Each configuration had 10 trials in randomized paired rounds, using the same image and immutable checkpoint. All checkpoint files started nonresident in host page cache, verified with
mincore. Application/rootfs caches remained warm; VM backing-storage caches were not controlled. Every configuration used the sameinitialize → thread/resume → turn/startclient flow.The metric is restore trigger to the first real model-provider request reaching a forwarding proxy. It includes our current pause-container/CRI restore path and the application RPCs; it excludes Pod scheduling, image pull and downstream inference. External prefetch starts concurrently with restore, without application changes or prewarming before the timer starts.
Hotset prefetch beat master and demand-only in all 10 paired rounds, with median paired savings of 199.8 ms and 35.0 ms, respectively. All 40 real model turns completed with validated replies and completion notifications; restored process identities and the full 500 MiB contents were also checked.
For the hotset, we recorded checkpoint ranges resident at first dispatch in three separate cold, demand-only training restores, then froze their union before evaluation. The resulting 56.9 MiB footprint includes restore/runtime accesses and readahead, rather than being a precise per-process memory profile. It is specific to this checkpoint. A separate host process warms those ranges into page cache; gVisor still loads requested pages into its MemoryFiles on demand. Both external-prefetch configurations used one worker paced at 512 MiB/s of logical page touches, not a hard device-bandwidth limit. Hotset prefetch finished about 115 ms after the restore trigger.
The existing priority queue does not fully isolate foreground loading from background work:
AsyncReader.Wait(..., 1)with an outstanding read and spare capacity. New demand for an unstarted page cannot interrupt that completion wait, so submission waits for a completion despite the free slot. Reserving slots alone does not fix this wakeup gap.With internal speculative loading disabled, external prefetch does not occupy gVisor's reader slots or run through its page-loader scheduling/completion loop. It can select the early working set and overlap I/O with restoration, leaving gVisor to service demand from a warmer host page cache.
This does not eliminate shared storage contention: whole-checkpoint external prefetch was slower than demand-only in every paired round. The useful combination here is demand-only loading plus selective, overlapping prefetch. These application-level measurements also do not quantify how much of master's delay comes from the specific
Waitgap versus unnecessary I/O and other resource contention.This supports exposing demand-only loading as the first policy option, while fixing the foreground scheduler wakeup issue independently. External prefetch provides a way to experiment with working-set selection and pacing without putting speculative reads back into the foreground loader's queue.
Assisted-by: OpenAI Codex
ayushr2 commentedon Oct 17, 2026
cc @nixprime could really use your help here! This looks like really interesting work. Specially the "2. Prioritize demand-driven page loading during background restore" part. I think you'll be best to comment here since you authored a lot of async page loading in gVisor.
jingyugao commentedon Nov 3, 2026
Status update
Resume latency for Cellbox now meets our goal, so we are pausing latency work. This comment summarizes what we measured and what remains open upstream. We run a public build: upstream
ac7b4e0fdcplus #15721, #15722, #16368 and #16744.Result
The test Box has 1 GB of memory in its cgroup, of which 900 MiB is a Go heap that nothing reads after resume. It ran on one k3s node (8 vCPUs, Hyper-V virtual disk) with systrap. These are best-case figures: resumes ran one at a time with no CPU or memory limits, the runtime processes ran at raised priority, and the node was otherwise idle. The client ran on the node.
Time from the resume request to the first HTTP response, in ms:
--defer-checkpoint,--background-load=lazy--defer-checkpoint, eager background loadWithout a warm slot, most of the time goes to Kubernetes creating the Pod, and that part varies widely. Without #16368 we cannot keep a sandbox ready for an unknown checkpoint, so the last two rows approximate what we would have without these PRs.
These figures depend on a small working set. A first request that touches a lot of memory takes longer, and so does a slower disk.
(1) Prewarming and deferred checkpoint binding
With #15551 merged, #16368 lets a no-root sandbox finish preparation before the checkpoint is known. Orchestration precreates the application container and waits at its start, so one warm slot can serve any compatible checkpoint. It accounts for most of the gain in the table above.
(2) Demand-driven page loading
Instead of limiting background reads (2b), we went with the explicit
--background-load=eager|lazysuggested in review (#15721). It saves about 20 ms per resume in the table above. With bandwidth limited to 50 MB/s and a dropped page cache, restore to the firstlsin headless Chromium went from 6.60 s with one background read to 2.28 s with lazy.Two costs remain:
We have not sent a separate fix for the wait gap in (2a). Lazy mode removes the speculative reads that exposed it for us, but we have not verified that the gap itself is gone.
Where the remaining time goes
With a warm slot, the resume operation takes about 55 ms (median of 40 rounds, 48-62 ms p10-p90). Kernel load is a stable 16 ms. Most of the spread comes from two steps on the host before the restore RPC:
cgroupSystemd.CloneIntoCgroupalways fails, soRunInCgroupfalls back toJoin, which opens a D-Bus connection and asks systemd to attach the process to the scope. The log saysCLONE_INTO_CGROUP cannot be used with systemd cgroup ... This slows down gVisor startup and checkpoint/restore.The scope is the sandbox's own, so it already exists at this point.Our own fsync of a durable marker cost 3-8 ms. Removing it in a test lowered the median by about 5 ms but did not narrow the spread.
Two earlier findings, from an instrumented build, are still experiments:
signal.NotifyinLoader.runtook 10-19 ms because Go starts its signal-mask thread. Starting that thread before waiting for the start signal removed the delay.asyncLoadMapUnitfrom 32 MiB to 2 MiB lowered the time to first response from about 74 ms to about 66 ms. This was on a small 8 MiB Box only and was noisy.PR status
--no-root-container--defer-checkpointfor prewarming--background-load=eager|lazyrunsc startof a sub-container in a restoring sandboxFragmentation.releaseJobafter restore#16744 and #15557 do not change latency. Each fixes a panic we hit around restore.
Where we'd like input
--background-loadshape what you want before we polish it further?CLONE_INTO_CGROUPwith the unit's cgroup directory instead of joining through D-Bus? Or is there a reason it must go through systemd?One unrelated problem, in case it is familiar: suspend occasionally fails with
prepareSaveDead: invalidated dentries can't be saved. We saw it twice, both times on an open SQLite WAL file in a persistent volume. We have not found the cause and will open a separate issue once we have a reproducer.jingyugao commentedon Nov 5, 2026
@manninglucas Could you help review or route #15721 and #16368? These are the two changes we most need to move back to upstream gVisor.
#15721 now uses the suggested
--background-load=eager|lazyAPI, and #16368 has been updated following review, including no-root deferred-restore tests. The latest measurements and remaining limitations are summarized in the status update above.@milantracy Could you take another look at #16368 when you have time? Thanks!