Skip to content

fix(ci): add swap to StartWRT riscv64 builds - #4803

Merged
dr-bonez merged 1 commit into
masterfrom
ci/wrt-riscv-oom
Nov 20, 2026
Merged

dr-bonez merged 1 commit into
masterfrom
ci/wrt-riscv-oom

Conversation

@Dominion5254

Copy link
Copy Markdown
Member

StartWRT's riscv64 builds add an 8 GiB swapfile. Since 2026-11-16, Build riscv64 binary has failed intermittently on master and unrelated PRs: rustc is SIGKILLed while compiling start-core (could not compile start-core … signal: 9).

Cause

All four kills ran on AWS-hosted ubuntu-latest runners. These runners have 15.33 GiB of RAM and no swap. The Azure-hosted ones have 15.61 GiB plus a 4 GiB swapfile.

Runner (from job logs) Root, kernel Memory Builds, 2026-11-17 to 11-19 Killed
AWS /dev/mapper/cow-root, 7.0.0-1016-aws 15.33 GiB, no swap 6 3
Azure /dev/root, 7.0.0-1019-azure 15.61 GiB + 4 GiB 40 0

The fourth kill, on 2026-11-16, predates this sample and also ran on AWS.

The runner image only creates its 4 GiB swapfile through the Azure agent's config (ResourceDisk.SwapSizeMB=4096 in images/ubuntu/scripts/build/configure-environment.sh). actions/runner-images#15335 made that conditional on the agent being present, and AWS VMs don't have it.

The build peaks during a window of about five minutes. start-core is still generating code, and startwrt-core starts compiling as soon as start-core's metadata is ready. start-core's source grew 21% on 2026-11-13 (#4583, #4485), which moved that peak close to an AWS runner's limit.

Change

  • setup-build takes a swap-size input. When set, it adds and enables a swapfile of that size. It is empty by default, so no other caller changes.
  • start-wrt.yaml sets BUILD_SWAP_SIZE: 8G once and passes it to both jobs that compile the riscv64 binary: Build riscv64 binary and Build OpenWrt image (start-wrt-image rebuilds the binary through files/.staged).
  • Why 8 GiB: an AWS runner then has 23.3 GiB in total, more than the 19.6 GiB of the Azure runners that pass, with room for start-core to keep growing. Both runner types start the job with 88–91 GB of disk free.
  • The swap is used only when RAM runs out. The overflow is the compiler state of start-core that is idle during that window. start-core frees it a few minutes later, so swapped pages are mostly discarded rather than read back.

StartOS's riscv64 compile runs on the same runner class, but no large crate compiles alongside its start-core, and it has had no kills. It can use the same input if that changes.

Because setup-build is an input to the StartOS image builds, this PR also builds the StartOS image matrix.

Verification

Build measurements ran on master 926e4aa82 with CI's builder image (ghcr.io/start9labs/cargo-zigbuild@sha256:50a56623…), restricted to 4 CPUs (--cpuset-cpus=0-3) as on the runner. Memory was sampled every 2 s from the container's cgroup.

  • Uncapped, cold build: completed in 1299 s. Anonymous memory peaked at 13.2 GB. start-core's rustc reached 11.1 GB, and startwrt-core reached 3.5 GB alongside it.
  • Memory caps, rebuilding start-core and startwrt-core:
Container limit Result
12 GiB, no swap start-core SIGKILLed, the same failure as CI
12 GiB + 8 GiB swap Completed in 13m 02s; 1.5 GB swapped
14 GiB, no swap Completed in 13m 43s

The 12 GiB cap was chosen below the measured peak to force an overflow. It shows that swap absorbs one without slowing the build. It does not measure how far short an AWS runner falls.

  • Swap step on the AWS root's storage stack. Public job output from other projects shows AWS runners mount / as ext4 on a device-mapper snapshot over NVMe, with discard,journal_async_commit,nobarrier,data=writeback,commit=30. I replicated that: ext4 with those options on a non-persistent dm-snapshot over direct-I/O loop devices.
    • The step's commands (fallocate, mkswap, swapon) activated the swapfile.
    • A process holding 120 MiB under a 64 MiB memory limit wrote 195 MB through the snapshot to the swapfile and completed.
    • Buffered loop devices are not a valid stand-in: their writeback is charged to the limited cgroup, and the process is OOM-killed even without the snapshot.
  • Checks: Prettier, actionlint 1.7.7 on start-wrt.yaml, shellcheck on the step's script, and check-pr-retarget-workflows.py pass on a3a0a0547, which is based on 926e4aa82.

This PR's own CI will land on AWS or Azure at random. On an AWS runner, swapon --show in the Add swap step lists /swapfile-build as the only swap.

Since 2026-11-16 the riscv64 build has been SIGKILLed while compiling
start-core, on master and on unrelated PRs. Every kill ran on an
AWS-hosted ubuntu-latest runner: 15.33 GiB of RAM and no swap, since
the runner image only creates its 4 GiB swapfile through the Azure
agent. Azure runners (15.61 GiB + 4 GiB swap) have not failed.

The build peaks at about 13.2 GB of anonymous memory while start-core
is still generating code and startwrt-core has already started. On an
AWS runner that leaves little or no headroom.

setup-build gains a swap-size input. start-wrt.yaml passes 8G to both
jobs that compile the binary, including the OpenWrt image job, whose
start-wrt-image target rebuilds it.
@Dominion5254 Dominion5254 added the repo Repository maintenance label Nov 19, 2026

@helix-white helix-white left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved. No correctness findings in a3a0a0547; it merges cleanly into current master.

Both StartWRT jobs that compile the riscv64 binary now request an additional 8 GiB of swap through the existing shared setup action. This includes the OpenWrt image job's binary-staging dependency. Existing swap is retained, and callers that omit the input remain unchanged. The input reaches the shell through a quoted environment variable, and swap-setup failures fail the job.

The tradeoff is 8 GiB of runner disk per opted-in job, including runners that already have swap, to absorb transient compiler memory peaks without reducing compilation parallelism. The size is chosen headroom, not a measured minimum; the forced-pressure experiment used about 1.5 GB of swap.

This is not evidence of a RISC-V-specific memory requirement. StartWRT's shipping build only targets riscv64, so there is no equivalent x86/ARM StartWRT comparison here. It imports the full start-core crate, including OS-only modules, then compiles a substantial router crate alongside start-core's unfinished code generation. The author measured compiler-process peaks of 11.1 GB and 3.5 GB respectively, with a combined anonymous-memory peak of 13.2 GB. The other product crates are thin wrappers, so they do not add the same second large compilation. Earlier separate profiling found roughly 21 million LLVM IR lines for start-core and substantial RPC-toolkit generic specialization; that establishes a large compiler workload, not a per-allocation explanation of this PR's memory peak. Swap mitigates that footprint without reducing it. A matched cross-target compiler profile would be needed to attribute any excess specifically to the RISC-V backend.

Implementation diff: +19 / −0 lines in 2 files (excludes lockfiles, tests, docs, release notes, and changelog).

Verification: the author reports reproducing the SIGKILL with a 12 GiB memory cap and no swap, completing with that cap plus 8 GiB swap, and successfully exercising swap on an AWS-like ext4/device-mapper storage stack. Reported Prettier, actionlint, shellcheck, and workflow-retarget checks pass. I reviewed the code and build callers without running builds or tests. All current non-skipped CI checks now pass, including the riscv64 build, product builds, builder verification, automated checks, and StartOS image matrix. The full OpenWrt image job is gated off on this PR.

Helix-Harness: pi
Helix-Model: openai-codex/gpt-6.1-sol

@helix-white

Copy link
Copy Markdown
Member

An alternative raised in discussion with @dr-bonez: build start-core to completion first, then build StartWRT using that completed artifact, instead of adding swap.

This would remove the overlap between the two large compiler processes while retaining normal dependency parallelism within each stage, unlike a global --jobs 1 limit.

The important constraint is artifact reuse: both invocations must use the same K1 target, profile, compiler flags, and unified dependency features. A standalone cargo zigbuild -p start-core can resolve a narrower feature graph and cause Cargo to rebuild it during the StartWRT stage, restoring the overlap. The stages should share their configuration rather than maintain independent copies of the flags or feature list.

This is an alternative to measure, not a demonstrated replacement yet. The useful comparison is peak memory and elapsed time without swap, with confirmation that the second stage reuses rather than recompiles start-core. It would still retain start-core's own measured roughly 11 GB compiler footprint.

@Dominion5254

Copy link
Copy Markdown
Member Author

I checked the two-stage proposal against build-rust.sh on master e8c464823. The check used cargo tree, which resolves dependencies without compiling anything.

The two stages build different start-core artifacts. For riscv64gc-unknown-linux-musl, -p start-core on its own resolves 8 packages in its dependency tree with fewer features than the StartWRT manifest does:

Package Extra features in the StartWRT build
axum 0.8.9 multipart
tower-http 0.6.11 set-header
strum 0.27.2 derive
rustls 0.23.46 default, prefer-post-quantum
x25519-dalek 2.0.1 default
sha2 0.9.9 default
spin 0.9.9 mutex, spin_mutex
syn 1.0.109 (host) visit-mut

Each difference changes that dependency's metadata hash, and with it start-core's. Stage 2 would compile a second start-core alongside startwrt-core, so the overlap returns after a second full compile. start-core's own features already match: StartWRT uses its defaults, and build-rust.sh passes no --features.

Sharing configuration can't close the gap. build-rust.sh already passes the same flags to both stages; the difference comes from which package is selected. --features dep/feat reaches only direct dependencies, and spin, sha2 0.9 and syn 1 are transitive. Copying the features into start-core's manifest would be the independent copy, and it would change StartOS: start-os and start-cli resolve rustls without prefer-post-quantum. Cargo no longer offers a stable switch to turn off pipelining; cargo 1.94 has no build.pipelining key. A working variant would need a permanent check that stage 2 reports start-core as fresh. Without one, the next dependency feature added on the StartWRT side would quietly bring back the double compile.

Headroom. Removing the overlap saves about 2 GB in the local measurement: 13.2 GB combined drops to the 11.1 GB of start-core alone. That 13.2 GB peak already fits under an AWS runner's 15.33 GiB on paper, yet half of those builds are killed, so the runner's own memory use isn't in these numbers. start-core's source grew 21% on 2026-11-13 (#4583, #4485). This PR's swap adds 8 GiB.

Build time. On 4 cores, startwrt-core's single-threaded front end would no longer run alongside start-core's code generation. That cost hasn't been measured. The staging would live in build-rust.sh, so local builds and deploys would pay it too.

Once the two feature graphs agree, staging could be added alongside swap, but it doesn't replace it. This PR's swap remains the fix for the AWS kills.

@helix-white helix-white left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved on re-review. The head remains a3a0a0547, unchanged from my previous review, and merges cleanly into current master.

Both StartWRT jobs that compile the riscv64 binary add 8 GiB of swap through the shared setup action. Existing swap is retained; other callers keep the empty default and remain unchanged. Setup errors fail the job. This adds runner capacity for overlapping compilation of the large start-core and router crates rather than reducing their compiler footprint. The disk cost is 8 GiB per opted-in job, including runners that already have swap; that size is chosen headroom, not a measured minimum.

The two-stage alternative raised with @dr-bonez is not a drop-in replacement. The author reports that a standalone start-core selection and the StartWRT selection resolve eight shared dependencies with different features, including transitive dependencies. Matching compiler flags alone therefore would not provide reusable artifacts: the second invocation would rebuild start-core. I do not request a manually duplicated feature list or a change to other products' feature selection to make staging work. A correctly matched staged build remains possible in principle, but neither its memory sufficiency without swap nor its elapsed-time cost has been measured; the feature-graph result does not establish that such a build could never replace swap.

Implementation diff: +19 / −0 lines in 2 files (excludes lockfiles, tests, docs, release notes, and changelog).

Verification evidence: all current non-skipped CI checks pass, including the StartWRT binary, builder verification, automated checks, product builds, and StartOS image matrix. The author also reports that a 12 GiB memory cap without swap reproduces the SIGKILL, while that cap plus 8 GiB swap completes using about 1.5 GB of swap, and that the swap commands work on an AWS-like storage stack. The full OpenWrt image job is gated off on this PR. I reviewed code and recorded evidence without running builds or tests.

Helix-Harness: pi
Helix-Model: openai-codex/gpt-6.1-sol

@helix-white

Copy link
Copy Markdown
Member

Thanks for checking the dependency graphs. That makes the artifact-reuse caveat concrete: sharing target/profile/compiler flags is insufficient, and the naïve two-command prebuild would compile start-core twice. I would not duplicate transitive feature lists or alter StartOS's feature selection to force reuse.

One distinction: this rules out that naïve implementation, not a correctly matched staged build in principle. Whether the latter could avoid AWS OOMs without swap, and its build-time cost, remain unmeasured.

I have re-approved the unchanged head and included this assessment in the approval brief. I am not requesting staging as a condition of this swap fix; it remains an optimization to evaluate separately if pursued.

@dr-bonez
dr-bonez merged commit 00a168b into master Nov 20, 2026
53 checks passed
@dr-bonez
dr-bonez deleted the ci/wrt-riscv-oom branch November 20, 2026 02:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

repo Repository maintenance

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants