Skip to content

Optimization: Suspend the Sentry's Go GC until the container runs #16134

Open

Description

@EtiennePerot

The idea

During runsc boot, the Sentry builds a large set of long-lived objects (kernel, VFS, netstack, and on restore the whole decoded kernel state) into a heap that starts at a few MiB. With the default GOGC, the Go runtime collects every time the heap doubles, so several collections land on the critical path of sandbox start and restore while finding almost nothing to free. Under a small CPU quota that GC CPU is paid for again in throttling.

The Sentry could turn the GC off from the start of boot until shortly after the container runs (for example 500 ms later, to stay clear of the first requests), with a soft memory limit as a safety bound, then return the startup garbage to the host with one FreeOSMemory. If the limit is ever hit, it should hand back to normal GC immediately rather than thrash near the limit. A small refcounted helper would let other suspensions (such as during checkpoint save) compose with this one.

Performance impact

  • Warm restore end to end: 3% to 24% faster at the median in every configuration tested (4-48 vCPUs; 0.25-CPU quota, 1-CPU quota, unlimited CPU quota). With 44 concurrent sandboxes each under tight CPU quota to magnify the effect, p50 229 → 184 ms and p95 302 → 230 ms.
  • Sentry anonymous memory: 5-8% lower than today, because the startup garbage is returned instead of staying resident, which on mostly-idle apps would not be reclaimed until much later.
  • //test/benchmarks/base: StartupEmpty, RestoreEmpty and CheckpointEmpty 2-3% faster, usage_test memory -4.8%, no regressions.
  • A request arriving right when the GC resumes pays for that collection (about 1.3 ms), as seen in single-shot syscallbench. nginx at concurrency 1 may lose up to 1% shortly after start (not confirmed at p<0.01).

Beat the autoresearch

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

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, 1-2 s hold between cycles)
                                  │    before    │                 after                  │
                                  │    sec/op    │    sec/op      vs base                 │
WarmResume/vcpus=4/cpu=0.25         187.5m ±  7%    155.3m ±  9%  -17.16% (p=0.000 n=120)
WarmResume/vcpus=4/cpu=1            70.77m ±  1%    56.53m ±  2%  -20.12% (n=80)
WarmResume/vcpus=4/cpu=unlimited    69.39m ± 10%    57.98m ±  1%  -16.44% (n=80)
WarmResume/vcpus=16/cpu=0.25        209.1m ±  5%    189.0m ±  4%   -9.62% (p=0.000 n=120)
WarmResume/vcpus=16/cpu=1           69.56m ±  1%    55.14m ±  1%  -20.72% (n=80)
WarmResume/vcpus=16/cpu=unlimited   62.59m ±  1%    59.53m ±  1%   -4.89% (n=80)
WarmResume/vcpus=48/cpu=0.25        263.1m ±  6%    200.5m ±  7%  -23.79% (n=80)
WarmResume/vcpus=48/cpu=1           75.92m ±  2%    69.90m ±  9%   -7.93% (n=80)
WarmResume/vcpus=48/cpu=unlimited   72.94m ±  1%    70.62m ±  1%   -3.18% (p=0.000 n=80)
Suspend/vcpus=4/cpu=0.25            81.18m ±  8%    91.93m ± 22%        ~ (p=0.775 n=126)
Suspend/vcpus=4/cpu=1               45.53m ±  1%    44.34m ±  1%   -2.62% (p=0.000 n=84)
Suspend/vcpus=4/cpu=unlimited       46.01m ±  1%    44.74m ±  1%   -2.75% (p=0.000 n=84)
Suspend/vcpus=16/cpu=0.25           94.46m ± 12%   103.43m ± 29%        ~ (p=0.188 n=126)
Suspend/vcpus=16/cpu=1              46.34m ±  1%    45.38m ±  1%   -2.07% (p=0.000 n=84)
Suspend/vcpus=16/cpu=unlimited      51.12m ±  1%    49.57m ±  1%   -3.04% (p=0.000 n=84)
Suspend/vcpus=48/cpu=0.25           79.32m ± 36%    92.58m ± 18%        ~ (p=0.281 n=84)
Suspend/vcpus=48/cpu=1              50.10m ±  1%    49.47m ±  1%   -1.26% (p=0.050 n=84)
Suspend/vcpus=48/cpu=unlimited      63.13m ±  2%    60.41m ±  1%   -4.31% (p=0.000 n=84)
geomean                             78.09m          73.23m         -6.22%

                                            │     before     │                after                 │
                                            │       B        │       B         vs base              │
IdleSentryRssAnon/age=15s                     8.815Mi ±  ∞ ¹   8.130Mi ±  ∞ ¹  -7.77% (p=0.029 n=4)
IdleSentryRssAnon/age=180s                    9.021Mi ±  ∞ ¹   8.555Mi ±  ∞ ¹  -5.16% (p=0.029 n=4)
RestoredSentryRssAnon/sandboxes=44/cpu=0.25   10.85Mi ± 0%     10.03Mi ± 0%    -7.56% (n=661)
geomean                                       9.520Mi          8.869Mi         -6.84%
¹ need >= 6 samples for confidence interval at level 0.95

pkg: gvisor.dev/gvisor/test/benchmarks/base
                                                │   before    │                after                │
                                                │   sec/op    │   sec/op     vs base                │
CheckpointEmpty-16                                54.73m ± 2%   52.98m ± 2%   -3.19% (p=0.004 n=16)
CheckpointNginx-16                                88.54m ± 1%   90.07m ± 2%        ~ (p=0.073 n=16)
Hackbench/ipcMode.pipe/processMode.thread-16      169.8m ± 7%   163.7m ± 3%   -3.60% (p=0.032 n=16)
Hackbench/ipcMode.socket/processMode.process-16   644.2m ± 2%   630.0m ± 2%   -2.21% (p=0.010 n=16)
RestoreEmpty-16                                   179.1m ± 2%   174.8m ± 1%   -2.40% (p=0.008 n=16)
RestoreNginx-16                                   224.7m ± 2%   222.1m ± 2%        ~ (p=0.305 n=16)
SizeNginx-16                                      751.2m ± 1%   754.6m ± 2%        ~ (p=0.491 n=16)
SizeNode-16                                       899.3m ± 1%   897.1m ± 1%        ~ (p=0.287 n=16)
StartupEmpty-16                                   167.4m ± 2%   164.3m ± 1%   -1.85% (p=0.008 n=16)
StartupNginx-16                                   451.4m ± 1%   448.1m ± 1%        ~ (p=0.056 n=16)
StartupNode-16                                    539.2m ± 1%   541.0m ± 1%        ~ (p=0.423 n=16)
Sysbench/testname.CPU-16                          784.0m ± 5%   771.0m ± 2%        ~ (p=0.160 n=16)
Sysbench/testname.CPU/threads.16-16               283.4m ± 4%   277.6m ± 4%        ~ (p=0.724 n=16)
Sysbench/testname.Memory-16                        1.297 ± 1%    1.294 ± 0%        ~ (p=0.642 n=16)
Sysbench/testname.Memory/threads.16-16             1.257 ± 1%    1.252 ± 0%        ~ (p=0.138 n=16)
Sysbench/testname.Mutex-16                        285.1m ± 4%   276.0m ± 2%   -3.19% (p=0.039 n=16)
Syscallbench/benchtime.1x/syscall.getpid-16       12.70m ± 6%   14.02m ± 7%  +10.42% (p=0.002 n=16)
Syscallbench/benchtime.1x/syscall.getpidopt-16    11.66m ± 7%   10.67m ± 3%   -8.51% (p=0.003 n=16)
Syscallbench/syscall.getpid-16                    2.477µ ± 3%   2.480µ ± 2%        ~ (p=0.676 n=16)
Syscallbench/syscall.getpidopt-16                 1.127µ ± 5%   1.107µ ± 4%        ~ (p=0.485 n=16)
SizeEmpty-16                                       2.091 ± 0%    2.091 ± 0%        ~ (p=0.696 n=16)
geomean                                           86.90m        86.02m        -1.01%

                                                │      before      │                  after                   │
                                                │ execution_time.s │ execution_time.s  vs base                │
Hackbench/ipcMode.pipe/processMode.thread-16           12.00m ± 8%       11.00m ±  9%   -8.33% (p=0.008 n=16)
Hackbench/ipcMode.socket/processMode.process-16        42.50m ± 8%       37.00m ± 16%        ~ (p=0.053 n=16)
geomean                                                22.58m            20.17m        -10.67%

                                                │          before           │                       after                       │
                                                │ execution_time_per_loop.s │ execution_time_per_loop.s  vs base                │
Hackbench/ipcMode.pipe/processMode.thread-16                    12.00m ± 8%                11.00m ±  9%   -8.33% (p=0.008 n=16)
Hackbench/ipcMode.socket/processMode.process-16                 42.50m ± 8%                37.00m ± 16%        ~ (p=0.053 n=16)
geomean                                                         22.58m                     20.17m        -10.67%

             │            before            │                        after                        │
             │ average_container_size.bytes │ average_container_size.bytes  vs base               │
SizeNginx-16                   35.42M ± 22%                   34.35M ± 14%       ~ (p=1.000 n=16)
SizeNode-16                    56.80M ± 12%                   58.03M ±  8%       ~ (p=0.491 n=16)
geomean                        44.85M                         44.64M        -0.47%

                                    │            before            │                        after                        │
                                    │ cpu_events.events_per_second │ cpu_events.events_per_second  vs base               │
Sysbench/testname.CPU-16                               359.1 ±  9%                    354.2 ± 10%       ~ (p=0.346 n=16)
Sysbench/testname.CPU/threads.16-16                    393.8 ± 16%                    362.8 ± 17%       ~ (p=0.642 n=16)
geomean                                                376.0                          358.4        -4.67%

                                       │              before              │                          after                          │
                                       │ memory_operations.ops_per_second │ memory_operations.ops_per_second  vs base               │
Sysbench/testname.Memory-16                                   1.031M ± 0%                        1.032M ± 0%       ~ (p=0.897 n=16)
Sysbench/testname.Memory/threads.16-16                        1.077M ± 1%                        1.080M ± 0%       ~ (p=0.138 n=16)
geomean                                                       1.054M                             1.056M       +0.17%

                           │          before          │                   after                    │
                           │ average_execution_time.s │ average_execution_time.s  vs base          │
Sysbench/testname.Mutex-16                 50.00µ ± ?                100.00µ ± ?  ~ (p=0.420 n=16)

                           │      before       │                after                │
                           │ average_latency.s │ average_latency.s  vs base          │
Sysbench/testname.Mutex-16        45.00µ ± 56%        80.00µ ± 50%  ~ (p=0.124 n=16)

                           │         before          │                    after                    │
                           │ stddev_execution_time.s │ stddev_execution_time.s  vs base            │
Sysbench/testname.Mutex-16                0.000 ± 0%                0.000 ± 0%  ~ (p=1.000 n=16) ¹
¹ all samples are equal

             │                before                │                            after                            │
             │ average_container_memory_usage.bytes │ average_container_memory_usage.bytes  vs base               │
SizeEmpty-16                            14.89M ± 2%                            14.17M ± 1%  -4.81% (p=0.000 n=16)
Benchmark environment

GCE c4-standard-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 first block is a checkpoint/restore cycle harness (pause + small HTTP app container, 1-2 s between cycles): WarmResume is restore request to first HTTP 200, Suspend is checkpoint including teardown, cpu= is the sandbox's CFS quota, and the memory rows are the Sentry's RssAnon for idle docker run containers and for restored sandboxes. The second block is the real //test/benchmarks/base targets run against docker runtimes for each build; Syscallbench/benchtime.1x/* is syscallbench_test at -test.benchtime=1x, which times one exec right after start.

Activity

  1. added this to the Lightspeed milestone on Oct 21, 2026
  2. added
    area: performance
    on Oct 21, 2026
  3. added 16 commits that reference this issue on Oct 30, 2026
    1eea32c
    7b49dec
    6975beb
    45c398f
    6aa5cb1
    d7ae7eb
    5f6da28
    9b62a57
    9d3e651
    dba9830
    7eccf74
    874db9f
    5068ecb
    a48b7a1
    71b5044
    c31b2ad
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area: performance

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions