Skip to content

Optimization: Prefetch the runsc and Sentry binaries when the page cache is cold #16133

Open

Description

@EtiennePerot

The idea

runsc and the Sentry binary (about 19 MB and 53 MB) are paged in on demand. On a host where they aren't in the page cache yet (a freshly booted or upgraded node, or after memory pressure), the first sandbox operation pays for that as a long series of small, serialized page faults, adding about 170 ms on a hyperdisk-balanced disk.

runsc could check, when creating a sandbox, whether both binaries are cold by sampling a few pages of their PT_LOAD segments with preadv2(RWF_NOWAIT), which costs a few microseconds. If they are, it would ask the kernel to read those segments in the background (posix_fadvise(WILLNEED) in readahead-sized steps) while the rest of sandbox setup proceeds. Filesystems that can't report cache residency (tmpfs, overlayfs) would simply be skipped.

Performance impact

  • First runsc restore / runsc run on a cold node: about 2.4x faster (p50 299 → 127 ms and 302 → 124 ms), at 2, 16 and 48 vCPUs.
  • Warm page cache: no measurable change.
  • On a cold restore the CLI uses 4.5-7 ms more CPU, since page-cache allocation moves into it from the sandbox's page faults; total CPU including the sandbox falls 12-15% at 16-48 vCPUs and rises about 5% at 2 vCPUs.
  • //test/benchmarks/base: no regressions; size_test is 2.5-4.9% faster because it drops the page cache before starting containers.

Beat the autoresearch

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

Add value by beating these benchmark numbers, or reducing any regressions they cause, or both
goos: linux
goarch: amd64
pkg: runsc payoff harness (c4-standard-16, hyperdisk-balanced, COS 129)
            │   before    │                after                │
            │   sec/op    │   sec/op     vs base                │
ColdRun       301.7m ± 6%   124.0m ± 4%  -58.91% (p=0.000 n=16)
ColdRestore   298.7m ± 3%   126.9m ± 5%  -57.53% (p=0.000 n=16)
WarmRun       30.45m ± 1%   30.18m ± 1%   -0.89% (p=0.039 n=16)
WarmRestore   37.15m ± 3%   36.90m ± 2%        ~ (p=0.926 n=16)
geomean       100.5m        64.69m       -35.62%

            │   before    │                after                │
            │ cpu-sec/op  │ cpu-sec/op   vs base                │
ColdRun       73.20m ± 4%   62.29m ± 2%  -14.90% (p=0.000 n=16)
ColdRestore   13.13m ± 5%   18.74m ± 5%  +42.66% (p=0.000 n=16)
WarmRun       50.80m ± 3%   52.12m ± 2%        ~ (p=0.073 n=16)
WarmRestore   8.180m ± 4%   8.200m ± 2%        ~ (p=0.809 n=16)
geomean       25.14m        26.58m        +5.71%

goos: linux
goarch: amd64
pkg: gvisor.dev/gvisor/test/benchmarks/base
                                       │   before    │                after                │
                                       │   sec/op    │    sec/op     vs base               │
StartupEmpty-16                          169.2m ± 1%   170.0m ±  1%       ~ (p=0.539 n=16)
StartupNginx-16                          459.1m ± 2%   460.7m ±  1%       ~ (p=0.867 n=16)
StartupNode-16                           560.1m ± 1%   558.6m ±  1%       ~ (p=0.669 n=16)
CheckpointEmpty-16                       56.89m ± 2%   56.16m ±  1%       ~ (p=0.361 n=16)
RestoreEmpty-16                          183.8m ± 2%   182.5m ±  1%       ~ (p=0.402 n=16)
CheckpointNginx-16                       91.63m ± 1%   92.04m ±  2%       ~ (p=0.564 n=16)
RestoreNginx-16                          231.5m ± 1%   232.9m ±  1%       ~ (p=0.171 n=16)
SizeEmpty-16                             346.9m ± 1%   329.9m ±  1%  -4.91% (p=0.000 n=16)
SizeNginx-16                             702.9m ± 1%   685.7m ±  1%  -2.45% (p=0.000 n=16)
SizeNode-16                              933.6m ± 1%   897.2m ±  1%  -3.90% (p=0.000 n=16)
Sysbench/testname.CPU-16                 93.80m ± 5%   95.77m ±  3%       ~ (p=0.184 n=16)
Sysbench/testname.CPU/threads.16-16      94.15m ± 3%   96.07m ±  3%       ~ (p=0.402 n=16)
Sysbench/testname.Memory-16              511.4m ± 0%   511.0m ±  0%       ~ (p=0.956 n=16)
Sysbench/testname.Memory/threads.16-16   480.0m ± 1%   481.3m ±  1%       ~ (p=0.361 n=16)
Sysbench/testname.Mutex-16               93.35m ± 5%   96.27m ±  2%       ~ (p=0.061 n=16)
Syscallbench/syscall.getpid-16           2.577µ ± 1%   2.575µ ±  1%       ~ (p=0.874 n=16)
Syscallbench/syscall.getpidopt-16        1.193µ ± 3%   1.237µ ± 11%       ~ (p=0.508 n=16)
SyscallUnderSeccomp/cacheable.false-16   1.248µ ± 8%   1.184µ ±  6%       ~ (p=0.141 n=16)
SyscallUnderSeccomp/cacheable.true-16    1.133µ ± 4%   1.160µ ±  9%       ~ (p=0.616 n=16)
geomean                                  18.98m        18.94m        -0.20%

             │            before            │                        after                        │
             │ average_container_size.bytes │ average_container_size.bytes  vs base               │
SizeEmpty-16                   20.62M ± 12%                   22.47M ± 15%       ~ (p=0.196 n=16)
SizeNginx-16                   31.26M ± 18%                   32.12M ± 10%       ~ (p=0.254 n=16)
SizeNode-16                    54.42M ± 12%                   59.23M ± 13%       ~ (p=0.323 n=16)
geomean                        32.73M                         34.97M        +6.82%

                                    │            before            │                        after                        │
                                    │ cpu_events.events_per_second │ cpu_events.events_per_second  vs base               │
Sysbench/testname.CPU-16                               1.270k ± 1%                   1.277k ±  2%       ~ (p=0.462 n=16)
Sysbench/testname.CPU/threads.16-16                    1.302k ± 8%                   1.224k ± 10%       ~ (p=0.831 n=16)
geomean                                                1.286k                        1.250k        -2.79%

                                       │              before              │                          after                          │
                                       │ memory_operations.ops_per_second │ memory_operations.ops_per_second  vs base               │
Sysbench/testname.Memory-16                                   2.534M ± 0%                        2.535M ± 0%       ~ (p=0.838 n=16)
Sysbench/testname.Memory/threads.16-16                        2.744M ± 1%                        2.735M ± 1%       ~ (p=0.642 n=16)
geomean                                                       2.637M                             2.633M       -0.16%

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

                           │      before       │                after                │
                           │ average_latency.s │ average_latency.s  vs base          │
Sysbench/testname.Mutex-16        55.00µ ± 45%       40.00µ ± 125%  ~ (p=0.743 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
Benchmark environment

GCE c4-standard-16, 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 times runsc run /bin/true and runsc restore --detach directly; "Cold" samples drop the page cache and re-read everything except the gVisor binaries first, and cpu-sec/op is the CPU of the runsc process and its waited children. The second 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

Labels

area: performance

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions