ZFS Compression Paradox: Logical vs. Physical Blocks

2025-04-17

A 256KB zero file created with `dd` on a ZFS filesystem with compression enabled exhibits a puzzling behavior: `ls -l` shows its size as 256KB, but `ls -s` and `ls -slh` show a much smaller size, almost zero. This is due to ZFS's efficient compression resulting in a minimal number of physical blocks. The article explores three ways to measure file size: logical size (in bytes), physical block count, and logical block count. It points out that the POSIX `st_blocks` field doesn't specify which size to report, leading to potential changes in `st_blocks` value when moving files between filesystems, and even potential file size expansion exceeding the capacity of the new filesystem.

Development