Repository navigation
Description
The idea
state.Save builds the checkpoint's encoder state on the Sentry's Go heap while the kernel is paused, with the default GOGC. A save allocates far more than the live heap at the start of the save, so the Go runtime runs collections in the middle of it that find almost nothing to free. On a non-resuming runsc checkpoint, the GC also comes back on with the heap well above its target, so a full cycle runs during the RPC reply and sandbox exit. Under a small CPU quota, those few milliseconds of GC CPU push checkpoint and exit into the next CFS period.
The Sentry could turn the GC off for the length of state.Save. A soft memory limit would bound it, set to the runtime's current memory use plus max(used, 128 MiB). If the runtime collects anyway because the limit was reached, normal GC should come back immediately. Without that rule, a large heap thrashes near the limit and a save got 3.3x slower in testing. After a resuming save (--leave-running, autosave), the old settings would be restored. After a non-resuming save, the GC would stay off, because the sandbox is always killed afterwards. This could share the small refcounted GC-suspension helper proposed in #16134 (defer GC until the container runs), so a boot-time suspension and a save-time suspension nest correctly.
Performance impact
runsc checkpoint6-7% faster on an idle node at any CPU quota. On a loaded node it is 13% faster at a 1-CPU quota and 33% faster at 0.25 CPU (101 → 68 ms).- Total suspend (checkpoint until the sandbox is gone) is 3-6% faster at a 1-CPU quota or with no quota, and 16-30% faster at 0.25 CPU. The size of the gain depends on where the save falls relative to the CFS period boundary.
- On a large heap (100k tmpfs files, about 740 MiB peak), save time is unchanged and the Sentry's peak RSS is 2-6% lower. On small sandboxes, peak RSS is up to 1.6% (about 0.6 MiB) higher (p=0.007 on one host).
- On the loaded node at 0.25 CPU, restores ran 1.4% slower (p=0.02). All of the extra time is in
runsc create, which this change doesn't touch. It is not seen without load or at a 1-CPU quota. //test/benchmarks/base: no regressions.startup_testcheckpoint/restore is unchanged (the containers have little state to save).
Beat the autoresearch
The following benchmark results were benchmarked using this patch: master...EtiennePerot:gvisor:autoresearch/gc-off-during-save
Add value by beating these benchmark numbers, or reducing any regressions they cause, or both
goos: linux
goarch: amd64
pkg: checkpoint/restore cycle harness (pause + app container, c4-standard-48)
│ before │ after │
│ sec/op │ sec/op vs base │
Suspend/load=fixed-rate/cpu=0.25 165.5m ± 1% 138.9m ± 2% -16.10% (n=2617+2633)
Suspend/load=fixed-rate/cpu=1 99.99m ± 1% 93.65m ± 1% -6.35% (n=1759+1751)
Suspend/load=single/cpu=0.25 106.27m ± 28% 74.39m ± 19% -30.00% (p=0.000 n=124)
Suspend/load=single/cpu=1 47.16m ± 1% 45.60m ± 0% -3.30% (p=0.000 n=124)
Suspend/load=single/cpu=unlimited 61.48m ± 0% 59.11m ± 1% -3.87% (n=124)
RunscCheckpoint/load=fixed-rate/cpu=0.25 100.68m ± 2% 67.89m ± 5% -32.57% (n=2617+2633)
RunscCheckpoint/load=fixed-rate/cpu=1 45.38m ± 2% 39.29m ± 2% -13.41% (n=1759+1751)
RunscCheckpoint/load=single/cpu=0.25 21.92m ± 1% 20.47m ± 1% -6.61% (n=124)
RunscCheckpoint/load=single/cpu=1 21.73m ± 1% 20.27m ± 1% -6.73% (n=124)
RunscCheckpoint/load=single/cpu=unlimited 35.21m ± 1% 32.95m ± 1% -6.42% (n=124)
WarmResume/load=fixed-rate/cpu=0.25 470.4m ± 1% 477.1m ± 1% +1.42% (p=0.022 n=2089+2105)
WarmResume/load=fixed-rate/cpu=1 166.3m ± 1% 163.6m ± 1% -1.60% (p=0.001 n=1407+1399)
WarmResume/load=single/cpu=0.25 280.0m ± 4% 270.3m ± 5% ~ (p=0.101 n=120)
WarmResume/load=single/cpu=1 83.02m ± 1% 83.53m ± 1% ~ (p=0.246 n=120)
WarmResume/load=single/cpu=unlimited 81.59m ± 1% 81.17m ± 0% ~ (p=0.292 n=120)
geomean 82.70m 75.09m -9.21%
pkg: gvisor.dev/gvisor/test/benchmarks/base
│ before │ after │
│ sec/op │ sec/op vs base │
StartupEmpty-16 180.7m ± 4% 181.2m ± 4% ~ (p=0.669 n=16)
StartupNginx-16 475.8m ± 2% 476.5m ± 3% ~ (p=0.926 n=16)
StartupNode-16 576.1m ± 3% 572.4m ± 4% ~ (p=0.926 n=16)
CheckpointEmpty-16 58.06m ± 3% 57.83m ± 4% ~ (p=0.239 n=16)
RestoreEmpty-16 188.0m ± 2% 186.5m ± 2% ~ (p=0.956 n=16)
CheckpointNginx-16 92.99m ± 2% 92.67m ± 1% ~ (p=0.491 n=16)
RestoreNginx-16 234.8m ± 1% 233.7m ± 2% ~ (p=0.445 n=16)
SizeEmpty-16 370.5m ± 1% 364.3m ± 1% -1.69% (p=0.017 n=16)
SizeNginx-16 733.6m ± 1% 721.6m ± 1% -1.63% (p=0.000 n=16)
SizeNode-16 849.3m ± 1% 834.5m ± 2% ~ (p=0.080 n=16)
geomean 277.7m 275.6m -0.74%
│ before │ after │
│ average_container_size.bytes │ average_container_size.bytes vs base │
SizeEmpty-16 20.82M ± 18% 20.15M ± 16% ~ (p=0.838 n=16)
SizeNginx-16 32.53M ± 13% 32.34M ± 9% ~ (p=0.985 n=16)
SizeNode-16 57.53M ± 4% 58.38M ± 6% ~ (p=0.305 n=16)
geomean 33.90M 33.63M -0.78%
pkg: runsc checkpoint harness (fresh busybox sandbox)
│ before │ after │
│ sec/op │ sec/op vs base │
Checkpoint/vcpus=4/app=small/cpu=0.25 14.00m ± 7% 11.00m ± 9% -21.43% (p=0.000 n=12)
Checkpoint/vcpus=4/app=small/cpu=unlimited 12.50m ± 4% 11.00m ± 9% -12.00% (p=0.000 n=12)
Checkpoint/vcpus=4/app=bigheap/cpu=unlimited 2.253 ± 3% 2.264 ± 3% ~ (p=1.000 n=6)
Checkpoint/vcpus=16/app=small/cpu=0.25 13.00m ± 15% 12.00m ± 8% -7.69% (p=0.019 n=12)
Checkpoint/vcpus=16/app=small/cpu=unlimited 13.00m ± 8% 12.00m ± 25% ~ (p=0.164 n=12)
Checkpoint/vcpus=16/app=bigheap/cpu=0.25 11.90 ± 11% 11.35 ± 2% ~ (p=0.065 n=6)
CheckpointExit/vcpus=4/app=small/cpu=0.25 17.00m ± 12% 14.00m ± 14% -17.65% (p=0.000 n=12)
CheckpointExit/vcpus=4/app=small/cpu=unlimited 17.00m ± 6% 14.50m ± 17% -14.71% (p=0.000 n=12)
CheckpointExit/vcpus=4/app=bigheap/cpu=unlimited 2.311 ± 3% 2.323 ± 3% ~ (p=1.000 n=6)
CheckpointExit/vcpus=16/app=small/cpu=0.25 19.00m ± 16% 17.00m ± 12% ~ (p=0.051 n=12)
CheckpointExit/vcpus=16/app=small/cpu=unlimited 17.00m ± 6% 16.00m ± 19% ~ (p=0.638 n=12)
CheckpointExit/vcpus=16/app=bigheap/cpu=0.25 12.15 ± 10% 11.60 ± 2% ~ (p=0.065 n=6)
geomean 106.3m 96.68m -9.03%
│ before │ after │
│ B │ B vs base │
SentryPeakRSS/vcpus=4/app=small/cpu=0.25 35.78Mi ± 2% 35.79Mi ± 1% ~ (p=0.682 n=12)
SentryPeakRSS/vcpus=4/app=small/cpu=unlimited 35.64Mi ± 1% 36.23Mi ± 1% +1.64% (p=0.007 n=12)
SentryPeakRSS/vcpus=4/app=bigheap/cpu=unlimited 755.8Mi ± 5% 709.6Mi ± 1% -6.12% (p=0.004 n=6)
SentryPeakRSS/vcpus=16/app=small/cpu=0.25 36.02Mi ± 1% 36.01Mi ± 1% ~ (p=0.843 n=12)
SentryPeakRSS/vcpus=16/app=small/cpu=unlimited 37.39Mi ± 2% 37.93Mi ± 4% +1.43% (p=0.024 n=12)
SentryPeakRSS/vcpus=16/app=bigheap/cpu=0.25 738.8Mi ± 2% 727.1Mi ± 1% -1.58% (p=0.041 n=6)
geomean 99.31Mi 98.51Mi -0.81%
Benchmark environment
GCE c4-standard-4/16/48, COS cos-129-19506-448-8 (kernel 6.12.105+), hyperdisk-balanced. before is master at 2511bc60218a. after is the patch above, except that the two harness blocks used a revision that differs only in comments and an unused FreeOSMemory helper. The first block is a checkpoint/restore cycle harness on c4-standard-48. Suspend runs from the checkpoint request until the sandbox is gone, RunscCheckpoint is the runsc checkpoint call alone, and WarmResume runs from the restore request to the first HTTP 200. load=single means one sandbox at a time with a 1-2 s hold between cycles. load=fixed-rate means many live sandboxes cycling at a fixed rate on the same node, with arms interleaved over 2-3 rounds. cpu= is the sandbox's CFS quota. Its samples are individual operations within each run, so they are not fully independent. The second block is the real //test/benchmarks/base targets on c4-standard-16, run against docker runtimes for each build. The third block times runsc checkpoint (Checkpoint), checkpoint until the sandbox exits (CheckpointExit) and the Sentry's VmHWM for a fresh busybox sandbox, either idle (small) or holding 100k tmpfs files (bigheap). It has 1 ms timing resolution.
Activity
Suspend Sentry Go GC during sandbox boot, checkpoint, and restore
Suspend Sentry Go GC during sandbox boot, checkpoint, and restore
GC: Suspend Go GC during boot, checkpoint, and restore.
GC: Suspend Go GC during boot, checkpoint, and restore.
GC: Suspend Go GC during boot, checkpoint, and restore.
GC: Suspend Go GC during boot, checkpoint, and restore.
GC: Suspend Go GC during boot, checkpoint, and restore.
GC: Suspend Go GC during boot, checkpoint, and restore.
GC: Suspend Go GC during boot, checkpoint, and restore.
GC: Suspend Go GC during boot, checkpoint, and restore.
GC: Suspend Go GC during boot, checkpoint, and restore.
GC: Suspend Go GC during boot, checkpoint, and restore.
GC: Suspend Go GC during boot, checkpoint, and restore.
GC: Suspend Go GC during boot, checkpoint, and restore.
GC: Suspend Go GC during boot, checkpoint, and restore.
GC: Suspend Go GC during boot, checkpoint, and restore.