[lug] # of subdirectory limits

D. Stimits stimits at idcomm.com
Tue Apr 17 14:34:43 MDT 2001


Andrew Diederich wrote:
> 
> Folks,
> 
> I've run into a limit on Solaris 8, and was wondering if the same thing
> happened to linux.  I wa creating bunches of subdirectories, and ran
> into a limit at 32767 because of the limit on the number of links a file
> can have to it.  So in Solaris if you:
> 
> % grep LINK_MAX /usr/include/limits.h
> #define LINK_MAX        32767
> 
> you see that you can't have more than 32766 subdirectories in a directory,
> and this apparently isn't changable.  So, what is this in linux, and is it
> a compile-time option in the kernel?  Enquiring minds want to know.
> 
> Danke.
> --
>     Andrew Diederich
> _______________________________________________
> Web Page:  http://lug.boulder.co.us
> Mailing List: http://lists.lug.boulder.co.us/mailman/listinfo/lug

The file /usr/src/linux/include/linux/ext2_fs.h has EXT2_LINK_MAX as
32000. A LINKS_MAX in the directory /usr/include/ apparently only set to
127 by default, which I would guess is a conservative minimum for those
who don't specify EXT2 specifically.

This #define for EXT2_LINK_MAX does not have a variable type assigned to
it, so in theory you could use arbitrarily large sizes; in reality,
other variables have to compare against it, so those being compared
against must support that size. An rgrep of the entire 2.2.15 tree shows
the only place it appears is in the source tree's fs/ext2/namei.c and
include/linux/ext2_fs.h. Within namei.c is the only place within the
kernel that comparisons are made, always against struct inode member
i_nlink. That member is type is alias nlink_t; this in turn is in
<linux/types.h>, aliased as __kernel_nlink_t. That last value changes
with architecture, but it is given its final and real meaning in the
kernel source under the relevant
include/asm-SomeArchitecture/posix_types.h. For i386 it is unsigned
short. For i386 you'll find <limits.h> has a 16 bit value for USHRT_MAX
of 65535. Since the test will probably require being able to go one
beyond the actual current node count, you'd have to limit it to
USHRT_MAX minus 1, or 65534.

Alter file /usr/src/linux/include/linux/ext2_fs.h, change EXT2_LINK_MAX
to any value 65534 or less, and it should work. If you have other
programs that were compiled and contain that value before changing it,
they'll need a recompile too. FYI, test it on a machine that can handle
a corrupted file system as a test before you use it on a production
machine. And if you run into something using LINK_MAX instead of
EXT2_LINK_MAX, it'll ignore it and still limit you to lower values.

D. Stimits, stimits at idcomm.com



More information about the LUG mailing list