Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I ran df, and the output appears almost instantly:

(FS        Size  Used   Avail  Use%)
/dev/sda1  145G  8.4G   130G   7%

sda1 is an ext4 partition.

Without summing the size of all files, how can df give me the space information almost instantly?

share|improve this question
add comment

1 Answer

up vote 3 down vote accepted

Like traditional Unix File Systems, ext2, ext3 and ext4 have a segment of metadata called a superblock, which contains information about the configuration of the file system. The primary superblock is stored at a fixed offset from the start of the partition, and since the information it contains is so important, backup copies of the superblock are stored throughout the file system.

The information the superblock contains includes the total number of inodes and blocks in the filesystem and how many are free. This information can be used to calculate the used and available space of the file system efficiently.

share|improve this answer
    
+1 You're right, the superblock is important, so much so that a copy is almost always kept in memory such that df doesn't even have to go to disk to get the allocation totals. –  msw Sep 27 '13 at 12:08
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.