Skip to content

Optimization: Stop raising GOMAXPROCS for the parallel restore pages-file reader #16138

Closed

Description

@EtiennePerot

The idea

aio.NewGoQueue raises GOMAXPROCS by its worker count until the queue is destroyed. The restore pages-file reader uses one with 12 workers, so a sandbox restores with 12 extra Ps (for example 14 Ps for a 0.25-CPU sandbox, whose base GOMAXPROCS is 2 with --cpu-num-from-quota). The workers spend most of their time blocked in pread, where they don't need a P. The extra Ps mainly let the restore goroutines and the GC run past the CPU quota, so the sandbox gets throttled. Each change also stops the world, and Go never frees the Ps and threads it creates. The GOMAXPROCS raise dates from when the reader used 128 workers but was (accidentally?) kept when the reader went down to 12.

gVisor could drop the raise for parallel GoQueues and keep the +1 P of NewSerialGoQueue (the checkpoint writer's single worker), since removing that one gave mixed checkpoint results under fractional quotas. A side benefit: today, if the network links are created while the raise is still active (seen in large-memory restores), the FIFO qdisc dispatchers and fdbased processors are sized from the raised GOMAXPROCS for the sandbox's lifetime (14 instead of 2 at 0.25 CPU). Without the raise, they would no longer be oversized.

Performance impact

  • Restore under a tight CPU quota: 8-20% faster and 8-16% less CPU (e.g. 1 CPU with 512 MiB background restore: 823 → 663 ms; 0.25 CPU with 512 MiB: 2.10 → 1.93 s).
  • Restored Sentry: up to 7% (0.4-0.8 MiB) less anonymous memory and 1-7 fewer threads.
  • Under unlimited CPU and a small image: no change in restore time or CPU. Checkpoint unchanged everywhere (the writer keeps its +1 P).
  • //test/benchmarks/base:startup_test: RestoreNginx -2.2%, everything else unchanged.

Beat the autoresearch

The following benchmark results were benchmarked using this patch: master...EtiennePerot:gvisor:autoresearch/aio-temp-maxprocs

Add value by beating these benchmark numbers, or reducing any regressions they cause, or both
goos: linux
goarch: amd64
cpu: INTEL(R) XEON(R) PLATINUM 8581C CPU @ 2.30GHz
pkg: gvisor.dev/gvisor/test/benchmarks/base
                   │   before    │               after                │
                   │   sec/op    │   sec/op     vs base               │
StartupEmpty-16      185.2m ± 1%   185.4m ± 1%       ~ (p=0.539 n=16)
StartupNginx-16      499.3m ± 2%   497.7m ± 2%       ~ (p=0.590 n=16)
StartupNode-16       630.1m ± 1%   631.2m ± 1%       ~ (p=0.669 n=16)
CheckpointEmpty-16   62.07m ± 3%   62.17m ± 2%       ~ (p=0.616 n=16)
RestoreEmpty-16      190.3m ± 2%   189.7m ± 2%       ~ (p=0.752 n=16)
CheckpointNginx-16   97.28m ± 3%   98.13m ± 2%       ~ (p=0.539 n=16)
RestoreNginx-16      244.7m ± 2%   239.3m ± 1%  -2.21% (p=0.004 n=16)
geomean              207.2m        206.7m       -0.23%

pkg: runsc create/checkpoint/restore harness (c4-standard-16, COS 129)
                                            │    before     │                after                 │
                                            │    sec/op     │    sec/op     vs base                │
Restore/cpuquota=none/app=small                39.16m ±  3%   38.81m ±  2%        ~ (p=0.481 n=10)
Checkpoint/cpuquota=none/app=small             18.42m ±  4%   17.90m ±  2%        ~ (p=0.143 n=10)
Restore/cpuquota=0.25/app=small                166.3m ± 29%   156.8m ± 36%        ~ (p=0.481 n=10)
Checkpoint/cpuquota=0.25/app=small             18.60m ± 70%   18.42m ± 22%        ~ (p=0.218 n=10)
Restore/cpuquota=1/app=128MiB                  183.4m ± 20%   147.4m ± 13%  -19.65% (p=0.009 n=10)
Checkpoint/cpuquota=1/app=128MiB               66.98m ±  6%   66.95m ±  1%        ~ (p=0.796 n=10)
Restore/cpuquota=0.5/app=32MiB                117.01m ± 51%   67.15m ± 85%        ~ (p=0.075 n=10)
Checkpoint/cpuquota=0.5/app=32MiB              22.52m ±  2%   22.43m ±  2%        ~ (p=0.912 n=10)
Restore/cpuquota=0.25/app=512MiB                2.104 ± 10%    1.934 ±  8%   -8.12% (p=0.002 n=10)
Checkpoint/cpuquota=0.25/app=512MiB             1.090 ±  1%    1.091 ±  1%        ~ (p=0.481 n=10)
Restore/cpuquota=1/app=512MiB/background       822.9m ± 10%   662.5m ± 11%  -19.49% (p=0.000 n=10)
Checkpoint/cpuquota=1/app=512MiB/background    261.5m ±  5%   265.3m ±  3%        ~ (p=0.353 n=10)
geomean                                        134.7m         122.2m         -9.30%

                                            │    before    │                after                 │
                                            │  cpu-sec/op  │  cpu-sec/op   vs base                │
Restore/cpuquota=none/app=small               67.40m ±  5%   66.55m ±  2%        ~ (p=0.383 n=10)
Checkpoint/cpuquota=none/app=small            27.35m ± 10%   27.15m ±  7%        ~ (p=0.447 n=10)
Restore/cpuquota=0.25/app=small               57.80m ±  3%   57.25m ±  2%   -0.95% (p=0.009 n=10)
Checkpoint/cpuquota=0.25/app=small            23.05m ±  2%   22.50m ±  6%        ~ (p=0.255 n=10)
Restore/cpuquota=1/app=128MiB                 244.5m ±  8%   214.5m ± 23%  -12.25% (p=0.023 n=10)
Checkpoint/cpuquota=1/app=128MiB              86.80m ±  1%   86.10m ±  2%        ~ (p=0.109 n=10)
Restore/cpuquota=0.5/app=32MiB                94.70m ±  3%   79.90m ±  6%  -15.63% (p=0.001 n=10)
Checkpoint/cpuquota=0.5/app=32MiB             38.25m ±  2%   37.95m ±  4%        ~ (p=0.869 n=10)
Restore/cpuquota=0.25/app=512MiB              543.0m ±  7%   497.5m ±  8%   -8.38% (p=0.000 n=10)
Checkpoint/cpuquota=0.25/app=512MiB           281.8m ±  1%   283.3m ±  1%        ~ (p=0.224 n=10)
Restore/cpuquota=1/app=512MiB/background      856.3m ± 10%   753.7m ± 15%  -11.98% (p=0.000 n=10)
Checkpoint/cpuquota=1/app=512MiB/background   277.0m ±  1%   277.0m ±  2%        ~ (p=0.868 n=10)
geomean                                       117.4m         111.9m         -4.72%

                                                │    before     │                after                │
                                                │       B       │      B        vs base               │
RestoredSentry/cpuquota=none/app=small            10.375Mi ± 5%   9.980Mi ± 1%  -3.80% (p=0.030 n=10)
RestoredSentry/cpuquota=0.25/app=small             9.143Mi ± 5%   8.982Mi ± 7%       ~ (p=0.184 n=10)
RestoredSentry/cpuquota=1/app=128MiB              10.025Mi ± 5%   9.594Mi ± 3%  -4.31% (p=0.003 n=10)
RestoredSentry/cpuquota=0.5/app=32MiB              9.551Mi ± 2%   9.461Mi ± 5%       ~ (p=0.529 n=10)
RestoredSentry/cpuquota=0.25/app=512MiB           10.291Mi ± 3%   9.650Mi ± 5%  -6.23% (p=0.000 n=10)
RestoredSentry/cpuquota=1/app=512MiB/background   10.289Mi ± 3%   9.537Mi ± 3%  -7.31% (p=0.000 n=10)
geomean                                            9.935Mi        9.530Mi       -4.08%

                                                │   before    │                after                │
                                                │   threads   │   threads    vs base                │
RestoredSentry/cpuquota=none/app=small            20.00 ± 20%   19.00 ± 11%        ~ (p=0.639 n=10)
RestoredSentry/cpuquota=0.25/app=small            14.00 ±  7%   12.00 ±  0%  -14.29% (p=0.000 n=10)
RestoredSentry/cpuquota=1/app=128MiB              26.00 ± 12%   19.00 ± 21%  -26.92% (p=0.000 n=10)
RestoredSentry/cpuquota=0.5/app=32MiB             18.00 ± 11%   13.00 ±  8%  -27.78% (p=0.000 n=10)
RestoredSentry/cpuquota=0.25/app=512MiB           24.00 ± 25%   22.00 ±  5%   -8.33% (p=0.000 n=10)
RestoredSentry/cpuquota=1/app=512MiB/background   27.00 ±  4%   24.00 ±  4%  -11.11% (p=0.000 n=10)
geomean                                           20.97         17.60        -16.04%
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 is the real //test/benchmarks/base:startup_test run against docker runtimes for each build, interleaved, caches dropped before each run. The second block is a harness that runs runsc create/start of an app touching app= bytes of memory (small = only the Python app) in a cgroup with the given cpu.max, then runsc checkpoint and runsc restore (with --background where noted), interleaved with a 2 s hold. Restore is the time from the restore request until the app has touched all of its memory again, cpu-sec/op is the cgroup's CPU usage (for restore, until 0.5 s after the app is ready), and the RestoredSentry rows are the Sentry's RssAnon and thread count at that point.

Activity

  1. added this to the Lightspeed milestone on Oct 21, 2026
  2. added
    area: performance
    on Oct 21, 2026
  3. EtiennePerot commented on Oct 24, 2026

    @EtiennePerot
    MemberAuthor

    Being done by @shayonj in #16252

  4. self-assigned this
    on Oct 26, 2026
  5. milantracy commented on Nov 5, 2026

    @milantracy
    Member

    🤖 This comment was written by a bot (Claude Code) acting on behalf of @milantracy, as part of a triage of old issues.

    This is implemented by commit 708536a ("Keep restore readers within the CPU budget", PR #16252), as proposed here.

    aio.NewGoQueue no longer raises GOMAXPROCS; its workers share the existing budget (pkg/aio/aio.go). The restore pages-file reader (pkg/sentry/state/stateio/fdreader.go) uses it. NewSerialGoQueue, used for the checkpoint writer, still adds one P. TestGoQueueGOMAXPROCS in pkg/aio/aio_test.go covers this.

    Closing as implemented.

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