Repository navigation
Conversation
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
433c671 to
feb5c54
Compare
1858794 to
783c415
Compare
|
Do you think a cleaner API will be just to have a restore mode where we lazy load with read ahead. Currently the restore is very eager. We can make it lazy. I assume that's the problem you're solving? We can add a flag to
The downside is that all page-faults in the future incur more latency. But it's arguably more resource efficient. I think the flag captures the trade-off well. The proposed |
783c415 to
cd1614f
Compare
cd1614f to
8fcdd62
Compare
|
Thanks, done: the PR now adds Our use case is agent sandboxes: they often keep a browser or a Node.js dev server in memory, but the first actions after restore are short commands like Unrelated: on master, |
ayushr2
left a comment
There was a problem hiding this comment.
Two issues remain in lazy restore completion and lifecycle handling; details are inline.
Codex posting on behalf of Ayush
ayushr2
left a comment
There was a problem hiding this comment.
Please fold 7e7d36fa5 into 8fcdd62e5 before landing, and rebase away the merge commit. The completion/failure fixes are required for the lazy-restore feature to work correctly, so they belong in the same logical commit; gVisor applies PR commits directly rather than squashing them.
Codex posting on behalf of Ayush
79051b7 to
8c01fd4
Compare
8c01fd4 to
2c7b261
Compare
ayushr2
left a comment
There was a problem hiding this comment.
I found two issues that can persist after a lazy restore reports success.
Codex posting on behalf of Ayush
| // Fill remaining queue with reads for pages with no waiters. | ||
| throttled := apfl.throttled.Load() | ||
| if apfl.canEnqueue() && (!throttled || (apfl.qavail == maxParallel && apfl.curOp == nil)) { | ||
| if !apfl.lazy && apfl.canEnqueue() && (!throttled || (apfl.qavail == maxParallel && apfl.curOp == nil)) { |
There was a problem hiding this comment.
Preserve MADV_DONTNEED on cold anonymous huge pages. After a lazy WaitRestore() succeeds, an application can discard part of a still-cold, privately owned anonymous huge page. MemoryManager.Decommit keeps that PMA and calls MemoryFile.Decommit, which zeroes the backing range but leaves it in amfl.unloaded. On the next fault, DataFD reads the pre-discard checkpoint bytes back into a range the application expects to be zero. Eager restore has drained those reads by the time WaitRestore() returns.
Could the partial-huge-page optimization fall back to the existing unmap/DecRef path while the MemoryFile is loading? That path already handles outstanding page reads.
Codex posting on behalf of Ayush
| } | ||
| } | ||
|
|
||
| if !r.lazy { |
There was a problem hiding this comment.
Release restore-only memory once the sandbox is ready. A single untouched page can keep postRestore blocked on pageLoadResult for the sandbox’s lifetime. This read of r.lazy after the receive keeps the whole restorer reachable even after onRestoreDone clears cm.restorer. That includes the closed statefile’s 256 KiB SimpleReader buffer and the decoded checkpoint OCI specs for every container. Eager restore releases them when prefetch finishes.
Could the late-error monitor retain just the dependencies it needs, or could the restorer drop the consumed reader and checkpoint specs at their last use?
Codex posting on behalf of Ayush
2c7b261 to
d79fb66
Compare
ayushr2
left a comment
There was a problem hiding this comment.
The partial huge-page discard and restorer lifetime issues from the previous review are fixed. I found one remaining memory-accounting issue and a test caller that needs updating when this lands on current master.
Codex posting on behalf of Ayush
2a3fea6 to
9629305
Compare
ayushr2
left a comment
There was a problem hiding this comment.
The resident-neighbor accounting fix works. I found two resource costs in the revised accounting path and its new regression test.
Codex posting on behalf of Ayush
During background restore, reads of pages without waiters and page-fault reads share the storage device, so page faults wait behind background reads. With the default reader, up to 48 MiB can be queued ahead of a page fault. Add --background-load to runsc restore. eager (the default) keeps the current behavior. lazy never starts reads of pages without waiters: pages are read when the application faults on them (a fault on an async-loading MemoryFile already maps up to 32 MiB around it), or when MemoryFile.AwaitLoadAll() needs them before the next checkpoint. The pages file must stay available and unchanged until then. lazy requires --background. The async page loader no longer depends on background reads to make progress: awaited loads wake it when it is idle, and it completes when all MemoryFiles are registered and loaded, rather than when it first has no work after all MemoryFiles are registered. eager prefetch behavior does not change. Complete MemoryFiles when their remaining unloaded pages are discarded. Release the metadata reader after metadata loading, and let lazy restore finish without waiting for untouched pages. Preserve page-load error handling before and after restore completion. While a MemoryFile is loading, decommitting part of a hugepage-backed private anonymous mapping invalidates the pma instead of zeroing the backing range in place, so that checkpoint reads cannot restore discarded data into the mapping. With lazy loading, this applies until all pages are loaded or discarded. After a lazy restore completes, waiting for page loading must not keep the restorer reachable, so that consumed restore state is released. Track host page commitment separately from pending checkpoint reads. Account for pages when the host reports them resident or a checkpoint read completes. Serialize lazy restore readiness with the recording of terminal page-load errors. Signed-off-by: gaojingyu <[email protected]>
Refine lazy restore cancellation and page-loader resource lifetime. Allocate I/O vectors on demand for lazy loads and queue discarded MemoryFiles without completing them twice. Preserve partial huge-page mappings only when no complete interior huge page must be invalidated. Add regression tests and async load/decommit benchmarks. Benchmark results (24 baseline and 48 modified samples): - AsyncPageLoad/eager: 3.266 ms -> 3.152 ms (p=0.052). - DecommitHugePage: 2.599 us -> 2.758 us (p=0.052). Signed-off-by: gaojingyu <[email protected]>
9629305 to
f3a971b
Compare
During background restore, reads of pages without waiters and page-fault reads share the storage device. The device serves requests roughly in order, so a page fault waits behind all prefetch bytes in flight: up to 48 MiB with the default reader (12 reads × 4 MiB).
This matters for agent sandboxes: they often keep a browser or a Node.js dev server in memory, but the first actions after restore are short commands like
lsandcat, which touch little of it.Following the review suggestion, this PR adds
runsc restore --background-load=eager|lazy:eager(default): current behavior.lazy: no reads of pages without waiters. Pages are read when the application faults on them (a fault on an async-loading MemoryFile already maps and loads up to 32 MiB around it), or whenMemoryFile.AwaitLoadAll()needs them before the next checkpoint. The pages file must stay available until then. Requires--background.The async page loader no longer depends on background reads to make progress: awaited loads wake it when it is idle, and it completes when all MemoryFiles are registered and loaded, rather than when it first has no work after registration.
lazyis then only a condition that skips reads of pages without waiters;eagerbehavior does not change.Results
Kubernetes node, 8 vCPU, local virtual disk, read bandwidth limited with cgroup
io.max(the limit also covers prewarm reads). The page cache is dropped before each restore.Time from restore start to the first command done. Measured on the node: the first command runs with
runsc execas soon as the application starts, so orchestration (Pod creation, readiness probes) is excluded. "1 background read" is the earlier version of this PR (prefetch limited to one read in flight).ls /ls /¹
catof the checkpoint files into the page cache, started with the restore.Median of 3–5 runs, configurations interleaved; Chromium at 50 MB/s: p = 0.008 (two-sided exact Mann-Whitney U, 5 runs each).
End to end with
eager(restore request through the orchestrator to the first command, 3 runs):ls /Cost. With lazy, the next checkpoint first reads the pages that are still unloaded. Without a bandwidth limit this added 0.4–0.75 s to suspend (170–700 MB). On slow storage it is about (unloaded bytes / bandwidth), unless the page cache was prewarmed.
Tests
TestAsyncPageLoadLazy: no reads start before a page is awaited; one awaited page causes one read; the load does not complete while pages are unloaded;AwaitLoadAll()loads the remaining pages with the correct contents.//pkg/sentry/pgalloc:pgalloc_test(30 runs;TestAsyncSaveToPreservesContentscovers eager completion),//pkg/sentry/kernel:kernel_test,//runsc/sandbox:sandbox_test,//runsc/config:config_test,make lint. Built//runsc,//runsc/cmd/sentry:gvisor_sentry,//runsc/container:container_test.Separately, on current master
containerManager.StartSubcontainer()callsRestoreSubcontainer(args, nil), andRestoreSubcontainer()writesreply.KernelStarted, so arunsc startof a subcontainer on a restoring sandbox panics (introduced in a49825f). The end-to-end tests above ran with a local fix (&sentryapi.RestoreReply{}); it is not part of this PR.AI assistance is disclosed in accordance with CONTRIBUTING.md.