Skip to content

Optimization: Decode the kernel state while the remaining containers register their restore #16150

Open

Description

@EtiennePerot

The idea

When a multi-container sandbox is restored (one runsc restore per container, as with a pause container plus app containers), the Sentry waits for the last container to register before it starts Kernel.LoadFrom. Decoding the kernel state is single-threaded and CPU-bound, and it runs only after every registration RPC has completed, so the whole decode sits on the critical path even though the Sentry is mostly idle while the remaining containers register.

runsc could start decoding in a background goroutine when the first container registers, and finish the restore when the last one arrives. Host FDs and per-container private MemoryFiles (filestores, including the default --overlay2=root:self) that belong to containers not registered yet would be recorded as placeholders and resolved once they arrive. The current kernel would be swapped out only after the decode completes, so control RPCs never run into a partially-decoded kernel. This should only apply for restores with at least 2 containers, not with rootfs extraction, filesystem restore or nvproxy/tpuproxy, and only when the sandbox's CPU quota is at least 1 CPU. Below 1 CPU, the decode takes up too much CPU and throttles the other runsc start RPCs.

Performance impact

  • Warm multi-container restore on 16 vCPUs: -16% (60.6 → 50.6 ms) without CPU quota and -11% (68.6 → 61.1 ms) at 1 CPU (-6% with root:self). The gain grows with the host's core count: -16 to -17% on 48 vCPUs, 0 to -3% on 2 vCPUs.
  • About +4% CPU per checkpoint/restore cycle, which is because of the extra Go GC cycle during the decode. With 44 or 176 concurrent sandboxes on 16 vCPUs, checkpoint gets 8% or 3% slower. However, combined with the Sentry GC deferred until the container runs (Optimization: Suspend the Sentry's Go GC until the container runs #16134), the extra CPU usage goes away.

Beat the autoresearch

The following benchmark results were benchmarked using this patch: master...EtiennePerot:gvisor:autoresearch/early-decode

Add value by beating these benchmark numbers, or reducing any regressions they cause, or both
goos: linux
goarch: amd64
pkg: gvisor.dev/gvisor/test/benchmarks/base
                   │   before    │               after                │
                   │   sec/op    │   sec/op     vs base               │
StartupEmpty-16      174.9m ± 1%   177.6m ± 2%       ~ (p=0.073 n=16)
StartupNginx-16      476.0m ± 1%   473.0m ± 2%       ~ (p=0.590 n=16)
StartupNode-16       591.0m ± 1%   583.8m ± 1%  -1.22% (p=0.014 n=16)
CheckpointEmpty-16   57.48m ± 1%   57.82m ± 2%       ~ (p=0.468 n=16)
RestoreEmpty-16      186.8m ± 2%   188.0m ± 2%       ~ (p=0.838 n=16)
CheckpointNginx-16   93.75m ± 2%   92.33m ± 1%       ~ (p=0.160 n=16)
RestoreNginx-16      233.6m ± 1%   231.9m ± 1%       ~ (p=0.119 n=16)
SizeEmpty-16          2.094 ± 0%    2.096 ± 0%       ~ (p=0.752 n=16)
SizeNginx-16          2.135 ± 0%    2.136 ± 0%       ~ (p=0.724 n=16)
SizeNode-16           2.111 ± 1%    2.108 ± 0%       ~ (p=0.224 n=16)
geomean              401.6m        401.1m       -0.13%

             │                before                │                            after                            │
             │ average_container_memory_usage.bytes │ average_container_memory_usage.bytes  vs base               │
SizeEmpty-16                            14.93M ± 2%                            14.94M ± 1%       ~ (p=0.402 n=16)
SizeNginx-16                            23.90M ± 1%                            23.96M ± 1%       ~ (p=0.521 n=16)
SizeNode-16                             48.84M ± 1%                            48.82M ± 1%       ~ (p=0.669 n=16)
geomean                                 25.92M                                 25.95M       +0.10%

pkg: multi-container checkpoint/restore cycle harness (pause + app container)
                                                      │    before    │                    after                    │
                                                      │    sec/op    │    sec/op     vs base                       │
WarmResume/vcpus=16/cpu=unlimited/overlay=root:memory   60.56m ±  1%   50.60m ±  0%  -16.45% (p=0.000 n=40)
Suspend/vcpus=16/cpu=unlimited/overlay=root:memory      50.17m ±  3%   49.62m ±  1%        ~ (p=0.525 n=42)
WarmResume/vcpus=16/cpu=1/overlay=root:memory           68.57m ±  4%   61.06m ±  4%  -10.96% (p=0.000 n=40)
Suspend/vcpus=16/cpu=1/overlay=root:memory              45.39m ±  2%   44.53m ±  2%   -1.91% (p=0.001 n=42)
WarmResume/vcpus=16/cpu=unlimited/overlay=root:self     60.76m ±  1%   50.61m ±  1%  -16.71% (p=0.000 n=40)
Suspend/vcpus=16/cpu=unlimited/overlay=root:self        50.49m ±  3%   49.56m ±  2%        ~ (p=0.055 n=42)
WarmResume/vcpus=16/cpu=1/overlay=root:self             68.51m ±  2%   64.11m ±  6%   -6.42% (p=0.000 n=40)
Suspend/vcpus=16/cpu=1/overlay=root:self                45.32m ±  2%   44.94m ±  2%        ~ (p=0.202 n=42)
WarmResume/vcpus=16/cpu=0.25/overlay=root:memory        245.2m ±  6%   228.6m ±  7%   -6.80% (p=0.030 n=40)
Suspend/vcpus=16/cpu=0.25/overlay=root:memory           124.1m ±  1%   123.2m ±  1%        ~ (p=0.195 n=42)
WarmResume/vcpus=2/cpu=unlimited/overlay=root:memory    74.07m ±  2%   71.53m ±  5%   -3.43% (p=0.000 n=40)
Suspend/vcpus=2/cpu=unlimited/overlay=root:memory       45.13m ±  1%   44.31m ±  2%   -1.81% (p=0.044 n=42)
WarmResume/vcpus=2/cpu=1/overlay=root:memory            71.80m ±  2%   71.81m ±  4%        ~ (p=0.506 n=40)
Suspend/vcpus=2/cpu=1/overlay=root:memory               45.35m ±  1%   44.12m ±  2%   -2.72% (p=0.016 n=42)
WarmResume/vcpus=2/cpu=0.25/overlay=root:memory         183.4m ±  5%   184.9m ±  7%        ~ (p=0.973 n=40)
Suspend/vcpus=2/cpu=0.25/overlay=root:memory            99.76m ±  1%   99.55m ±  2%        ~ (p=0.719 n=42)
WarmResume/vcpus=4/cpu=unlimited/overlay=root:memory    69.06m ± 11%   64.94m ±  4%   -5.97% (p=0.008 n=40)
Suspend/vcpus=4/cpu=unlimited/overlay=root:memory       44.07m ±  3%   44.04m ±  1%        ~ (p=0.471 n=42)
WarmResume/vcpus=4/cpu=1/overlay=root:memory            69.95m ±  3%   65.93m ±  5%   -5.74% (p=0.000 n=40)
Suspend/vcpus=4/cpu=1/overlay=root:memory               44.38m ±  1%   43.02m ±  3%   -3.08% (p=0.017 n=42)
WarmResume/vcpus=4/cpu=0.25/overlay=root:memory         199.5m ±  6%   184.5m ± 10%        ~ (p=0.076 n=40)
Suspend/vcpus=4/cpu=0.25/overlay=root:memory            99.36m ±  2%   98.36m ±  2%        ~ (p=0.352 n=42)
WarmResume/vcpus=48/cpu=unlimited/overlay=root:memory   71.79m ±  1%   60.52m ±  1%  -15.70% (p=0.000 n=40)
Suspend/vcpus=48/cpu=unlimited/overlay=root:memory      62.31m ±  3%   60.93m ±  2%        ~ (p=0.082 n=42)
WarmResume/vcpus=48/cpu=1/overlay=root:memory           75.27m ±  4%   62.39m ±  5%  -17.12% (p=0.000 n=40)
Suspend/vcpus=48/cpu=1/overlay=root:memory              50.01m ±  3%   50.57m ±  1%        ~ (p=0.188 n=42)
WarmResume/vcpus=16/cpu=1/sandboxes=44                  328.3m ±  3%   324.2m ±  3%   -1.26% (p=0.049 n=440)
Suspend/vcpus=16/cpu=1/sandboxes=44                     225.8m ±  3%   244.9m ±  4%   +8.45% (p=0.000 n=528)
WarmResume/vcpus=16/cpu=1/sandboxes=176                 624.2m ±  0%   608.3m ±  1%   -2.55% (n=5470+5461)
Suspend/vcpus=16/cpu=1/sandboxes=176                    290.9m ±  1%   299.9m ±  1%   +3.11% (p=0.000 n=5822+5813)
geomean                                                 88.21m         84.49m         -4.22%

pkg: multi-container checkpoint/restore cycle harness, GC deferral interaction
                                          │   before    │               after                │
                                          │   sec/op    │   sec/op     vs base               │
WarmResume/vcpus=16/cpu=1/gc-deferral=no    67.72m ± 1%   63.30m ± 4%  -6.52% (n=80)
WarmResume/vcpus=16/cpu=1/gc-deferral=yes   54.14m ± 2%   56.87m ± 1%  +5.05% (p=0.020 n=80)
geomean                                     60.55m        60.00m       -0.91%

                                           │    before    │               after                │
                                           │  cpu-sec/op  │  cpu-sec/op   vs base              │
CPUPerCycle/vcpus=16/cpu=1/gc-deferral=no    106.1m ± ∞ ¹   110.6m ± ∞ ¹  +4.25% (p=0.029 n=4)
CPUPerCycle/vcpus=16/cpu=1/gc-deferral=yes   97.39m ± ∞ ¹   97.94m ± ∞ ¹       ~ (p=0.686 n=4)
geomean                                      101.7m         104.1m        +2.39%
¹ need >= 6 samples for confidence interval at level 0.95
Benchmark environment

GCE c4-standard-2/4/16/48 (vcpus=), COS cos-129-19506-448-8 (kernel 6.12.105+), hyperdisk-balanced. before is master at 2511bc60218a, after is the patch above. The cycle harness repeatedly checkpoints and restores a sandbox made of a pause container and a small HTTP app container (two runsc restore calls), with a 1.5 s hold between cycles. WarmResume runs from restore request to the app's first HTTP 200, and Suspend is checkpoint including teardown. cpu= is the sandbox's CFS quota (unlimited means a quota of at least the host's vCPU count), and overlay= is the rootfs overlay medium. The sandboxes= rows run that many sandboxes concurrently (no hold) and don't set an overlay medium. Their samples are individual activations within one run, so they are not independent and the p-values overstate significance. At cpu=0.25 the gate disables the change, so those differences are noise. In the GC deferral block, gc-deferral=no compares master with the patch, and gc-deferral=yes compares the GC-deferral patch alone with the GC-deferral patch plus this one. CPUPerCycle is the CPU of the whole benchmark cgroup (sandboxes, runsc CLI, harness) per cycle, with one sample per run. In the main block, the patch build differs from the linked branch by one doc comment. The last block is the real //test/benchmarks/base targets, run against Docker runtimes for each build.

Activity

  1. added this to the Lightspeed milestone on Oct 21, 2026
  2. added
    area: performance
    on Oct 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: performance

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions