Mailinglist Archive: opensuse (1445 mails)

< Previous Next >
[opensuse] Re: faster way to get total dir size besides du?
  • From: Joachim Schrod <jschrod@xxxxxxx>
  • Date: Tue, 06 Mar 2012 18:27:44 +0100
  • Message-id: <jj5heg$5m8$>
Jim Henderson wrote:
On Tue, 06 Mar 2012 04:38:21 +0100, Carlos E. R. wrote:

Hash: SHA1

On 2012-03-06 04:07, David Haller wrote:

- AFAIK no filesystem I know of stores the sizes of a directory's
contents somewhere in the directory's metadata

FAT does, kind of. The directory is a record that contains file names,
attributes, sizes, and starting record. You just have to load the
directory record and sum the sizes of all files: one single read one
disc record operation (I don't remember how many files per record). If
the directory is big, then there have to be more reads. The operation is
very fast. If there are subdirectories, then it is slower (recursive

That's different than storing the size of the contents in the directory
entry's metadata - the summing of each subordinate file is what takes the
time. What David is trying to say is that no filesystem that he knows of
(nor that I know of for that matter) stores the total of the subordinate

ie, for a structure of:


/usr doesn't store the sum of the sizes of file1, file2, and file3. It
has to be calculated on the fly.

But that does neither contradict Carlos' point nor does it address
his argument. /usr might not store the sum of the sizes, but each
size for each file.

To repeat:

-- Both for FAT and for Linux filesystems, you have to read the
directory contents.
-- Only for Linux filesystems, you have to stat every file.
-- Both for FAT and for Linux filesystems, you have to sum the

Summing sizes is fast. Carlos' argument is, by not needing to stat
every file, disk usage determination on FAT is much faster, because
stat(2) is an expensive operation when it has to be done on many files.

Actually, I don't know if stat(2) is really the culprit for slow
du; but it's a good bet: I'm quite sure that summing some numbers
ain't the issue. Computers are good in adding numbers, much better
than in accessing disks...

Mind you, I'm not telling that this behaviour would convince me to
use FAT beyond an USB stick. ;-) I just want to contribute what I
see as a misunderstanding. ;-)


Joachim Schrod Email: jschrod@xxxxxxx
Roedermark, Germany

To unsubscribe, e-mail: opensuse+unsubscribe@xxxxxxxxxxxx
To contact the owner, e-mail: opensuse+owner@xxxxxxxxxxxx

< Previous Next >