-
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
Add option to zeroing unused space through zpool initialize
#16778
Comments
Isn't there a tunable that you can change to 0, instead of the default https://github.com/openzfs/zfs/blob/master/module/zfs/vdev_initialize.c#L828 |
Hmm... There seems to exist:
So you mean setting that to lets say "00000000000000000000" would Does it have to be of that length or can I just set it to "0" or should there be some length to it for performance reasons? If above is possible it should be added to the manpages for zpool-initialize :-) |
Just "0" will be expanded to set all bits to 0. |
That seems to have been working... Added zero to the tuneable:
Verified that it updated:
Uninitialized the zpool:
Tried to initialize it again:
Verified through The result is that the thin-provisoned VDI-file grew with about 69 MB at the VM-host. From 12 657 360 896 bytes to 12 726 566 912 bytes After running compact it shrunk down to 10 047 455 232 bytes. Size from within the VM-guest is 8122 MB. So Im guessing it should be fairly straight forward to add the option "-z" (or similar) if this feature request is picked up? |
Agreed... There is this: But I can't find a man page for the module parameters. Does it exist and I just can't find it? |
Maybe this is a stupid question, but can't you just issue a |
The physical drive (Samsung 850 Pro 1TB) do support trim and in Virtualbox the storage is configured as VirtIO where the virtual drives have "Solid-state Drive" enabled. The ZFS module within the VM-guest being used is:
The host is a Ubuntu 24.04 LTS (Intel i5-4250U, 16GB RAM, Samsung 850 Pro 1TB) using VirtualBox 7.1.4 r165100 (Qt6.4.2) with extension pack 7.1.4r165100 installed. The Ubuntu installation is fully updated up until today. The VM-guest is Proxmox PVE 8.2.8 fully updated up until today. Main purpose of this setup is to test out software raid1 using ZFS on bootdrives in Proxmox before doing the same on baremetal later on. And thats when I went into this rabbit hole of "hmm, how do I zeroize the zpool so the VM-host can compact the VDI-files?". |
Line 1689 in ff3df12
|
Describe the feature would like to see added to OpenZFS
Add option to
zpool inititalize
to zeroing written blocks instead of using a known string ("0xdeadbeefdeadbeeeULL", ref: https://github.com/openzfs/zfs/blob/master/module/zfs/vdev_initialize.c#L39).Perhaps adding this as an optional "-z" (zeroing) option?
A bonus to this feature request would be to also add option to use some random pattern for zeroing, for example through optional "-r" (random) option?
Current manpage:
https://openzfs.github.io/openzfs-docs/man/master/8/zpool-initialize.8.html
How will this feature improve OpenZFS?
Avoiding doing lengthy workarounds (described below) to zero out unused space which then can be reclaimed by the VM-host in a thin-provisioned environment.
Additional context
When issuing
zpool initialize
it will try to write to all available sectors in the drive(s) being used for a zpool using a known string "0xdeadbeefdeadbeeeULL".This method is often used to verify that a drive is healthy similar to do a scan for badblocks.
However that writing is using a non-zero string which makes if ZFS is being used through a thin-provisioned VM such as Virtualbox then this unused space cannot be reclaimed by the VM-host.
Doing a dd from within the VM-guest:
will also not work if you have compression=on for that zpool.
A workaround for above is to first put the box in singleuser mode (init 1) followed by disabling compression:
verify through:
and then issue the "create large empty file and then remove it" through:
Once the above have completed and the large empty file have been deleted you renable compression and then shutdown the VM:
Once the VM-guest is shutdown issue a compaction of the VDI-file at the VM-host such as (example for Virtualbox):
Now the thinprovisioned virtual drive can shrink in size at the host to the actual content (in my test from a provisioned 80GB file down to approx 12GB which is the actual content within the VM-guest + some metadata etc).
If the
zpool initialize
command could have a zeroing option (such aszpool inititalize -z <poolname>
) that could be used instead of above workaround to write zeroes to all unused blocks which then will make it possible to compact the thin-provisioned storage.The text was updated successfully, but these errors were encountered: