>>I am aware of the fact that in DOS, its better to keep the number
>>of files in a directory below 150 - for performance reasons. I am
>>bit confused if the same applies for UNIX and if it does exist, I
>>am interested to know the number.
>It is not important for UNIX.
Yes, it is. It's going to be an issue for just about any OS,
although the specific number will vary. But since ANSI C doesn't
recognize the existence of anything called a "directory", it's
not relevant to C.
I have had systems trying to use UUCP cease working because
the work directory got so large it took too long to search it
and the other end timed out. The directory got over
about 5,000 files. It didn't help that this particular old
version of UNIX would never shrink a directory. Once things
got bad, they would only get worse.
>If you have 1000 files in a directory, when you type "ls", the
>command must sort them before displaying them, so it is longer
>than if there were only 100 files.
>With UNIX a 150 files directory is a little directory. ;-)
Imagine you are chief programmer for AOL or Netcom. Would
you design mail so that each user's mail is kept in one file
in a single mail directory? AOL has at least a million
subscribers last I heard, and they should be planning for expansion.
Assume a typical directory entry takes about 20 bytes.
That's a *20 MEGABYTE* directory NOW, and maybe 200 megabytes
a few years later - and this is just for the directory, not
for the files in it. To find a file in that directory, you
have to read, on the average, half of it. *SLOW*.
Typical breakpoints in performance searching UNIX directories
occur at these points:
- The directory gets bigger than one block.
- The directory acquires an indirect block (typically, gets bigger
than 10 blocks)
- The directory acquires a double-indirect block. (it's
probably over the megabyte range now)
- The directory acquires a triple-indirect block. (Now you're
getting totally insane, and where were you planning on putting
the file contents?).
Just because these are breakpoints where search time increases
in a way WORSE than proportional to the size of the directory
doesn't mean you shouldn't try to keep the directory as small
How big a UNIX "block" is depends on your system, and perhaps
how the disk was initialized. Typical values include 512 bytes,
4k, and 8k. With BSD UFS filesystems, directory entries are
not fixed size. Use of very long filenames will require very
large directory entries.
In the old V7 UNIX filesystem, a block was 512 bytes, directory
entries were 16 bytes long (14 character names max), and
you could fit 30 files (plus "." and "..") in a single block,
and 318 before getting an indirect block.
Assuming similar-sized directory entries for a BSD 8k filesystem,
that would be about 510 files and 5118 files, respectively.
This would get a lot smaller if you go nuts with long file names.
Gordon L. Burditt