Skip to content

gc: prune local cache during disk pressure - #13375

Merged
sipsma merged 1 commit into
dagger:mainfrom
sipsma:prune-more-often
Jun 9, 2026
Merged

sipsma merged 1 commit into
dagger:mainfrom
sipsma:prune-more-often

Conversation

@sipsma

@sipsma sipsma commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Summary

  • add a disk-pressure monitor that triggers local cache GC while sessions are still active
  • keep pressure-triggered GC separate from session-end GC throttling, while preserving serialized pruning through the existing GC mutex
  • add unit and integration coverage for reclaiming old cache when an active session pushes the engine below min-free space

Problem

Local cache GC previously ran on startup and after client sessions ended. That left a gap for a long-running or still-active session that allocates enough data to put the engine root below its configured min-free-space target. In that state, the machine can be under disk pressure even though older cache entries are already prunable, but the engine would not attempt to prune them until the active session ended.

That means one large session could consume the remaining disk space and fail the instance, despite there being reclaimable cache from previous sessions.

Fix

This adds a lightweight disk-pressure monitor that periodically checks the engine root against the resolved local cache GC policies. If available space is below any configured min-free target, it schedules a pressure-specific throttled GC.

The actual prune still runs under the existing GC mutex, so pressure-triggered and session-end prunes cannot run concurrently. The pressure path also re-checks disk state while holding the mutex, which skips stale queued pressure prunes if another GC already relieved the condition.

Startup GC now calls the underlying GC directly so it does not consume the session-end throttle window.

Tests

  • go test ./engine/server
  • dagger --progress=plain call engine-dev test --pkg ./core/integration --run='TestLocalCache/TestLocalCacheGCRunsDuringDiskPressureWithActiveSession'

Local cache GC only ran on startup and after client sessions ended. That left a bad failure mode for long-running or still-active sessions: one session could allocate enough data to push the engine root below its configured min-free-space target, but no prune would be attempted until that session ended. If older cache entries were already prunable, the engine still would not reclaim them while the pressure was happening, so the active session could consume the remaining disk space unnecessarily.

Add a lightweight disk-pressure monitor that periodically checks the engine root against the resolved local cache GC min-free-space policies. When the machine is below any configured min-free target, schedule a pressure-specific throttled GC. The actual prune still goes through the existing GC mutex, and the pressure path re-checks disk state while holding that mutex so queued pressure GCs are skipped if another prune already relieved the condition.

Keep session-end GC on its existing one-minute throttle, but give disk-pressure GC its own shorter throttle so active sessions can trigger cleanup while preserving a bound on prune frequency. Also call startup GC directly so it does not consume the session-end throttle window.

Add unit coverage for the disk-pressure predicate and an integration test that seeds prunable cache, creates disk pressure from an active session, and verifies the old cache is reclaimed before the pressure session exits.

Signed-off-by: Erik Sipsma <[email protected]>
@sipsma sipsma added this to the v0.21.5 milestone Jun 9, 2026
@sipsma
sipsma merged commit f3184bc into dagger:main Jun 9, 2026
76 of 77 checks passed
marcosnils pushed a commit that referenced this pull request Jun 9, 2026
Local cache GC only ran on startup and after client sessions ended. That left a bad failure mode for long-running or still-active sessions: one session could allocate enough data to push the engine root below its configured min-free-space target, but no prune would be attempted until that session ended. If older cache entries were already prunable, the engine still would not reclaim them while the pressure was happening, so the active session could consume the remaining disk space unnecessarily.

Add a lightweight disk-pressure monitor that periodically checks the engine root against the resolved local cache GC min-free-space policies. When the machine is below any configured min-free target, schedule a pressure-specific throttled GC. The actual prune still goes through the existing GC mutex, and the pressure path re-checks disk state while holding that mutex so queued pressure GCs are skipped if another prune already relieved the condition.

Keep session-end GC on its existing one-minute throttle, but give disk-pressure GC its own shorter throttle so active sessions can trigger cleanup while preserving a bound on prune frequency. Also call startup GC directly so it does not consume the session-end throttle window.

Add unit coverage for the disk-pressure predicate and an integration test that seeds prunable cache, creates disk pressure from an active session, and verifies the old cache is reclaimed before the pressure session exits.

Signed-off-by: Erik Sipsma <[email protected]>
social4hyq pushed a commit to social4hyq/homebrew-core that referenced this pull request Sep 20, 2026
dagger 0.21.5

Created-by: HarmonybrewBot
Commit-by: HarmonybrewBot
Merged-by: HarmonybrewBot
Description: Created by `brew bump`

---

Created with `brew bump-formula-pr`.<details>
  <summary>release notes</summary>
  <pre>## v0.21.5 - 2026-06-10

### Added

- Added expand option to container.exists by @alexcb in dagger/dagger#13310
- Support both Dang v1 and v2, routed by module engineVersion by @vito in dagger/dagger#13388

### Changed

- Prune local cache during disk pressure by @sipsma in dagger/dagger#13375
- Persist trivial core objects by @sipsma in dagger/dagger#13387

### Fixed

- Correct namespaced type-name mangling and cross-dependency interface dispatch in Dang by @vito in dagger/dagger#13377
- Surface exec errors correctly on the Bun runtime in the TypeScript SDK by @marcosnils in dagger/dagger#13395
- Ignore host xattrs for local filesync import identity by @sipsma in dagger/dagger#13389
- Don't shallow-clone the user's repo for git telemetry labels by @marcosnils in dagger/dagger#13363
- Preserve pending lazy container parents by @sipsma in dagger/dagger#13365
- Preserve withChanges parent layers by @dagger-codex[bot] + @shykes in dagger/dagger#13342
- Treat incomplete image metadata as cache miss by @sipsma in dagger/dagger#13346
- Cache registry image metadata by @dagger-codex[bot] + @shykes in dagger/dagger#13341
- Don't require id field for interface conformance in Dang by @vito in dagger/dagger#13318
- Use module-local check names for scale-out by @dagger-codex[bot] + @tiborvass in dagger/dagger#13329
- Fix snapshot owner lease attach/remove race by @sipsma in dagger/dagger#13321
- Follow source symlinks when copying directory contents in layercopy by @marcosnils in dagger/dagger#13326

### What to do next?

- Read the [documentation](https://docs.dagger.io)
- Join our [Discord server](https://discord.gg/dagger-io)
- Follow us on [Twitter](https://twitter.com/dagger_io)

</pre>
  <p>View the full release notes at <a href="https://github.com/dagger/dagger/releases/tag/v0.21.5">https://github.com/dagger/dagger/releases/tag/v0.21.5</a>.</p>
</details>
<hr>

See merge request: Harmonybrew/homebrew-core!11205
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