I try to use LXD on ZFS.
$ zpool list
NAME SIZE ALLOC FREE EXPANDSZ FRAG CAP DEDUP HEALTH ALTROOT
lxd 408G 140G 268G - 26% 34% 1.00x ONLINE -
$ zpool status
pool: lxd
state: ONLINE
scan: none requested
config:
NAME STATE READ WRITE CKSUM
lxd ONLINE 0 0 0
/var/lib/lxd/zfs.img ONLINE 0 0 0
/data/index/file01 ONLINE 0 0 0
/data/index/file02 ONLINE 0 0 0
errors: No known data errors
Size of file01, and file02 - 200G each file.
The fragmentation is 26%. How to defrag ZFS pool for LXD correctly?
Not really a LXD question but a generic ZFS question.
I don't believe there is a way to do so. There is a plan that was mentioned a few times (block pointer rewrite), but fragmentation hasn't been enough of a problem for anyone using ZFS to cause someone to actually implement it. https://github.com/zfsonlinux/zfs/issues/3582
One thing to note is that the percentage you're seeing there is apparently free space fragmentation of your pool, not fragmentation of existing files in the pool.
The way to defrag is to do a "zfs send" then "zfs recv" the pool but at 26% fragmentation, you probably don't have any performance impact due to fragmentation so why bother.
Most helpful comment
The way to defrag is to do a "zfs send" then "zfs recv" the pool but at 26% fragmentation, you probably don't have any performance impact due to fragmentation so why bother.