Skip to content

ci: sample macOS job memory by class; bound update hash memory - #1829

Merged
davidtai merged 3 commits into
devfrom
ci/true-memory
Nov 5, 2026
Merged

davidtai merged 3 commits into
devfrom
ci/true-memory

Conversation

@davidtai

@davidtai davidtai commented Nov 5, 2026 •

Copy link
Copy Markdown
Collaborator

Why

#1821 sizes the macOS lanes from the sampler's "peak memory in use". That figure (active + wired + compressed pages) counts active file cache as app memory and misses inactive anonymous pages. Its largest-RSS figure misses Metal memory. This PR records the right classes, so the sizes can come from data. It also fixes the 15 GiB process in provider shard 1.

The 15 GiB process in provider shard 1 (run 42041608780)

  • The samples (resource-samples-test-provider-0) put the jump in RSS between 14:21:10 and 14:21:20 UTC: 0.9 GiB to 14.5 GiB. It stays until 14:23:41. A per-test timeline from the log puts it in selection 2-of-6, Swift Testing, Update rollback end to end (UpdateRollbackEndToEndTests), from offset 40.9 s to 75.7 s = 14:20:47 to 14:21:22. The timeline is serial under --no-parallel and anchored on the run's XCTest end and printed end. Selection 1 ended at 14:23:06 while the 15 GiB stayed, and the RSS fell when selection 2 ended (14:23:42).
  • Cause: UpdateAtomicFilesystem.sha256(file:) and treeHash(root:) read 1 MiB chunks with FileHandle.read(upToCount:). On Darwin that call returns autoreleased storage. On a Swift concurrency thread no autorelease pool drains between jobs, so every hashed byte stays resident. The test installs and rolls back two bundles of the debug, coverage-built darkbloom CLI. Every manifest and verify step hashes the CLI twice (bundle tree and binary), about a dozen reads in total.
  • Fix: each chunk is read in its own autorelease pool, as WeightHasher already does (fix(provider): bound weight hash memory growth #358). This changes production code, but only in memory use: the bytes hashed and the digests are the same. In production the provider's updater hashes the release bundle the same way, so an update keeps several times the bundle size resident while a model may be loaded. The test is unchanged; it needs the real built CLI.
  • Regression test: UpdateFileHashMemoryTests hashes a sparse 256 MiB file with both functions. It checks the digests against known values and that the process footprint grows less than 64 MiB. Before the fix it grew by about 512 MiB.
  • Same pattern, not changed here: ManifestBuilder.hashOne (model weights, darkbloom-publish, 64 KiB chunks in an async build), SpecDecStore.digestRegularFile (drafter weights, 1 MiB), BinaryHasher.sha256Digest(of:) and the metallib copy loop. Each keeps the whole file resident when it runs in async code.

Sampler (report-only, never fails a job)

  • Memory classes from vm_stat: app (anonymous less purgeable), wired (holds resident GPU memory), file cache (file-backed + purgeable), compressed, used = app + wired + compressed (Activity Monitor's sum). Swap in use from sysctl vm.swapusage.
  • Per-process physical footprint from proc_pid_rusage (ri_phys_footprint, which includes IOAccelerator/Metal memory). This is the counter that footprint and Activity Monitor print, read in every sample. It also keeps ri_lifetime_max_phys_footprint, so a peak between samples counts. The report shows the top 3 processes by peak, with their names, and the sum.
  • /usr/bin/footprint, where present, writes a category breakdown (IOAccelerator and others) at a new 2 GiB high, at most twice a job. The report says if the tool is present.
  • Busy vCPUs now come from host CPU ticks (host_statistics), so short compile processes count. It falls back to the ps sum.
  • run-provider-tests.sh and cluster-test-plan.py mark each selection's start and end with its PID. The report names the selection of each large process and the selections that ran at the peak.
  • summary.json in each resource-samples-* artifact. The sampled time is scaled to 4 and 8 vCPUs: each interval is stretched by busy / vCPUs where busy is more than the vCPUs.

Before / After

flowchart LR
  subgraph Before
    A1[vm_stat active+wired+compressed] --> R1[peak memory in use]
    B1[ps RSS] --> R2[largest RSS: misses Metal]
    C1[ps %cpu averages] --> R3[busy vCPUs]
  end
  subgraph After
    A2[vm_stat classes] --> S2[used / app / wired / file cache / compressed / swap]
    B2[proc_pid_rusage footprint + lifetime peak] --> T2[top 3 processes + sum]
    M2[selection marks from the runners] --> T2
    F2[/usr/bin/footprint at highs/] --> T2
    C2[host CPU ticks] --> U2[busy vCPUs + time at 4 and 8 vCPUs]
    S2 & T2 & U2 --> J2[report + summary.json]
  end
Loading
flowchart LR
  subgraph "Before: update hash"
    H1[read 1 MiB chunk] --> P1[autoreleased Data kept on the thread] --> H1
  end
  subgraph "After: update hash"
    H2[read 1 MiB chunk in autoreleasepool] --> P2[chunk released after hashing] --> H2
  end
Loading

Hooked up

  • start exports CI_RESOURCE_SAMPLES through GITHUB_ENV. The workflow's sampler steps are unchanged.
  • Marks: run-provider-tests.sh (each selection, isolated filters, exclusive GPU test) and cluster-test-plan.py execute() (Popen keeps the subprocess.run kill-on-interrupt behaviour).
  • The size table in provider-plan.yml is not touched.

Results (run 42105290034; attempt 1 on Darkbloom/Blacksmith, attempt 2 on Blacksmith 12x48)

Peak GiB per class (worst attempt). Used = app + wired + compressed. The file cache is reclaimable. Busy vCPUs come from host CPU ticks. Pressure stayed normal (1) and swap at 0 in every job.

Job Used App Wired File cache Largest process footprint (selection) Busy mean / p95 Smallest fit
Provider Unit Tests 1 10.79 8.96 2.09 22.31 2.22 helper (3-of-6); was 14.96 RSS 1.62 / 3.28 4x16
Provider Unit Tests 2 16.17 (1 sample; about 9 sustained) 14.45 1.77 18.27 1.57 helper (6-of-6) 1.62 / 3.16 4x24
Cluster Runtime 1 11.75 10.05 2.75 11.05 4.61 helper (base) 1.25 / 2.23 4x16
Cluster Runtime 2 29.29 (24.76 on a 32 GiB sandbox) 21.09 11.54 11.33 18.36 helper (glm53-paged-kv) 2.17 / 3.73 12x32 offered (tight); 4x40 unsigned
Cluster Runtime 3 14.57 12.90 7.60 10.94 7.47 helper (base-gemma) 1.27 / 1.98 4x24
Cluster Focused 1 8.06 6.51 1.78 13.66 0.69 check 1.35 / 3.58 4x16 (4x12 unsigned)
Cluster Focused 2 7.61 6.13 1.97 12.64 0.36 0.86 / 3.82 4x16 (4x12 unsigned)
Cluster GPU 1 17.37 15.09 5.36 11.21 9.28 helper (qwen-tp-real-geometry-gpu), IOAccelerator 1.07 / 1.44 4x24
Cluster GPU 2 41.99 34.98 13.19 11.01 34.26 helper (paged-verify-bench), IOAccelerator 1.41 / 3.19 none offered: 4x48 unsigned (12x32 is too small)
Cluster Release Build Checks 9.65 7.99 1.73 10.05 2.38 swift-frontend 2.40 / 3.79 4x16
Build cluster (warm) 10.91 8.97 1.95 13.70 0.93 dsymutil 3.23 / 12.00 8x16
Build provider (warm) 17.50 15.55 2.05 19.86 2.11 swift-frontend 5.97 / 12.00 12x32 or 8x24 unsigned

"Fit" means used × 1.25 ≤ RAM, and the job, scaled to that vCPU count, takes at most 5% longer. All test jobs scale to 4 vCPUs within 1.2%.

Build time scaled to fewer vCPUs: every sample interval inside the build step is stretched by busy / n where busy > n. Serial phases keep their time. Cold runs predate this PR, so their busy figure is the ps %cpu average.

Build Cache Wall (s) At 8 vCPUs (s) At 4 vCPUs (s)
provider cold Swift + cold metallib (run 42057277814) 745 908 1545
provider cold Swift (runs 42078464492, 42082034456) 488 / 414 585 / 506 982 / 853
provider warm, about 937 compiles (run 42103116746) 170 186 261
provider warm, this PR (attempts 1 and 2) 121 / 188 121 / 223 125 / 351
cluster cold (runs 42041608780, 42103370968) 242 / 204 266 / 215 366 / 287
cluster warm, this PR (attempts 1 and 2) 53 / 79 52 / 82 52 / 99

Validation

  • Run 42105290034 attempt 2: every job passed, including Update file hash memory and Update rollback end to end (34.8 s). Attempt 1's 7 Darkbloom-routed test jobs waited for sandbox runners. One runner lost communication (Cluster Runtime 1), and the coordinator cancelled the attempt and re-ran it. /usr/bin/footprint is present on both runner types.
  • The sampler's self-tests (scripts/test-ci-resource-sampler.py, in Check the CI plans) cover parsing, attribution, capture limits, summary and marks. No local builds or tests.
  • Refactor pass: not run. The agent that wrote this PR cannot start a refactor subagent, so this gate is still open.

🤖 Generated with Claude Code

The resource sampler's "memory in use" (active + wired + compressed) mixed
file cache into app memory and missed inactive anonymous pages, and its
largest-RSS figure missed Metal memory. Sizes were picked from it.

Sampler (report-only, never fails a job):
- vm_stat classes: app (anonymous less purgeable), wired, file cache,
  compressed, used = app + wired + compressed; swap in use.
- Per-process physical footprint from proc_pid_rusage (includes
  IOAccelerator memory) with lifetime peaks; the top three, their sum.
- /usr/bin/footprint breakdown at new 2 GiB highs, at most twice a job.
- Busy vCPUs from host CPU ticks instead of the ps %cpu averages.
- Selection marks from run-provider-tests.sh and cluster-test-plan.py,
  so each large process and the peak name their test selection.
- summary.json, and the sampled time scaled to 4 and 8 vCPUs.

Provider (production change, memory only): UpdateAtomicFilesystem's
sha256(file:) and treeHash(root:) read each 1 MiB chunk in its own
autorelease pool, as WeightHasher does. On a Swift concurrency thread
the autoreleased chunks otherwise stay resident: "Update rollback end to
end" hashes the debug CLI many times and its test process held 15 GiB
(provider shard 1, run 42041608780). The hashes are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@vercel

vercel Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
d-inference Error Error Nov 5, 2026 11:04pm UTC
d-inference-console-ui-dev Error Error Nov 5, 2026 11:04pm UTC
d-inference-landing Ready Ready Preview Nov 5, 2026 11:04pm UTC
darkbloom-status Ready Ready Preview Nov 5, 2026 11:04pm UTC
eigen-homepages-darkbloom Ready Ready Preview Nov 5, 2026 11:04pm UTC

Request Review

Run 42105290034 showed the GPU lane's Metal buffers as app (anonymous)
memory: 35 GiB app against 12 GiB wired, with a 34 GiB IOAccelerator
footprint. The sampler's text, the build doc and the changelog said
wired held the GPU memory.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- The sampler parses the marks file in one place (read_marks); a row with a
  bad time or pid is skipped by both readers, so a torn row can no longer
  stop the report. The capture threshold is named captured_bytes.
- run-provider-tests.sh names the exclusive GPU filter once.
- UpdateAtomicFilesystem calls autoreleasepool directly, as the rest of
  ProviderCore does; the hashed bytes and digests are unchanged.
- build.md gives the measured per-class peaks (runs 42105290034 and
  42123224100) in place of the old 21.5 / 18.8 / 32.8 GiB figures, and says
  when a footprint capture runs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch had an error being deployed

2 failed and 3 active deployments
Preview – eigen-homepages-darkbloom — 9edfaeb4 Deployed Nov 5, 2026 by vercel[bot]
Preview – d-inference-landing — 9edfaeb4 Deployed Nov 5, 2026 by vercel[bot]
Preview – d-inference-console-ui-dev — 9edfaeb4 Deployed Nov 5, 2026 by vercel[bot]
Preview – darkbloom-status — 9edfaeb4 Deployed Nov 5, 2026 by vercel[bot]
Preview – d-inference — 9edfaeb4 Deployed Nov 5, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant