L2ARC: Add depth cap and write budget fairness for persistent markers#18289
Closed
ixhamza wants to merge 6 commits intoopenzfs:masterfrom
Closed
L2ARC: Add depth cap and write budget fairness for persistent markers#18289ixhamza wants to merge 6 commits intoopenzfs:masterfrom
ixhamza wants to merge 6 commits intoopenzfs:masterfrom
Conversation
amotin
approved these changes
Mar 9, 2026
The dynamic headroom redistribution formula gave later sublists progressively larger scanning budgets, and random sublist selection caused uneven coverage across sublists. For depth cap to work effectively, each sublist should be equally and fairly treated. Use equal per-sublist headroom (headroom / num_sublists) for even distribution and deterministic round-robin selection for fair coverage across cycles. Signed-off-by: Ameer Hamza <[email protected]>
Replace direct marker-to-tail manipulation with per-sublist boolean flags consumed lazily by feed threads. Each scanning thread resets its own marker when it sees the flag, rather than having another thread manipulate the marker directly. Signed-off-by: Ameer Hamza <[email protected]>
With persistent markers and inclusive scanning, the marker traverses the entire ARC state across many feed cycles, writing buffers far from the tail that may no longer be relevant. Track cumulative bytes scanned per pass in l2arc_ext_scanned. When scans reach l2arc_ext_headroom_pct (default 25%) of the ARC state size, reset the pass markers to the tail via lazy reset flags. This keeps markers focused on the tail zone where buffers soon to be evicted have the most value for L2ARC. Signed-off-by: Ameer Hamza <[email protected]>
Under heavy metadata load, metadata passes can monopolize the write budget every cycle while data passes get nothing written. Track consecutive monopolized cycles per device in l2ad_meta_cycles. After l2arc_meta_cycles (default 2) consecutive cycles where metadata fills the write budget, skip metadata for one cycle to let data run. Reset the counter when nothing is written. Signed-off-by: Ameer Hamza <[email protected]>
Signed-off-by: Ameer Hamza <[email protected]>
prev_hdr is dereferenced after the sublist lock is dropped for write I/O but nothing prevents it from being freed during that window. Eliminate prev_hdr entirely and simplify persistent marker repositioning logic. Signed-off-by: Ameer Hamza <[email protected]>
amotin
approved these changes
Mar 9, 2026
behlendorf
approved these changes
Mar 9, 2026
behlendorf
pushed a commit
that referenced
this pull request
Mar 10, 2026
Replace direct marker-to-tail manipulation with per-sublist boolean flags consumed lazily by feed threads. Each scanning thread resets its own marker when it sees the flag, rather than having another thread manipulate the marker directly. Reviewed-by: Brian Behlendorf <[email protected]> Reviewed-by: Alexander Motin <[email protected]> Signed-off-by: Ameer Hamza <[email protected]> Closes #18289
behlendorf
pushed a commit
that referenced
this pull request
Mar 10, 2026
With persistent markers and inclusive scanning, the marker traverses the entire ARC state across many feed cycles, writing buffers far from the tail that may no longer be relevant. Track cumulative bytes scanned per pass in l2arc_ext_scanned. When scans reach l2arc_ext_headroom_pct (default 25%) of the ARC state size, reset the pass markers to the tail via lazy reset flags. This keeps markers focused on the tail zone where buffers soon to be evicted have the most value for L2ARC. Reviewed-by: Brian Behlendorf <[email protected]> Reviewed-by: Alexander Motin <[email protected]> Signed-off-by: Ameer Hamza <[email protected]> Closes #18289
behlendorf
pushed a commit
that referenced
this pull request
Mar 10, 2026
Under heavy metadata load, metadata passes can monopolize the write budget every cycle while data passes get nothing written. Track consecutive monopolized cycles per device in l2ad_meta_cycles. After l2arc_meta_cycles (default 2) consecutive cycles where metadata fills the write budget, skip metadata for one cycle to let data run. Reset the counter when nothing is written. Reviewed-by: Brian Behlendorf <[email protected]> Reviewed-by: Alexander Motin <[email protected]> Signed-off-by: Ameer Hamza <[email protected]> Closes #18289
behlendorf
pushed a commit
that referenced
this pull request
Mar 10, 2026
Reviewed-by: Brian Behlendorf <[email protected]> Reviewed-by: Alexander Motin <[email protected]> Signed-off-by: Ameer Hamza <[email protected]> Closes #18289
behlendorf
pushed a commit
that referenced
this pull request
Mar 10, 2026
prev_hdr is dereferenced after the sublist lock is dropped for write I/O but nothing prevents it from being freed during that window. Eliminate prev_hdr entirely and simplify persistent marker repositioning logic. Reviewed-by: Brian Behlendorf <[email protected]> Reviewed-by: Alexander Motin <[email protected]> Signed-off-by: Ameer Hamza <[email protected]> Closes #18289
ixhamza
added a commit
to truenas/zfs
that referenced
this pull request
Mar 10, 2026
The dynamic headroom redistribution formula gave later sublists progressively larger scanning budgets, and random sublist selection caused uneven coverage across sublists. For depth cap to work effectively, each sublist should be equally and fairly treated. Use equal per-sublist headroom (headroom / num_sublists) for even distribution and deterministic round-robin selection for fair coverage across cycles. Reviewed-by: Brian Behlendorf <[email protected]> Reviewed-by: Alexander Motin <[email protected]> Signed-off-by: Ameer Hamza <[email protected]> Closes openzfs#18289
ixhamza
added a commit
to truenas/zfs
that referenced
this pull request
Mar 10, 2026
Replace direct marker-to-tail manipulation with per-sublist boolean flags consumed lazily by feed threads. Each scanning thread resets its own marker when it sees the flag, rather than having another thread manipulate the marker directly. Reviewed-by: Brian Behlendorf <[email protected]> Reviewed-by: Alexander Motin <[email protected]> Signed-off-by: Ameer Hamza <[email protected]> Closes openzfs#18289
ixhamza
added a commit
to truenas/zfs
that referenced
this pull request
Mar 10, 2026
With persistent markers and inclusive scanning, the marker traverses the entire ARC state across many feed cycles, writing buffers far from the tail that may no longer be relevant. Track cumulative bytes scanned per pass in l2arc_ext_scanned. When scans reach l2arc_ext_headroom_pct (default 25%) of the ARC state size, reset the pass markers to the tail via lazy reset flags. This keeps markers focused on the tail zone where buffers soon to be evicted have the most value for L2ARC. Reviewed-by: Brian Behlendorf <[email protected]> Reviewed-by: Alexander Motin <[email protected]> Signed-off-by: Ameer Hamza <[email protected]> Closes openzfs#18289
ixhamza
added a commit
to truenas/zfs
that referenced
this pull request
Mar 10, 2026
Under heavy metadata load, metadata passes can monopolize the write budget every cycle while data passes get nothing written. Track consecutive monopolized cycles per device in l2ad_meta_cycles. After l2arc_meta_cycles (default 2) consecutive cycles where metadata fills the write budget, skip metadata for one cycle to let data run. Reset the counter when nothing is written. Reviewed-by: Brian Behlendorf <[email protected]> Reviewed-by: Alexander Motin <[email protected]> Signed-off-by: Ameer Hamza <[email protected]> Closes openzfs#18289
ixhamza
added a commit
to truenas/zfs
that referenced
this pull request
Mar 10, 2026
Reviewed-by: Brian Behlendorf <[email protected]> Reviewed-by: Alexander Motin <[email protected]> Signed-off-by: Ameer Hamza <[email protected]> Closes openzfs#18289
ixhamza
added a commit
to truenas/zfs
that referenced
this pull request
Mar 10, 2026
prev_hdr is dereferenced after the sublist lock is dropped for write I/O but nothing prevents it from being freed during that window. Eliminate prev_hdr entirely and simplify persistent marker repositioning logic. Reviewed-by: Brian Behlendorf <[email protected]> Reviewed-by: Alexander Motin <[email protected]> Signed-off-by: Ameer Hamza <[email protected]> Closes openzfs#18289
14 tasks
bugclerk
pushed a commit
to truenas/zfs
that referenced
this pull request
Mar 10, 2026
The dynamic headroom redistribution formula gave later sublists progressively larger scanning budgets, and random sublist selection caused uneven coverage across sublists. For depth cap to work effectively, each sublist should be equally and fairly treated. Use equal per-sublist headroom (headroom / num_sublists) for even distribution and deterministic round-robin selection for fair coverage across cycles. Reviewed-by: Brian Behlendorf <[email protected]> Reviewed-by: Alexander Motin <[email protected]> Signed-off-by: Ameer Hamza <[email protected]> Closes openzfs#18289 (cherry picked from commit 61423b5)
bugclerk
pushed a commit
to truenas/zfs
that referenced
this pull request
Mar 10, 2026
Replace direct marker-to-tail manipulation with per-sublist boolean flags consumed lazily by feed threads. Each scanning thread resets its own marker when it sees the flag, rather than having another thread manipulate the marker directly. Reviewed-by: Brian Behlendorf <[email protected]> Reviewed-by: Alexander Motin <[email protected]> Signed-off-by: Ameer Hamza <[email protected]> Closes openzfs#18289 (cherry picked from commit 4afadbc)
bugclerk
pushed a commit
to truenas/zfs
that referenced
this pull request
Mar 10, 2026
With persistent markers and inclusive scanning, the marker traverses the entire ARC state across many feed cycles, writing buffers far from the tail that may no longer be relevant. Track cumulative bytes scanned per pass in l2arc_ext_scanned. When scans reach l2arc_ext_headroom_pct (default 25%) of the ARC state size, reset the pass markers to the tail via lazy reset flags. This keeps markers focused on the tail zone where buffers soon to be evicted have the most value for L2ARC. Reviewed-by: Brian Behlendorf <[email protected]> Reviewed-by: Alexander Motin <[email protected]> Signed-off-by: Ameer Hamza <[email protected]> Closes openzfs#18289 (cherry picked from commit 2d85830)
bugclerk
pushed a commit
to truenas/zfs
that referenced
this pull request
Mar 10, 2026
Under heavy metadata load, metadata passes can monopolize the write budget every cycle while data passes get nothing written. Track consecutive monopolized cycles per device in l2ad_meta_cycles. After l2arc_meta_cycles (default 2) consecutive cycles where metadata fills the write budget, skip metadata for one cycle to let data run. Reset the counter when nothing is written. Reviewed-by: Brian Behlendorf <[email protected]> Reviewed-by: Alexander Motin <[email protected]> Signed-off-by: Ameer Hamza <[email protected]> Closes openzfs#18289 (cherry picked from commit b5172ee)
bugclerk
pushed a commit
to truenas/zfs
that referenced
this pull request
Mar 10, 2026
Reviewed-by: Brian Behlendorf <[email protected]> Reviewed-by: Alexander Motin <[email protected]> Signed-off-by: Ameer Hamza <[email protected]> Closes openzfs#18289 (cherry picked from commit 8965fff)
bugclerk
pushed a commit
to truenas/zfs
that referenced
this pull request
Mar 10, 2026
prev_hdr is dereferenced after the sublist lock is dropped for write I/O but nothing prevents it from being freed during that window. Eliminate prev_hdr entirely and simplify persistent marker repositioning logic. Reviewed-by: Brian Behlendorf <[email protected]> Reviewed-by: Alexander Motin <[email protected]> Signed-off-by: Ameer Hamza <[email protected]> Closes openzfs#18289 (cherry picked from commit 66a8726)
14 tasks
bugclerk
pushed a commit
to truenas/zfs
that referenced
this pull request
Mar 10, 2026
The dynamic headroom redistribution formula gave later sublists progressively larger scanning budgets, and random sublist selection caused uneven coverage across sublists. For depth cap to work effectively, each sublist should be equally and fairly treated. Use equal per-sublist headroom (headroom / num_sublists) for even distribution and deterministic round-robin selection for fair coverage across cycles. Reviewed-by: Brian Behlendorf <[email protected]> Reviewed-by: Alexander Motin <[email protected]> Signed-off-by: Ameer Hamza <[email protected]> Closes openzfs#18289 (cherry picked from commit 61423b5)
bugclerk
pushed a commit
to truenas/zfs
that referenced
this pull request
Mar 10, 2026
Replace direct marker-to-tail manipulation with per-sublist boolean flags consumed lazily by feed threads. Each scanning thread resets its own marker when it sees the flag, rather than having another thread manipulate the marker directly. Reviewed-by: Brian Behlendorf <[email protected]> Reviewed-by: Alexander Motin <[email protected]> Signed-off-by: Ameer Hamza <[email protected]> Closes openzfs#18289 (cherry picked from commit 4afadbc)
bugclerk
pushed a commit
to truenas/zfs
that referenced
this pull request
Mar 10, 2026
With persistent markers and inclusive scanning, the marker traverses the entire ARC state across many feed cycles, writing buffers far from the tail that may no longer be relevant. Track cumulative bytes scanned per pass in l2arc_ext_scanned. When scans reach l2arc_ext_headroom_pct (default 25%) of the ARC state size, reset the pass markers to the tail via lazy reset flags. This keeps markers focused on the tail zone where buffers soon to be evicted have the most value for L2ARC. Reviewed-by: Brian Behlendorf <[email protected]> Reviewed-by: Alexander Motin <[email protected]> Signed-off-by: Ameer Hamza <[email protected]> Closes openzfs#18289 (cherry picked from commit 2d85830)
bugclerk
pushed a commit
to truenas/zfs
that referenced
this pull request
Mar 10, 2026
Under heavy metadata load, metadata passes can monopolize the write budget every cycle while data passes get nothing written. Track consecutive monopolized cycles per device in l2ad_meta_cycles. After l2arc_meta_cycles (default 2) consecutive cycles where metadata fills the write budget, skip metadata for one cycle to let data run. Reset the counter when nothing is written. Reviewed-by: Brian Behlendorf <[email protected]> Reviewed-by: Alexander Motin <[email protected]> Signed-off-by: Ameer Hamza <[email protected]> Closes openzfs#18289 (cherry picked from commit b5172ee)
bugclerk
pushed a commit
to truenas/zfs
that referenced
this pull request
Mar 10, 2026
Reviewed-by: Brian Behlendorf <[email protected]> Reviewed-by: Alexander Motin <[email protected]> Signed-off-by: Ameer Hamza <[email protected]> Closes openzfs#18289 (cherry picked from commit 8965fff)
bugclerk
pushed a commit
to truenas/zfs
that referenced
this pull request
Mar 10, 2026
prev_hdr is dereferenced after the sublist lock is dropped for write I/O but nothing prevents it from being freed during that window. Eliminate prev_hdr entirely and simplify persistent marker repositioning logic. Reviewed-by: Brian Behlendorf <[email protected]> Reviewed-by: Alexander Motin <[email protected]> Signed-off-by: Ameer Hamza <[email protected]> Closes openzfs#18289 (cherry picked from commit 66a8726)
14 tasks
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.
Motivation and Context
Follow-up to #18093. With persistent markers, scan positions drift indefinitely toward the head of ARC eviction lists where buffers will stay in ARC for a while, writing them to L2ARC adds little value since ARC already serves them. The tail is where buffers are closest to eviction and benefit most from L2ARC. Additionally, when eviction outpaces L2ARC write throughput, metadata passes run first and can fill the entire write budget every cycle, starving data passes of buffers that could have produced L2ARC hits.
Description
l2arc_ext_headroom_pct(default 25%) of ARC state size. Keeps markers in the tail zone where L2ARC adds the most value. Set to 0 to disable.How Has This Been Tested?
Types of changes
Checklist:
Signed-off-by.