Skip to content

Ask for continuous discard where the runtime makes an ext4 - #870

Open
MayCXC wants to merge 1 commit into
apple:mainfrom
MayCXC:online-discard
Open

Ask for continuous discard where the runtime makes an ext4#870
MayCXC wants to merge 1 commit into
apple:mainfrom
MayCXC:online-discard

Conversation

@MayCXC

@MayCXC MayCXC commented Aug 27, 2026

Copy link
Copy Markdown

Summary

A container's root filesystem and writable layer are sparse files, and the guest never returns the blocks it frees: deleting inside the guest frees guest blocks, the host file keeps every block it has ever touched, so its real size is the high water mark of everything ever written rather than what is live.

The filesystem hands freed blocks back the moment they are freed when its mount asks for discard, and the runtime forwards those discards to hole punches in the backing file. The ask belongs to the file: every ext4 the runtime creates is such a sparse file, so its mount options carry discard from the moment the mount exists, and every place the file is later mounted, container or pod, lower layer or writable, inherits the ask with the rest of the options. A read-only mount parses the option and leaves it idle.

Motivation and Context

This is the continuous counterpart to an explicit trim: rather than reclaiming in a sweep after the fact, the filesystem returns each block as it is freed, and the backing file stops growing to its high water mark.

Putting the option on the mount where the file is created, rather than at each place it is mounted, means a caller cannot forget it, and the two do not drift apart as more mount sites appear.

Relationship to #859

#859 adds an explicit trim that returns blocks on demand and reports how many. The two are complementary: continuous discard keeps a live filesystem from growing, while a trim reclaims what a filesystem that has been running without it already holds. Neither depends on the other, and they touch different files.

Testing

  • swift build and make check clean.
  • swift test: 595 tests in 82 suites passed.
  • Integration: the swap and reclaim tests watch the backing file's allocated blocks while a workload fills and frees, which is where a filesystem that keeps its high water mark shows up.

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update

A container's root filesystem and writable layer are sparse files, and
the guest never returns the blocks it frees: deleting inside the guest
frees guest blocks, the host file keeps every block it has ever
touched, so its real size is the high water mark of everything ever
written rather than what is live.

The filesystem hands freed blocks back the moment they are freed when
its mount asks for discard, and the runtime forwards those discards to
hole punches in the backing file. The ask belongs to the file: every
ext4 the runtime creates is such a sparse file, so its mount options
carry discard from the moment the mount exists, and every place the
file is later mounted, container or pod, lower layer or writable,
inherits the ask with the rest of the options. A read-only mount
parses the option and leaves it idle, and a caller who builds a mount
of their own chooses their own options, as they do for everything
else. The swap area has asked for the same thing since it was added,
for the same reason.
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.

1 participant