Skip to content

git-mirror: fstrim the mirror sticky disk before unmount at commit - #63

Merged
magma-beef merged 11 commits into
mainfrom
devin/1792451273-git-mirror-fstrim
Nov 25, 2026
Merged

magma-beef merged 11 commits into
mainfrom
devin/1792451273-git-mirror-fstrim

Conversation

@magma-beef

@magma-beef magma-beef commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Summary

In git-mirror cleanup, runs fstrim on the mirror sticky disk before it is unmounted and committed, so freed blocks are discarded from the backing image, and reports the result to the agent.

  • Mount stores the agent's trim budget (GetStickyDiskResponse.fstrim_timeout_secs) and minimum extent (fstrim_min_extent_bytes) in action state; a 0/absent budget disables the trim.
  • Cleanup trims only when the budget is positive and shouldCommit holds, after sync/maintenance and before umount: asRoot('timeout', <budget>, 'fstrim', '-v', [-m <bytes>], '--', <mount>), bare in root job containers and under sudo elsewhere, so timeout can stop fstrim.
  • Best-effort: the outcome (ok / timeout / unsupported / failed, the same vocabulary as setup-docker-builder and the agent's FstrimOutcome) is logged in one line and never fails the step.
  • The result is posted as a git_mirror_maintenance_run with op: fstrim (duration_ms, bytes, outcome, error_class); the agent side is fa#7761.

Start here: src/blacksmith-cache.ts (trimFilesystem, TrimResult, the trim in cleanup), src/mirror-telemetry.ts (maintenanceRunFromTrim). dist/ is regenerated.

Production behavior: unchanged until a host sends a positive budget.
Memory: no new buffers or copies.

Link to Devin session: https://app.devin.ai/sessions/92e53b7390c14f5cbff677d4c81f04ad
Open in Devin Desktop: https://app.devin.ai/desktop/session/92e53b7390c14f5cbff677d4c81f04ad?variant=devin
Requested by: @magma-beef


🟢 Devin Review found nothing to fix · View findings · Follow Devin's work

Devin Review


View full Proof
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.


View full Proof Follow the PR Trail
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need. (Staging)

@devin-ai-integration

Copy link
Copy Markdown
Contributor

I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".

  • Disable automatic comment, CI, and merge conflict monitoring

@blacksmith-staging

blacksmith-staging Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

Matches Post step trims mirror disk before unmount

After 400 MB was freed on the mirror disk, the post step ran fstrim (ok) between sync and umount and the backing image dropped to 16MB; before the PR it stayed at 416MB.

Merge-base

Backing image

This PR cf94d646

Backing image

Also checked · 5 match

Matches Agent budget and -m reach the post step
Matches Trim runs as root without sudo
Matches Trim outcome, duration, bytes reported to agent
Matches No trim when disabled or not committing
Matches Timeout or unsupported never fails the step

Proof on cf94d646 · mocked: Blacksmith VM agent (StickyDiskService g... (The VM agent only runs on Blacksmith hosts; a local gRPC/HTTP stub answers Up, G...), Mirror sticky disk (Ceph RBD) (No RBD in the sandbox; a sparse file on a loop device (which honors discard by p...) · Did Proof get it right? Yes · No

View full Proof report · React 👎 or comment @codesmith dismiss this proof to dismiss

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Devin Review

@piob-io

piob-io commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

This branch predates #69, which stopped calling sudo directly so the mirror works in root job containers without sudo. The new fstrim call still uses bare sudo, so after a rebase it is the one command that fails there and the trim never runs.

@piob-io

piob-io commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

The trim result only goes to a log line. Outcome, duration and bytes trimmed are not reported anywhere we can query, so once the host enables this we cannot tell fleet-wide how often it times out or is unsupported, or how much time it adds to the post step. setup-docker-builder v2 reports these three to the agent; the mirror trim should be just as visible.

magma-beef and others added 11 commits November 17, 2026 14:03
Deleted packs keep their RBD extents allocated on the backing store until
the guest discards them. Run a best-effort fstrim on the mirror mount
after sync and before unmount, only when the run will commit and only
when the host enabled it: the VM agent returns
GetStickyDiskResponse.fstrim_timeout_secs (fa live config
guest_fstrim_timeout_secs), saved in action state at mount time; 0 means
no trim. Any failure or timeout only logs.

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…oto package predates it

The bundled GetStickyDiskResponse has no fstrim_timeout_secs yet, and protobuf-es keeps fields it does not know in the message's unknown-field list (the gRPC transport is binary), so decode field 8 from there when the typed field is absent. Releases built before the field existed therefore honour the host budget once the agent sends it.

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Bump @buf/blacksmith_vm-agent.bufbuild_es to a build that includes
GetStickyDiskResponse.fstrim_timeout_secs (fa #6600) and drop the
unknown-field-8 decoding.

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…ackages

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
GetStickyDiskResponse.fstrim_min_extent_bytes (fa #6823) is saved as action
state next to the timeout budget and, when positive, becomes
`fstrim -m <bytes>` so free extents below the host's threshold are not
discarded. Zero or absent leaves fstrim at its default. Bumps the @buf
vm-agent packages to the fa main build that carries field 9 and regenerates
their licensed records.

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
An unprivileged timeout cannot signal the root-owned sudo/fstrim it
spawned, so the host budget never bounded the trim and fstrim could
outlive it and keep the mirror mount busy. sudo timeout <secs> fstrim
gives timeout the privilege to kill fstrim; exit 124 still maps to the
timeout outcome.

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Same vocabulary as setup-docker-builder and the agent's FstrimOutcome, so
logs across the actions read alike and a discard that the host has not
negotiated yet is not mixed in with real failures.

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Job containers run as root without sudo, so the trim goes through asRoot
like every other root command in the mirror lifecycle; timeout keeps
running with fstrim's privilege so it can stop it. trimFilesystem now
returns outcome, duration and the byte count fstrim -v reported, carried
in CleanupResult.fstrimResult.

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…ce run

op fstrim, duration_ms the trim's wall time, bytes the count discarded,
and the fstrim outcome folded into the maintenance vocabulary with
error_class keeping unsupported apart from a real failure, so the trim's
cost and outcome distribution are queryable next to refresh/gc.

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@devin-ai-integration
devin-ai-integration Bot force-pushed the devin/1792451273-git-mirror-fstrim branch from 5580ba7 to cf94d64 Compare November 17, 2026 14:11
@devin-ai-integration

Copy link
Copy Markdown
Contributor

Rebased onto main (past #69) and the trim now goes through asRoot like the other root commands (3151574): asRoot('timeout', budget, 'fstrim', '-v', [-m N], '--', mountPoint), so in a root job container it runs bare and elsewhere under sudo, with timeout keeping fstrim's privilege so it can stop it. __test__/mirror-fstrim.test.ts pins the argv.

@devin-ai-integration

Copy link
Copy Markdown
Contributor

Now reported (cf94d64) over the channel the mirror already has: a git_mirror_maintenance_run with op: fstrim, duration_ms the trim's wall time, bytes the count fstrim -v reported discarded, and the outcome folded into the maintenance vocabulary — ok → success, timeout → timeout, unsupported → failure + error_class: unsupported, failed → failure + error_class: error — so unsupported stays separable in git_mirror_maintenance_runs / the daily error_class_map, and the admin git-mirror maintenance list shows fstrim as its own op row. The agent side (accepting fstrim as a maintenance op; it is a closed enum, so until then the row is dropped at ingest) is in fa #7761, together with the stickydisk MountReport fields.

I went with the maintenance table rather than a new payload type because the row already has exactly these three fields and the daily rollup/admin tab read it per op; if you would rather see the ok/timeout/unsupported/failed words verbatim as in the other two actions, that needs its own column or table — say so and I will switch.

@blacksmith-sh

blacksmith-sh Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Matches Post step trims mirror disk before unmount

With a 30s budget and a committing job, the post step ran fstrim after sync and before umount and the backing image shrank from 533M to 33M; before the PR it stayed at 533M.

Merge-base

Backing image size

This PR cf94d646

Backing image size

Also checked · 4 match

Matches Trim works as root without sudo
Matches Trim outcome reported to the agent
Matches Timeout or unsupported never fails the step
Matches No trim when disabled or not committing

Proof on cf94d646 · mocked: Blacksmith VM agent (the agent only runs on Blacksmith hosts; a local stub answers CommitStickyDisk o...), Mirror sticky disk (Ceph RBD sticky disks exist only on Blacksmith hosts; a sparse ext4 image on a l...) · Did Proof get it right? Yes · No

View full Proof report · React 👎 or comment @codesmith dismiss this proof to dismiss

@piob-io

piob-io commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

Thank you!

@magma-beef
magma-beef merged commit b917122 into main Nov 25, 2026
19 checks passed
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.

2 participants