Usenet comp.unix.osf.osf1 (1992-2004)
 help / color / mirror / Atom feed
* Re: Number of file in a directory. Is there a limit ?
       [not found] <7q0lgc$m5j$1@jaydee.iway.fr>
@ 1999-08-25  4:00 ` Bob Harris
  1999-08-25  4:00   ` Serguei Patchkovskii
  0 siblings, 1 reply; 2+ messages in thread
From: Bob Harris @ 1999-08-25  4:00 UTC (permalink / raw)
  To: Ga�l Trinquart

[[ This message was both posted and mailed: see
   the "To," "Cc," and "Newsgroups" headers for details. ]]

In article <7q0lgc$m5j$1@jaydee.iway.fr>, Ga�l Trinquart
<gtrinquart@elan.fr> wrote:

>Number of file in a directory. Is there a limit ?

The limits for the Compaq Tru64 UNIX are specified in the Release
Notes.  You can find a copy at the following URL (I just picked on
v4.0d, but other versions are also available at that site):

<http://www.unix.digital.com/faqs/publications/base_doc/
DOCUMENTATION/V40D_HTML/AQTLMCTE/TITLE.HTM>

To be specific, there is no limit on the number of regular files. 

There is a limit on the number of subdirectories in a single directory. 
Currently that is 32K.  This is because each subdirectory has a hard
link to its parent directory (..) and in the current releases the hard
link limit was 32K.

This subdirectory limit is changing in the next release to 65K which is
the maximum that can fit in the 16 bit st_nlink field of the stat
structure.



^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Number of file in a directory. Is there a limit ?
  1999-08-25  4:00 ` Number of file in a directory. Is there a limit ? Bob Harris
@ 1999-08-25  4:00   ` Serguei Patchkovskii
  0 siblings, 0 replies; 2+ messages in thread
From: Serguei Patchkovskii @ 1999-08-25  4:00 UTC (permalink / raw)


Bob Harris (harris@zk3.dec.com) wrote:
: To be specific, there is no limit on the number of regular files. 

While this *may* be formally correct[1], this statement is not particularly
useful. Both ufs and AdvFs use linear arrays of variable-sized directory
entries as the directory structure. This necessarily implies that operations
which do not involve changing (a sufficiently large) directory with N files
(e.g. opening a file) *must* require O(N) time, and will on average examine 
N/2 directory entries. Any operation involving change to the directory (like
creating, removing, or renaming a file) will need to *update* N/2 directory
entries on average. A little table will help to illustrate this:

  Times in seconds on a AdvFS filesystem using DPW-500au with 64M.
  Per-file times are in milliseconds.

    Files     Create[2]         List[3]         rm[4]
            Total  Per-file  Total Per-file   Total Per-file
            (sec)   (ms)     (sec)   (ms)     (sec)   (ms)
   1,000    1.30    1.30      0.08   0.08      1.17   1.17
  10,000   19.94    1.99      0.17   0.02     13.11   1.31
 100,000  885.58    8.86     40.63   0.41    302.04   3.02

  Directories with 1,000 and 10,000 files are still sufficiently small
to fit in the buffer cache, so that per-file performance does not degrade
too much as the directory grows. The 100,000-file directory is too large
to fit into the buffer cache (which has been tuned to 1% of the available
memory, or ca. 600k - while the directory is over 2Mbytes in size), and
all operations involving changing the directory become painfully slow[5].
Even 'ls -1', which is quite speedy for smaller directories now takes
almost a minute ...

  So, while there may be no *theoretical* limit on the number of files
in a single directory (or, at least, the limit is much larger than anything
most people are likely to encounter in practice), handling more that a few
hundred thousands files in a single directory is likely to result in
severely degraded performance.

  Bob, do you plan to introduce hashed directory structures any time soon?

Regards,

/Serge.P

[1] In fact, it is not. From /usr/include/sys/dirent.h, a directory entry
    is at least 12 bytes in size; since AdvFS limits file size to 2**63
    bytes, there is no way to have a directory with more than 0.33*2**61
    entries. The corresponding limit for UFS is 0.33*2**33. In either case,
    since inode number is a 32-bit value, there is no way to have more
    that 2^32-2 *distinct* files in any directory (or filesystem).

[2] time perl -e 'foreach $x(1..100000){open(F,sprintf(">%d",$x))&&close(F)}'
[3] time ls -1 >/dev/null
[4] time sh -c 'find . -type f | xargs rm'
[5] I must emphasize at this point that AdvFS performs *remarkably* well
    on large directories for a file system with linear directory structures.
    I'd seen much worse performance on substantially smaller directories
    on some other unix variants.

--
home page: http://www.cobalt.chem.ucalgary.ca/ps/



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~1999-08-25  4:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <7q0lgc$m5j$1@jaydee.iway.fr>
1999-08-25  4:00 ` Number of file in a directory. Is there a limit ? Bob Harris
1999-08-25  4:00   ` Serguei Patchkovskii

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox