Linux – Invalid size displayed for SSD

ext4filesystemshard drivelinuxssd

I have an 80GB Intel X25-M SSD drive installed on a Linux box running Debian 5.0. The file system on the SSD is ext4. I've had no problems with the drive, and have been using it for quite some time as both swap file storage as well as a place to store a few large database files which require random access.

However, I noticed this odd size readout from ls:

> ls -lh /ssd
total 34G
-rwx------ 1 root root 23G 2010-12-11 18:00 file1.dat
-rwx------ 1 root root 22G 2010-12-11 18:00 file2.dat

I changed the names of the files here for security reasons, but other than that this is exactly what ls has output. Obviously, the total size readout is incorrect.

Here is the corresponding output from df

> df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda1              74G   35G   36G  50% /ssd

Despite this incorrect readout, the drive seems to be working fine, and diagnostic utilities turned up nothing wrong with the drive. Is this some sort of known bug in ext4, or is it more likely there's something physically wrong with the drive?

Best Answer

Most likely neither. The size displayed by ls is the length of the file, however most modern filesystems support "Sparse Files" where empty blocks are not actually written to disk. Try running du -h /ssd/* and see what size it reports the files as. 'du' will display the amount of disk actually used, which should be fairly close (excluding filesystem overhead & reserved blocks) to that reported by 'df'.

Related Question