Been tinkering with btrfs with consideration of moving from ext4 to that.
However, when wanting to compare R/W speeds, I seem to have come across an (to me at least) unusual behavior by du
on the btrfs disk, where it apparently don't report the filesize in same way as with files on my ext4.
(Apologies for the Norwegian locale. Though most are probably familiar enough with the English outputs to see what's going on)
Making a testfile
I create a 5GB "testfile" with
dd
on the mounted btrfs disk :$ sudo dd if=/dev/urandom of=5G_dd_test_file.tmp bs=1 count=0 seek=5G 0+0 oppføringer inn 0+0 oppføringer ut 0 byte kopiert, 0,00393248 s, 0,0 kB/s
In similar fashion I create a testfile using
fallocate
in same location :$ sudo fallocate -l 5G 5G_fallocate_test_file.tmp
ls
confirms they're both there:$ ls 5G_dd_test_file.tmp 5G_fallocate_test_file.tmp
du
acting weird..(?)
The size output from du <file>
:
$ sudo du 5G_dd_test_file.tmp
0 5G_dd_test_file.tmp
$ sudo du 5G_fallocate_test_file.tmp
5242880 5G_fallocate_test_file.tmp
Note the 0 filesize on the dd-generated file
In comparison, ls
and stat
on the very same files :
$ ls -l *.tmp
-rw-r--r-- 1 root root 5368709120 mars 24 18:07 5G_dd_test_file.tmp
-rw-r--r-- 1 root root 5368709120 mars 24 18:12 5G_fallocate_test_file.tmp
$ stat *.tmp
Fil: 5G_dd_test_file.tmp
Størrelse: 5368709120[tab]Blokker: 0 IO Blokk: 4096 vanlig fil
Device: 0,40 Inode: 258 Links: 1
Tilgang: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Tilgang: 2022-03-24 18:07:34.646755042 +0100
Omgjøring: 2022-03-24 18:07:34.646755042 +0100
Endring: 2022-03-24 18:07:34.646755042 +0100
Fødsel: 2022-03-24 18:07:34.646755042 +0100
Fil: 5G_fallocate_test_file.tmp
Størrelse: 5368709120[tab]Blokker: 10485760 IO Blokk: 4096 vanlig fil
Device: 0,40 Inode: 259 Links: 1
Tilgang: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Tilgang: 2022-03-24 18:12:11.768422242 +0100
Omgjøring: 2022-03-24 18:12:11.768422242 +0100
Endring: 2022-03-24 18:12:11.768422242 +0100
Fødsel: 2022-03-24 18:12:11.768422242 +0100
If however I add the -b
parameter to du
(not usually needed) when doing the same dd
generated file that showed 0 size. Then du
seems to be acting as usual.
$ sudo du -b 5G_dd_test_file.tmp
5368709120 5G_dd_test_file.tmp
Another oddity from du
(?)
So just out of curiosity, i decided to simply gzip
the file from dd
:
$ sudo gzip 5G_dd_test_file.tmp
$ sudo du 5G_dd_test_file.tmp.gz
5092 5G_dd_test_file.tmp.gz
Now it's showing a non-zero size..
$ sudo ls -l 5G_dd_test_file.tmp.gz
-rw-r--r-- 1 root root 5210230 mars 24 18:07 5G_dd_test_file.tmp.gz
sudo stat 5G_dd_test_file.tmp.gz
Fil: 5G_dd_test_file.tmp.gz
Størrelse: 5210230 [tab]Blokker: 10184 IO Blokk: 4096 vanlig fil
Device: 0,40 Inode: 260 Links: 1
Tilgang: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Tilgang: 2022-03-24 18:07:34.646755042 +0100
Omgjøring: 2022-03-24 18:07:34.646755042 +0100
Endring: 2022-03-24 18:43:41.061926016 +0100
Fødsel: 2022-03-24 18:42:27.554141544 +0100
Questions are
- Is this normal behavior and actually to be expected?
- If not, could this potentially break e.g scripts or programs reliant on
du
returns?
du
vswc -c
, one needs to choose the right tool for the job; here: the right filesystem type. And like in many other areas, the ability to choose the right tool comes from experiences of choosing a wrong tool.