ZFS How to find out how much a file has been compressed under zstd?

When I copy a file to a dataset with zstd compression, how to find out the uncompressed file size and compressed file size on this disk?
Example
Code:
# zfs set compression=zstd-6 pool/dataset

I'm not Eglish and FreeBSD native. Please also correct my terminology. Is it called 'compressed file size' or is it called 'file size on disk'?

Do any other parameters / zfs settings impact the zstd compression efficiency (I don't mean about the file content, just the zfs, zpool settings)?

Thank you for any elaboration on the matter.
 
The whole filesystem is compressed, not individual files. So you can only get an idea of the compression ratio for the whole filesystem. Look at the compressratio property:
Code:
root@molly:/usr/src/crypto # zfs get compressratio zroot/var
NAME       PROPERTY       VALUE  SOURCE
zroot/var  compressratio  4.44x  -
 
ls -ls will display the number of blocks used by a file on the left-hand column (in ZFS, this includes metadata; the count is broadly "how much disk space could be freed by deleting the file?"), normally the number is in kilobytes. In base FreeBSD, du(1) can also tell you how much space a file is using, and translate blocks into more human-readable values: du -h file.

It's a bit heavy-handed for this one task, but the GNU version of ls can also translate that right-most column into a human-readable value; it can be installed with sysutils/coreutils and run like gls -hls.

ZFS can broadly tell you how much on-disk space is used on a per-file basis. Even these user-space accounts don't quite tell the whole story when it comes to mirrors and raidz, but it takes into account compression (of any type), sparse files, and copies. It doesn't quite tell you what the file was compressed with -- compression operates on a per-block basis, and on long-lived file systems, you can have files where individual blocks are compressed using different algorithms. zdb(8) can retrieve the gritty per-block details, but the prior ls/du/gls suggestions should work for the original question :)
 
Try zdb(8) <https://openzfs.github.io/openzfs-docs/man/8/zdb.8.html>

An example, for file serial number (inode number) 160:

Code:
% mount | grep Transcend
Transcend on /Volumes/t500 (zfs, local, nfsv4acls)
Transcend/VirtualBox on /Volumes/t500/VirtualBox (zfs, local, nfsv4acls)
% pwd
/Volumes/t500/VirtualBox/BSD/GhostBSD/GhostBSD 13-STABLE
% ls -hil
total 41606
195 -rw-------  1 grahamperrin  grahamperrin    11K  1 Feb 20:43 GhostBSD 13-STABLE.vbox
334 -rw-------  1 grahamperrin  grahamperrin    11K  1 Feb 20:43 GhostBSD 13-STABLE.vbox-prev
160 -rw-------  1 grahamperrin  grahamperrin   107G  1 Feb 01:37 GhostBSD 13-STABLE.vdi
265 -rw-r--r--  1 grahamperrin  grahamperrin   2.6G  3 Jan 16:48 GhostBSD-21.11.24.iso
 10 -rw-r--r--  1 grahamperrin  grahamperrin    26K  3 Jan 16:37 GhostBSD-21.11.24.iso.torrent
300 drwx------  2 grahamperrin  grahamperrin     6B  1 Feb 17:47 Logs
515 drwx------  2 grahamperrin  grahamperrin     5B  1 Feb 20:43 Snapshots
% su -
Password:
root@mowa219-gjp4-8570p-freebsd:~ # zdb -d Transcend/VirtualBox 160
Dataset Transcend/VirtualBox [ZPL], ID 21, cr_txg 431200, 417G, 446 objects

    Object  lvl   iblk   dblk  dsize  dnsize  lsize   %full  type
       160    3   128K   128K  38.5G     512   107G   99.84  ZFS plain file

root@mowa219-gjp4-8570p-freebsd:~ # exit
logout
% zfs get compression,compressratio Transcend Transcend/VirtualBox
NAME                  PROPERTY       VALUE           SOURCE
Transcend             compression    zstd-15         local
Transcend             compressratio  1.71x           -
Transcend/VirtualBox  compression    zstd            local
Transcend/VirtualBox  compressratio  1.73x           -
% zfs version
zfs-2.1.99-FreeBSD_gf291fa658
zfs-kmod-2.1.99-FreeBSD_gf291fa658
% uname -aKU
FreeBSD mowa219-gjp4-8570p-freebsd 14.0-CURRENT FreeBSD 14.0-CURRENT #1 main-n252531-0ce7909cd0b-dirty: Wed Jan 19 13:29:34 GMT 2022     root@mowa219-gjp4-8570p-freebsd:/usr/obj/usr/src/amd64.amd64/sys/GENERIC-NODEBUG  amd64 1400048 1400048
%
 
du(1) can also tell you how much space a file is using, and translate blocks into more human-readable values: du -h file. …

Yep, for the example above:

Code:
% ls -Ghiln
total 41606
195 -rw-------  1 1002  1002    11K  1 Feb 20:43 GhostBSD 13-STABLE.vbox
334 -rw-------  1 1002  1002    11K  1 Feb 20:43 GhostBSD 13-STABLE.vbox-prev
160 -rw-------  1 1002  1002   107G  1 Feb 01:37 GhostBSD 13-STABLE.vdi
265 -rw-r--r--  1 1002  1002   2.6G  3 Jan 16:48 GhostBSD-21.11.24.iso
 10 -rw-r--r--  1 1002  1002    26K  3 Jan 16:37 GhostBSD-21.11.24.iso.torrent
300 drwx------  2 1002  1002     6B  1 Feb 17:47 Logs
515 drwx------  2 1002  1002     5B  1 Feb 20:43 Snapshots
% du -h GhostBSD\ 13-STABLE.vdi
 38G    GhostBSD 13-STABLE.vdi
%
 
Back
Top