I have several copies of a file. The files take 2390170KiB each, according to ls -lk
and du --apparent-size -k
.
The problem is that du -k
reports different sizes for each copy: 2389824, 2392512, 2392512 and 2390336.
I expected the disk usage should be the 2390172KiB (the size of the minimun number of blocks (597543) where the file fits.
So, why each file have a different disk usage?
I also have seen that one of the copies use 2389824KiB, but the file size is 346KiB bigger: 2390170. How does this make sense?
PD: All the files are in the same ext3 filesystem. The filesystem block size is 4096. All the files have the same hash.
Update: From the comments:
although the apparent size is usually smaller, it may be larger due to holes in ('sparse') files, internal fragmentation, indirect blocks, and the like
sparse files may be the reason because the disk usage is lower. But I fail to see how internal fragmentation or indirect blocks may reduce the disk usage in respect to the original file. Since the file is the same, the disk usage from the internal fragmentation and the indirect blocks should be constant.
I have observed that cp --sparse=always
can make a sparse file from a non-sparse one.
cp --sparse=always
results on a file that uses 2390336KiB
cp --sparse=never
results on a file that uses 2392512KiB
So I'll guess that the 2389824KiB usage from one of the copies is caused from a different implementation of the sparse algorithm...
The original file was copied from a windows machine through sftp or samba, and I think that the 2389824KiB file is a copy of it, but I don't remember how did I did it (I guess that with cp, but I'm not sure).