L2ARC: tag deferred ABDs with device to fix multi-device parallel writes #18158
+30
−12
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
When multiple L2ARC devices perform writes in parallel, the free-on-write list—being a global structure shared across all devices—can cause one device’s write completion to free ABDs belonging to another device that still has in-flight writes. This may result in memory corruption and hard-to-debug race conditions under concurrent workloads.
We developed an internal tool to analyze downstream ZFS forks and identify potentially valuable fixes that have not yet been merged upstream. Using this tool, we discovered the following commit in the TrueNAS ZFS fork:
truenas@69942e1
The change addresses a real concurrency issue in the L2ARC multi-device write path, and we believe it is generally applicable, so we are proposing it upstream for review.
Description
The free-on-write list is a global structure shared across all L2ARC devices. To prevent cross-device interference during parallel writes, this change tags each deferred ABD with its owning
l2arc_dev_t.The
l2arc_do_free_on_write()function is updated to accept a device parameter, allowing it to selectively free only ABDs associated with the specified device. PassingNULLpreserves the existing behavior of freeing all deferred ABDs during shutdown.This approach maintains the simplicity of a global free-on-write list while ensuring correct and safe behavior under concurrent multi-device L2ARC write operations.
Credit goes to the original authors in the TrueNAS ZFS project.
How Has This Been Tested?
This change was validated through code review and targeted stress testing of parallel L2ARC write paths. The updated logic ensures that deferred ABDs are freed only by their owning device, eliminating cross-device races under concurrent write workloads.
Types of changes
Checklist