Skip to content

[Request]: Clean container root fs and rw-mounted volumes periodically. #2206

Description

@jglogan

Feature or enhancement request details

Once #1949 is merged, we can implement periodic clean on containers so that filesystem blocks deallocated in Linux filesystems can be freed on the host. Today, the disk image files grow in size (number of allocated host blocks as shown by ls -s) but never decrease.

For short-running containers this is less of a problem, but longer running containers that frequently create and delete files (such as the builder) can consume quite a bit of host capacity.

A simple implementation is all that is necessary for now, something like running clean from a task in container-runtime-linux every hour, serialized such that only one of a scheduled clean and a user's container clean run at once.

@recrack if you want this one, please let us know in the comments and I'll assign you, since we took apple/containerization#838 and #1949 over your fixes.

Code of Conduct

  • I agree to follow this project's Code of Conduct

Activity

  1. added this to the 26w36 milestone on Aug 28, 2026
  2. added theissue type on Aug 28, 2026
  3. added
    facet/storage
    on Aug 28, 2026
  4. amanmaurya92 commented on Sep 3, 2026

    @amanmaurya92

    @jglogan can i work on this since #1949 is merged?

  5. removed this from the 26w36 milestone on Oct 5, 2026
  6. jglogan commented on Oct 9, 2026

    @jglogan
    ContributorAuthor

    @amanmaurya92 sure! I've assigned you. Sorry for the delay, I was gone for most of September.

    Before you do a PR, could you write up a brief (if you use AI, tell it to keep it concise :D) proposal here for what you plan to do and what the change would generally look like?

    I don't want to be prescriptive about it. The only thing I'd suggest is that we keep the initial feature minimal - we probably don't need a lot of customizable options initially.

  7. amanmaurya92 commented on Oct 11, 2026

    @amanmaurya92

    Hi @jglogan, thanks! Here is a concise proposal for what the initial change would look like (formatted using gemini since it is a new feature)

    1. Extract Clean Logic:
      Refactor the filesystem trim logic from RuntimeService.clean into an internal helper method (performClean()) targeting / (if not read-only) and any non-read-only block mounts.

    2. Periodic Task in RuntimeService:
      In RuntimeService.startProcess, once the container enters .running, spawn a background Task that sleeps on a 1-hour interval and runs performClean().
      Cancel the task cleanly during container teardown in cleanUpContainer.

    3. Serialization & Fault Tolerance:
      Guard performClean() with a lock or active-cleaning state flag so an incoming manual container clean XPC call and the scheduled background task cannot run concurrently.
      Catch and log errors in the background loop so filesystem trim errors never disrupt the container workload.

    Does this plan look good to you, or would you prefer any adjustments before I start on the PR?

  8. added 3 commits that reference this issue on Oct 15, 2026
    facb733
    5abc2e7
    b17b33a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

facet/storage

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions