From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fee84,a97c38d42145ae92 X-Google-Attributes: gidfee84,public From: patchkov@acs1.acs.ucalgary.ca (Serguei Patchkovskii) Subject: Re: Number of file in a directory. Is there a limit ? Date: 1999/08/25 Message-ID: <7q141s$i5s@ds2.acs.ucalgary.ca>#1/1 X-Deja-AN: 517068700 References: <7q0lgc$m5j$1@jaydee.iway.fr> <250819991016365821%harris@zk3.dec.com> Organization: The University of Calgary Newsgroups: comp.unix.osf.osf1 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/