Skip to content

test: bound the harness's memory footprint, and measure what an iteration actually costs - #364

Merged
scttfrdmn merged 4 commits into
mainfrom
test/193-harness-memory-footprint
Aug 5, 2026
Merged

scttfrdmn merged 4 commits into
mainfrom
test/193-harness-memory-footprint

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

Closes #193's three asks beyond the CI knob. The first one changed shape once it could be measured.

The budget asserts total allocation, not the ratio #193 proposed

That issue observed peak RSS tracking ~3.7× GOMEMLIMIT across a sweep and suggested asserting on it. The ratio is not a property of the harness:

GOMEMLIMIT=768MiB GOMEMLIMIT=384MiB apart
before #362 751 MiB 3570 MiB 4.75×
after #362 1859 MiB 1862 MiB 0.15%

A sync.Pool holding a 64 MiB buffer is cleared at every GC cycle, so a tighter limit bought more collections and therefore more total allocation. Removing that upload path removed the inversion. A number that moves 4.75× → 1.00× on a change touching no harness code describes the collector's response to a limit, and an assertion written against it would have pinned a deleted upload path's cost as the harness's expected footprint.

TestPerIterationAllocationBudget asserts per-iteration TotalAlloc instead — what actually rises when an iteration gets hungrier, and insensitive to both GOMEMLIMIT and worker count. Measured 6.3 MiB (writes and reads) and 7.1 MiB (flush/reopen pairs), under 1% apart with -race on and off. Ceiling 16 MiB: the regression worth catching is a 10× one, which is what OOMs a worker.

Measured against synthetic worst-shaped inputs, not the seed corpus. The corpus averages 0.31 MiB — 20× less — because its entries are four operations with 64-byte payloads while the decoder admits 64 operations with 4 KiB payloads and turns every flush into a real GET+PUT. A budget measured on the corpus passes forever while the shapes the fuzzer actually generates get arbitrarily more expensive.

Verified by mutation: a 1 MiB allocation per write takes both cases to ~30 MiB and fails both subtests.

Retention is bounded

The shared emulator's state manager is an in-memory map, difftest's factory mints a key per call, and Shrink calls that factory hundreds of times per counterexample — so nothing swept anything. Deleting each run's object in the cleanup the factory already returns holds heap flat across +700 iterations (29.2 MiB, delta 0.0–0.1 MiB) where its absence grows monotonically (+0.2 → +0.5 → +1.1 MiB, ~2.8 KB each). Verified in both directions.

Never the OOM cause, and the megabytes are not the point: "grows without bound, but slowly" is not a property worth having in the component every other test trusts to be inert.

The note that generalizes

internal/testaws's package doc and the fuzz target now record why a target using a real endpoint needs an explicit GOMEMLIMIT: go test -fuzz runs one worker process per CPU, each an independent runtime sizing its heap against total machine memory with no knowledge of its siblings, so four of them over-commit by 4× before any test code runs. That is why the limit is set for every fuzz target in CI rather than only the one that died — and why the failure misleads, since the kill reports as "fuzzing process hung or terminated unexpectedly", names an input, and writes it to the corpus, where it replays green.

Verification

  • go test -race ./internal/difftest/ ./internal/testaws/ — pass
  • golangci-lint run on both packages — 0 issues
  • Both behavior changes verified by mutation rather than by predicted signature

Refs #193

PutObject had two implementations. The CargoShip transporter branch already
carried three bypasses explaining what cargoships3.Archive cannot express — a
Content-Encoding, the configured encryption headers, a per-object storage
class — and #362 found the fourth, which was not bypassed but silently wrong:
Content-Type was written into Archive.Metadata, which is S3 user metadata, not
the header. Measured through the endpoint, file.txt stored as
application/octet-stream on that path and text/plain on the direct one, with
detectContentType having computed the right value one line earlier in both.

There was nothing on the other side. The transporter was reachable only below
MultipartThreshold, since PutObject returns into putObjectMultipart first and
that function never referenced a transporter — so its 64 MiB multipart
BufferProvider served an upload shape a mount cannot produce, and sync.Pool
released that buffer at every GC: 20 PUTs allocated 3.4 MiB with no GC between
them and 837 MiB with one after each, which also inverted GOMEMLIMIT.
Throughput was 35% slower at 4 KiB and a wash at 8 MiB.

So it is deleted rather than given a fourth bypass, along with
storage.s3.use_cargoship, s3.Config.EnableCargoShipOptimization,
GetTransporter, IsCargoShipEnabled, and cargoShipCanEncrypt. The config key is
removed rather than deprecated and the loader is strict, so a file still
setting it fails at startup naming the key — an operator who set it believed
their uploads took a different path, and an error is the one way that belief
gets re-examined. ConvertTierToCargoShipStorageClass stays.

upload_path_test.go now pins the boundary rather than the path: Content-Type
reaches the stored object on both sides of the threshold, the stored metadata
key set is exactly what ObjectFS wrote, and caller metadata survives. All three
fail on the old code and were verified by mutation. The first draft passed for
the wrong reason — a 1 MiB chunk size is below the AWS uploader's 5 MiB part
minimum, so every CargoShip upload failed and fell back to the path that sets
the header correctly.
#193 asked for three things beyond the CI knob that stopped the OOM. All three
are here, and the first one changed shape once it could be measured.

An allocation budget for the difftest fuzz target. The issue proposed asserting
peak RSS as a ratio of GOMEMLIMIT, on the strength of that ratio holding ~3.7x
across a sweep. It does not hold. Before #362 removed the CargoShip upload path,
300 iterations allocated 751 MiB under GOMEMLIMIT=768MiB and 3570 MiB under
384MiB -- 4.75x apart, because a sync.Pool holding a 64 MiB buffer is cleared at
every GC cycle, so a tighter limit bought more collections and therefore more
total allocation. After the removal the same measurement is 1859 vs 1862 MiB.
A number that moves 4.75x -> 1.00x on a change touching no harness code is a
property of the collector's response to a limit, not of the harness, and the
assertion would have pinned a deleted upload path's cost as the expected budget.

So the assertion is total allocation per iteration, which is what actually rises
when an iteration gets hungrier and is insensitive to both GOMEMLIMIT and the
worker count. 6.3 MiB for writes and reads, 7.1 MiB for flush/reopen pairs,
under 1% apart with -race on and off, ceiling at 16 MiB.

Measured against synthetic worst-shaped inputs, not the seed corpus, and that is
the difference between an assertion with teeth and one without: the corpus
averages 0.31 MiB, 20x less, because its entries are four operations with
64-byte payloads while the decoder admits 64 operations with 4 KiB payloads.
A budget measured on the corpus passes forever while the shapes the fuzzer
generates get arbitrarily more expensive. Verified by mutation -- a 1 MiB
allocation per write takes both cases to 30 MiB and fails them.

Bounding the shared emulator's retention. Its state manager is an in-memory map,
difftest's factory mints a key per call, and Shrink calls that factory hundreds
of times per counterexample, so nothing swept anything. Deleting each run's
object in the cleanup the factory already returns holds heap flat across 700
iterations where its absence grows ~2.8 KB each. Verified in both directions.
This was never the OOM cause; the reason to fix it is that "grows without bound,
but slowly" is not a property worth having in the component every other test
trusts to be inert.

The note that generalizes, in testaws's package doc and on the fuzz target:
go test -fuzz runs one worker process per CPU, each an independent runtime
sizing its heap against total machine memory with no knowledge of its siblings,
so four of them over-commit by 4x before any test code runs. That is why
GOMEMLIMIT is set for every fuzz target in CI and not just the one that died,
and why the failure misleads -- the kill reports as "fuzzing process hung or
terminated unexpectedly", names an input, and writes it to the corpus, where it
replays green.

Refs #193
@scttfrdmn scttfrdmn added the type: testing Test coverage, test infrastructure, or test improvements label Aug 5, 2026
@scttfrdmn scttfrdmn added priority: medium Important but not urgent area: core Core filesystem operations and POSIX compliance effort: medium Medium effort - 1-2 days labels Aug 5, 2026
"four of them jointly over-commit" reads as though the four workers
cooperate on a shared limit, which is the opposite of the point — each
sizes its heap against total machine memory precisely because it does not
know the others exist.
@scttfrdmn
scttfrdmn merged commit 7c4c069 into main Aug 5, 2026
33 checks passed
@scttfrdmn
scttfrdmn deleted the test/193-harness-memory-footprint branch August 5, 2026 22:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: core Core filesystem operations and POSIX compliance effort: medium Medium effort - 1-2 days priority: medium Important but not urgent type: testing Test coverage, test infrastructure, or test improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

test: harness memory footprint is unbounded per fuzz worker, not just in difftest

1 participant