Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 11 Sep 2009 01:30:55 -0500
From:      Dan Nelson <dnelson@allantgroup.com>
To:        fulan Peng <fulanpeng@gmail.com>
Cc:        freebsd-current@freebsd.org
Subject:   Re: How to make sysctl.conf effect?
Message-ID:  <20090911063055.GC37884@dan.emsphone.com>
In-Reply-To: <bf0f1bc90909102158j4356206cqbdccc03a69986fe2@mail.gmail.com>
References:  <bf0f1bc90909102158j4356206cqbdccc03a69986fe2@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
In the last episode (Sep 11), fulan Peng said:
> I am sorry if this is not the right place to ask this question.
> I am using freebsd amd64 7.2.
> I cannot make more than 32768 directories in a folder. So I edited
> /etc/sysctl.conf and added a line
> vfs_ufs_dirhash_maxmem=67108864
> when I do sysctl -a |grep mem, I saw the setting was correct.
> But when I went into a directory and try to make more than 32768
> subdirectories, it always was told me too many links. I have rebooted
> many, many times. I even powered of the computer several times. I have
> 6G memory in the computer. And I even recompiled the kernel once. All
> failed.

dirhash is simply a speed optimization for large directories.  It doesn't
set a hard limit of any sort.  

Your problem is that you are using the UFS filesystem, which does not allow
more than 32768 subdirectories.  The "number of links" counter in UFS
filesystems is a signed short type, and each subdirectory has to create a
".." link back to the parent directory, so if you try to create more than
32768 subdirectories, it fails because the parent directory would exceed the
maximum link count.

You'll need to either create multiple levels of directories (i.e.  make
directories called 345/678/ instead of 345678/ ), or switch to the zfs
filesystem, which has a much higher limit.  I was able to create 1 million
subdirs as a test, using zsh's brace expansion syntax to generate the
directory names:

(dan@dan) / # zfs create -o mountpoint=/tmp/zz local/zz
(dan@dan) / # cd /tmp/zz
(dan@dan) /tmp/zz/ # for i in {00..99} ; do echo ${i}0000 ; mkdir ${i}{0000..9999} ; done
000000
[..]
990000
(dan@dan) /tmp/zz/ # echo * | wc -w
1000000


-- 
	Dan Nelson
	dnelson@allantgroup.com



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20090911063055.GC37884>