bdev_discard_supported: understand discard_granularity=0 #16082
Merged
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
OpenZFS does not consider the
discard_granularity
property when enabling discard (TRIM), leading to the kernel rejecting discard requests with confusing warnings in the logs.Closes #16068.
Description
Kernel documentation for the
discard_granularity
property says:Some older kernels had drivers (notably loop, but also some USB-SATA adapters) that would set the
QUEUE_FLAG_DISCARD
capability flag, but havediscard_granularity=0
. Since 5.10 (torvalds/linux@b35fd7422c2f) the discard entry pointblkdev_issue_discard()
has had a check for this, which would immediately reject the call withEOPNOTSUPP
, and throw a scary diagnostic message into the log. See #16068.Since 6.8, the block layer sets a non-zero default for discard_granularity (torvalds/linux@3c407dc723bb), and a future kernel will remove the check entirely.
As such, there's no good reason for us to enable discard when
discard_granularity=0
. The kernel will never let the request go in anyway; better that we just disable it so we can report it properly to the user.How Has This Been Tested?
Compile checked on kernels:
On 5.10.214, loop devices do not set
discard_granularity
when the loop is backed by a file, making it a good candidate to check with.Before:
After:
This does cause parts of the
zpool_trim
andtrim
test suites to fail on kernels affected by this change. To be fair, they were somewhat erroneous in succeeding before, since all those tests really check for is that discards were issued; errors are not reported back through OpenZFS userspace tools (though they are visible, at distance, through the pool'siostats
kstat). I'll see what shakes out of CI first, but I will likely have to update the tests. Current ideas include, skipping the tests on kernels where loop doesn't setdiscard_granularity
, using an alternate block device for the tests (scsi_debug
), or introducing some testing hook.Types of changes
Checklist:
Signed-off-by
.