SOLVED How To: show ZFS compression of a SINGLE file (has answer, is not a ?)

SMnasMAN

Contributor
Joined
Dec 2, 2018
Messages
177
ive seen this question asked before (and dont recall an answer being given) , additionally, ive had this question myself, and recently found the answer:

How does one see how well ZFS compression is performing on a single, specific file?

I have several vmware/vcenter VMDK files on my Freenas box via NFS. I use lz4 compression (as most should)- ive wanted to see how well zfs compression is doing on a per VM / vm disk basis (beyond the "global" , per datastore "Compression Ratio" info in the freenas web gui).

the solution is to use command: du -A
-A = Apparent size , and thus in this case would be the "Uncompressed" size of the file

(also if you add -h , human readable, du will show the result in MB,GB,TB- so: du -Ah

to see the compressed size (ie what its actually being used up on your zfs "disk"/pool): du (or du -h)

so if you compare the output of: du -A vs du -h (du -Ah vs du -h ) its clear to see the savings (or lack of):

1610227884958.png



I wrote this quick oneliner to give cleaner output (and recursive) , for in this case standard *flat.vmdk VMware disk files;

find . -type f -iname "*flat.vmdk" -exec sh -c "echo -n ' de-compressed: '; du -Ah '{}'; echo -n 'compressed (used): '; du -h '{}'; echo ' '" \;

1610228080331.png


(not bad compression! in this case, on the 1.0TB vmdk, inside windows/ntfs vm, there is ~450gb of actual real prtg data on this disk, + this is going through a vmdk file, so zfs doesnt even have access to the raw files for compression!)

du -Ah shows the same size (as it should) as the standard (LS -Lh): ls -lh

(also a google search of this forum for "du -A" only turned up one relevant post, so i figured i would make this new post for others to find/see.)

tks
 
Last edited:

martin2380

Cadet
Joined
Apr 13, 2022
Messages
3
I've found this post via Google. Looks like there is no -A for Linux. If you are using Truenas SCALE, you have to use --apparent-size. -b should also work.
 

smcclos

Dabbler
Joined
Jan 22, 2021
Messages
43
Great script file, adding to my list of useful tasks!!
 
Top