Files
Etienne PerotandgVisor bot 0a86482f45 Shave ~150ms off gVisor startup by making host membarrier lazy + async.
Host membarrier support lookup and registation used to run as part of `init`
for the `hostmm` package. Due to `runsc` being a monolithic binary, this
executes unconditionally several times during the sandbox startup process.

This change skips this process for all `runsc` invocations that don't need
it by moving it to the Platform constructors, and makes initialization
itself async because the `MEMBARRIER_CMD_PRIVATE_EXPEDITED` probe can take
tens of milliseconds by itself.

Benchmarks:

```
# Plain Docker, Systrap in a VM, running just
# `docker run --runtime=runsc --rm alpine true`:
                 │    before    │                after                │
                 │     sec      │     sec      vs base                │
DockerRunBinTrue    836.5m ± 4%   674.6m ± 4%  -19.35% (p=0.000 n=16)

# Kubernetes with containerd, measuring time-to-first-log latency
# minus Kubernetes scheduling overhead:
        │          before          │                      after                       │
        │ totalruntimeinit-min-sec │ totalruntimeinit-min-sec  vs base                │
StartUp               1083.7m ± 2%                943.9m ± 3%  -12.91% (p=0.000 n=16)

        │          before          │                      after                       │

        │          before          │                      after                       │
        │ totalruntimeinit-p50-sec │ totalruntimeinit-p50-sec  vs base                │
StartUp               1083.7m ± 2%                943.9m ± 3%  -12.91% (p=0.000 n=16)

        │          before          │                      after                       │
        │ totalruntimeinit-p95-sec │ totalruntimeinit-p95-sec  vs base                │
StartUp               1083.7m ± 2%                943.9m ± 3%  -12.91% (p=0.000 n=16)
```

PiperOrigin-RevId: 947382582
2026-07-13 19:45:54 -07:00

50 lines
1.2 KiB
Python

load("//tools:defs.bzl", "go_library")
package(
default_applicable_licenses = ["//:license"],
licenses = ["notice"],
)
go_library(
name = "ptrace",
srcs = [
"filters.go",
"ptrace.go",
"ptrace_amd64.go",
"ptrace_arm64.go",
"ptrace_arm64_unsafe.go",
"ptrace_unsafe.go",
"stub_amd64.s",
"stub_arm64.s",
"stub_unsafe.go",
"subprocess.go",
"subprocess_amd64.go",
"subprocess_arm64.go",
"subprocess_linux.go",
"subprocess_linux_unsafe.go",
"subprocess_unsafe.go",
],
visibility = ["//:sandbox"],
deps = [
"//pkg/abi/linux",
"//pkg/bpf",
"//pkg/context",
"//pkg/cpuid",
"//pkg/fd",
"//pkg/hostarch",
"//pkg/hosttid",
"//pkg/log",
"//pkg/safecopy",
"//pkg/seccomp",
"//pkg/sentry/arch",
"//pkg/sentry/arch/fpu",
"//pkg/sentry/hostmm",
"//pkg/sentry/memmap",
"//pkg/sentry/platform",
"//pkg/sentry/platform/interrupt",
"//pkg/sighandling",
"//pkg/sync",
"@org_golang_x_sys//unix:go_default_library",
],
)