Skip to content

post: fstrim the buildkit sticky disk before unmount at commit (main) - #147

Merged
magma-beef merged 1 commit into
mainfrom
devin/1793898782-v1-buildkit-fstrim
Nov 5, 2026
Merged

magma-beef merged 1 commit into
mainfrom
devin/1793898782-v1-buildkit-fstrim

Conversation

@magma-beef

@magma-beef magma-beef commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Port of #143 (release/v2) to the v1 line: the post step runs fstrim on the buildkit sticky disk before unmounting and committing it, so freed blocks are discarded from the backing image.

  • The agent sends the trim budget in GetStickyDiskResponse.fstrim_timeout_secs and the minimum free extent in fstrim_min_extent_bytes (bumped @buf/blacksmith_vm-agent.bufbuild_es); setup stores both in action state. A 0/absent budget disables the trim; a 0/absent minimum keeps fstrim's default.
  • Post trims only when the budget is positive and the run is still on track to commit (expose id, integrity check passed, no early deny, no SIGKILL, no failed previous steps), after buildkitd shutdown and sync, before the usage sample and umount.
  • Best-effort timeout <budget> sudo fstrim -v [-m <bytes>]: a missing binary, unsupported discard, or timeout is logged and never fails the step. v1 has no DockerJobLifecycle report, so the result is log-only.

Prod impact: none at merge. The trim runs only when the agent sends a positive fstrim_timeout_secs, and v1 users pick it up with the next v1 release/tag.

Start here: src/main.ts (post step, trimFilesystem), then src/setup_builder.ts (parseFstrimTimeoutSecs, parseFstrimMinExtentBytes, fstrimFailureOutcome) and src/state-helper.ts. dist/ is regenerated.

Checks: pnpm lint, pnpm typecheck, pnpm test, pnpm build.

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


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


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


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

Devin Review

Pruned layers keep their RBD extents allocated on the backing store until
the guest discards them. Run a best-effort fstrim on /var/lib/buildkit
before unmount, only when the run is still on track to commit (integrity
check passed, no early deny, no SIGKILL, no failed steps) and only when
the host enabled it: the VM agent returns
GetStickyDiskResponse.fstrim_timeout_secs, saved in action state at mount
time; 0 means no trim. A positive fstrim_min_extent_bytes becomes
`fstrim -m`. Any failure or timeout only logs.

Port of #143 (release/v2) to the v1 line; v1 has no DockerJobLifecycle
report, so the trim result is logged only.

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@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

@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

@devin-ai-integration
devin-ai-integration Bot marked this pull request as ready for review November 5, 2026 17:22
@blacksmith-staging

blacksmith-staging Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

Matches Post step trims the buildkit disk before unmount

After the PR the post step runs fstrim between the integrity check and the usage sample/umount, and the freed 512 MiB is released from the backing image; before, it stays allocated. buildkitd was not running, so its shutdown step was a no-op.

Merge-base

Before: no trim

This PR 7eafd5e8

After: fstrim before umount

Also checked · 4 match

Matches Trim skipped when disabled or not committing
Matches Trim failures never fail the step
Matches Min extent passed as fstrim -m
Matches Setup reads budget from agent response

Proof on 7eafd5e8 · mocked: Blacksmith VM agent (GetStickyDisk / Com... (unavailable), Buildkit sticky disk (/var/lib/buildkit) (unavailable) · Did Proof get it right? Yes · No

View full Proof report

@cursor

cursor Bot commented Nov 5, 2026

Copy link
Copy Markdown

This PR is too large for Bugbot to review. It changes 13 lines and 2,387,194 characters. Split the change into smaller pull requests to get a review.

@magma-beef
magma-beef merged commit 8fbda81 into main Nov 5, 2026
18 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