-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
vdev_file: implement TRIM-like support for FreeBSD 14 #16496
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for making it feature-complete!
7f0c1a3
to
3c0c0ef
Compare
Last push makes |
3c0c0ef
to
19da2ac
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couple more comments, but otherwise looks good to me.
407a467
to
becc671
Compare
becc671
to
bceb3c4
Compare
In a next step we can re-enable TRIM tests on FreeBSD via ZTS. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We only use it on a specific way: to punch a hole in (make sparse) a region of a file, in order to implement TRIM-like behaviour. So, call the op "deallocate", and move the Linux-style mode flags down into the Linux implementation, since they're an implementation detail. FreeBSD gets a no-op stub (for the moment). Sponsored-by: https://despairlabs.com/sponsor/ Signed-off-by: Rob Norris <robn@despairlabs.com>
FreeBSD 14 gained a `VOP_DEALLOCATE` VFS operation and a `fspacectl` syscall to use it. At minimum, these zero the given region, and if the underlying filesystem supports it, can make the region sparse. We can use this to get TRIM-like behaviour for file vdevs. Sponsored-by: https://despairlabs.com/sponsor/ Signed-off-by: Rob Norris <robn@despairlabs.com>
bceb3c4
to
6e05c1b
Compare
Rebased. I haven't enabled the tests, as I couldn't tell if the new runners are using something other than UFS on FreeBSD. See OP; UFS doesn't support hole punching yet. |
FreeBSD 14 gained a `VOP_DEALLOCATE` VFS operation and a `fspacectl` syscall to use it. At minimum, these zero the given region, and if the underlying filesystem supports it, can make the region sparse. We can use this to get TRIM-like behaviour for file vdevs. Sponsored-by: https://despairlabs.com/sponsor/ Reviewed by: Brian Behlendorf <behlendorf1@llnl.gov> Reviewed-by: Alexander Motin <mav@FreeBSD.org> Reviewed-by: Tino Reichardt <milky-zfs@mcmilk.de> Signed-off-by: Rob Norris <robn@despairlabs.com> Closes #16496
We only use it on a specific way: to punch a hole in (make sparse) a region of a file, in order to implement TRIM-like behaviour. So, call the op "deallocate", and move the Linux-style mode flags down into the Linux implementation, since they're an implementation detail. FreeBSD gets a no-op stub (for the moment). Sponsored-by: https://despairlabs.com/sponsor/ Reviewed by: Brian Behlendorf <behlendorf1@llnl.gov> Reviewed-by: Alexander Motin <mav@FreeBSD.org> Reviewed-by: Tino Reichardt <milky-zfs@mcmilk.de> Signed-off-by: Rob Norris <robn@despairlabs.com> Closes openzfs#16496
We only use it on a specific way: to punch a hole in (make sparse) a region of a file, in order to implement TRIM-like behaviour. So, call the op "deallocate", and move the Linux-style mode flags down into the Linux implementation, since they're an implementation detail. FreeBSD gets a no-op stub (for the moment). Sponsored-by: https://despairlabs.com/sponsor/ Reviewed by: Brian Behlendorf <behlendorf1@llnl.gov> Reviewed-by: Alexander Motin <mav@FreeBSD.org> Reviewed-by: Tino Reichardt <milky-zfs@mcmilk.de> Signed-off-by: Rob Norris <robn@despairlabs.com> Closes openzfs#16496
Motivation and Context
Just reading code and noticed FreeBSD support for TRIM to file-backed vdevs was commented out. Looked further and found FreeBSD 14 implemented support for it, so for fun I wired it up.
Description
First, rename
vfs_file_fallocate
tovfs_file_deallocate
, and push the Linux-specific hole-punching flags down to the Linux implementation, and make a FreeBSD no-op implementation.Then, fill out the FreeBSD implementation with calls to
fspacectl()
(userspace) orfo_fspacectl()
(kernel).How Has This Been Tested?
Compile checked on Linux 6.1, FreeBSD 13 & 14.
On Linux,
zpool_trim
andtrim
test tags continue to pass.On FreeBSD its a little more complicated. Currently UFS doesn't implement a specific
VOP_DEALLOCATE
, so the generic fallback is used, which simply writes zeroes. As a result, enabling the test tags just gives a bunch of failed tests because they all look for the effective size on disk, that is, they assume the deallocated regions will become sparse. I don't really want to attempt to change the test suite to use a different filesystem (my FreeBSD test runner is already in tenuous shape as it is).But,
tmpfs(5)
does supportVOP_DEALLOCATE
, so we can faff around a bit to try and prove it that way.Lets make a tmpfs, and then make a file full of data:
Because its full of data, its effective size is 100K 1K-blocks:
I wrote a daft little program,
dumpholes
, to show the data/hole structure of a file. That also shows that it's all-data:So we make a pool over the top, then issue the trim:
For extra fun, we can use
dtrace
to see that yes, its really doing things:After, we can see the effective size of the file has dropped, and its now full of holes:
And if we read back part of the zeroed region, it is, indeed, zeroes:
So I suppose that works?
Types of changes
Checklist:
Signed-off-by
.