Hey everyone! I recently created a 10GB file using `fallocate` on my ZFS pool, which has compression enabled. I'm noticing that the space doesn't appear to be reserved as expected. After running some commands, I found that while the file size shows as 10GB, the actual disk usage is only about 1MB due to compression. It seems like it's treated as a sparse file. When I tried similar tests with XFS and EXT4, the space was indeed reserved. I've read that fallocate might not work as intended on CoW filesystems like ZFS. What's the best way to reserve space on a CoW filesystem? Should I just create the file and fill it with zeros instead? Thanks in advance!
2 Answers
Preallocating space for a CoW filesystem like ZFS seems counterintuitive since writes go to newly-allocated blocks anyway. With Btrfs, you can prevent CoW behavior on a file by marking it with `chattr +C` before using `fallocate` — not sure about ZFS, but it could be worth checking out.
It’s the compression feature of ZFS at play here. Even though you used `fallocate` to create a 10GB file, the filesystem compresses it down to a smaller size on disk. If you use `dd` from `/dev/zero` to fill the file, it should behave similarly. That compresses better, too.
Thanks for the tip!