Hi. In both 13.1-RELEASE and FreeBSD-14.0-Release, in ZFS, if I write files and then do a du or ls -l, the wrong size is reported for several seconds. It reports it way too small. In my example, it only reports 1 block at first, then finally reports the size as 11 blocks. This seems to be some kind of cache coherency issue.
I am developing some scripts that require getting and recording a directory size after writing files to it, but this creates a significant obstacle. Am I overlooking something? Perhaps a ZFS tuning parameter to correct it? If I run the test in a UFS file system the problem does not exist. It immediately reports the correct size. I have included a short script that reproduces the problem.
I am developing some scripts that require getting and recording a directory size after writing files to it, but this creates a significant obstacle. Am I overlooking something? Perhaps a ZFS tuning parameter to correct it? If I run the test in a UFS file system the problem does not exist. It immediately reports the correct size. I have included a short script that reproduces the problem.
sh:
#!/bin/sh
# Cleanup before starting the test
rm -rf testdir
# Make a test directory, and create a test file in it to use some space.
mkdir -p testdir
echo Creating testdir/testfile
dd if=/dev/random of=testdir/testfile bs=1k count=10 2> /dev/null
echo
ls -l testdir
du -s testdir # Reports wrong value (way too small)
# After sleeping 5 seconds, it reports the correct size.
# It sometimes reports the correct value after 3 seconds but is not
# consistent until after 5 seconds.
sleep 5
du -s testdir