Repository navigation
btrfs: expose async discard initial delays in sysfs - #4170
Open
IronsideXXVI wants to merge 1 commit into
Open
IronsideXXVI wants to merge 1 commit into
IronsideXXVI wants to merge 1 commit into
Conversation
Btrfs async discard holds freed extents in active data block groups for a hardcoded 120 s (BTRFS_DISCARD_DELAY) and empty block groups for 10 s (BTRFS_DISCARD_UNUSED_DELAY). On fast NVMe SSDs with a dynamic pSLC write cache (such as Apple ANS2), holding multi-MiB freed extents untrimmed for up to two minutes leaves the FTL free pool under-provisioned during back-to-back write bursts and loses untrimmed state across quick reboots. Expose discard_delay_ms (default 120000 ms) and discard_unused_delay_ms (default 10000 ms) as read-write attributes under /sys/fs/btrfs/<uuid>/discard/, preserving existing defaults identically. When updated via sysfs, clamp already-queued block groups down to the new deadline and reschedule discard work immediately. Signed-off-by: Dylan Ironside <dylan@dylanironside.io>
|
Merge readiness at
Areas: none matched in CODEOWNERS Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels. |
RyanTheTide
approved these changes
Dec 3, 2026
RyanTheTide
left a comment
Contributor
There was a problem hiding this comment.
The default deadlines match the old constants, and a sysfs write clamps only the selected class of queued block groups under the discard lock before rescheduling the worker. Milliseconds are widened before conversion to nanoseconds. The live result is from the integrated kernel, while the exact-head verification is the build.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What: Expose Btrfs async-discard initial delays as per-filesystem read-write sysfs attributes under
/sys/fs/btrfs/<uuid>/discard/while keeping existing defaults unchanged:discard=asynccurrently holds freed extents in active data block groups for a hardcoded120 s(BTRFS_DISCARD_DELAY) and empty block groups for10 s(BTRFS_DISCARD_UNUSED_DELAY). On fast NVMe SSDs with a dynamic pSLC write pool (such as Apple ANS2), holding multi-MiB freed extents untrimmed for up to two minutes leaves the FTL free pool under-provisioned during back-to-back write bursts and loses untrimmed state across reboots.discard_delay_ms(default120000ms) anddiscard_unused_delay_ms(default10000ms) via standardBTRFS_ATTR_RW(bounded to0..86400000ms, zero module parameters).btrfs_discard_update_delay()stores the new delay underdiscard_ctl->lock, clamps already-queued block groups on the corresponding discard list(s) down to the new deadline, and reschedules discard work immediately.omarchy-mac-btrfs-discard.service, which tunesdiscard_delay_ms=1000anddiscard_unused_delay_ms=100strictly onnvme-apple-backed Btrfs filesystems).Tested:
06d4fcfa8ac3onorigin/main(62c60d13d4d8,0merge-tree conflicts):scripts/checkpatch.pl --strict --git origin/main..HEAD:0errors,0warnings,0checks (199lines checked).LLVM=1 W=1 KCFLAGS="-Werror":fs/btrfs/discard.o(260664bytes) andfs/btrfs/sysfs.o(464656bytes),0warnings,0errors.0module_paramadditions.linux-aurora 7.3.0.aurora1-1.1693and primary release shiplinux-aurora 7.3.0.aurora1-1.1694(957908b7bd99, boot29379f09, paired withomarchy-macPR net: apple: Add N1 protocol-27 station and data-ring consumer #251):/sys/fs/btrfs/<uuid>/discard/discard_delay_msanddiscard_unused_delay_msread/write cleanly at boot (1000/100ms applied byomarchy-mac-btrfs-discard.service).1.1694passed all boot, ESP, thermal (34.0 C,PMPEV=0), display/GPU (1640.8 fps), and storage/runtime health gates with0failed units and0kernel/storage faults.Risk: two-way door · all platforms (
fs/btrfs/{discard.c,discard.h,fs.h,sysfs.c},+116 / -8lines). Default delays are unchanged (120000ms /10000ms); behavior only changes when userspace explicitly writes the new per-filesystem sysfs attributes. A plain revert restores the compile-time constants.Not yet:
linux-btrfsmailing list andDocumentation/ABI/testing/sysfs-fs-btrfsupdate.origin/mainhead06d4fcfa8ac3separate fromiops_limit/kbps_limit/max_discard_sizetuning inomacom/omarchy-mac-pkgs#251.Details and verification
Scope (
j604/btrfs-async-discard-sysfs-delays, head06d4fcfa8ac3onmain62c60d13d4d8)fs/btrfs/discard.c(+45 / -8)fs/btrfs/discard.h(+8)fs/btrfs/fs.h(+2)fs/btrfs/sysfs.c(+61)Signed-off-by: Dylan Ironside <dylan@dylanironside.io>scripts/checkpatch.pl --strict --git origin/main..HEAD:0 errors, 0 warnings, 0 checks(199lines checked).git merge-tree --write-tree origin/main HEAD: clean (267b9bde95bd).LLVM=1 W=1 KCFLAGS="-Werror":fs/btrfs/discard.o(260664bytes),fs/btrfs/sysfs.o(464656bytes),0warnings.linux-aurora 1.1694, boot29379f09):discard_delay_ms=1000,discard_unused_delay_ms=100active viaomacom/omarchy-mac-pkgs#251,0failed units,0faults, G6PMPEV=0, G734.0 C, G5b PASS.