zfs icon indicating copy to clipboard operation
zfs copied to clipboard

file size wrong directly after copying a file

Open flower1024 opened this issue 1 year ago • 2 comments

System information

Linux | zfs-2.2.4-1 zfs-kmod-2.2.4-1

--- | --- NixOS | 24.05 | 6.646 | x86_64 | zfs-2.2.4-1 zfs-kmod-2.2.4-1 |

Describe the problem you're observing

i have a script that copy a files and calls du directly afterwards. it shows the wrong filesize. after a few seconds it is correct. the copy doesnt run in the background

Describe how to reproduce the problem

the two du commands in the second line show different sizes. they should be identical

dd if=/dev/random of=/tmp/testfile bs=4M count=256 && cp /tmp/testfile . && du -sh testfile && sleep 1 && du -sh testfile

flower1024 avatar Aug 20 '24 13:08 flower1024

Physical disk space usage for a written file is just not known until ZFS transaction group commit is completed. If you really need it to be accurate, you may have to insert zpool sync call before the du, but it may affect performance.

amotin avatar Aug 22 '24 09:08 amotin

Physical disk space usage for a written file is just not known until ZFS transaction group commit is completed. If you really need it to be accurate, you may have to insert zpool sync call before the du, but it may affect performance.

is there a way to delay the return of cp until the zfs transaction group is committed? i dont want to wait for all io on all pools to sync. i just need this cp call to be synced.

in that specific case i could help myself by just du'ing the source file instead of the destination though.

flower1024 avatar Aug 22 '24 20:08 flower1024