Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

"Too many open files in system" -- Understanding /proc/sys/fs/file-nr

48 views
Skip to first unread message

Doug Simpson

unread,
Aug 10, 2001, 1:47:09 PM8/10/01
to
After reading several posts just now and running some tests under 7.0,
I have a much better understanding of how to increase the maximum
number of open files and how to monitor the usage of this resource.

As many folks pointed out, increasing max open files is easy:

# echo 5000 > /proc/sys/fs/file-max

will set the max open files to 5000.

As others pointed out, another useful file is /proc/sys/fs/file-nr.
Here's a view this file on my system, before and after changing
file-max:

# cat /proc/sys/fs/file-nr
4096 1703 4096
# echo 5000 > /proc/sys/fs/file-max
# cat /proc/sys/fs/file-nr
4096 1703 5000

The three numbers in file-nr are most-files-ever-opened,
#-files-available-for-opening, and max-open-files (from file-max). Or
so I thought. The left and right numbers are defined correctly, but
the middle number is not so simple.

If max-open-files increased from 4096 to 5000, why did the middle
number not increase by the same amount? To investigate, I used Expect
to spawn a bunch of processes, each of which consumed 25 or so files:

Expect> while 1 {puts [exec cat /proc/sys/fs/file-max]; spawn bash}

At first, the middle number counted down from 1703 by 25s. When it
reached 10, the left number started counting up by 25s. Then the
middle number would go up a little and down a little, hovering mostly
around 10 or 11. Loop finally failed with "Too many files in system."

Final view of /proc/sys/fs/file-nr after exiting Expect (which freed
up all those files):

5000 2607 5000

Once you force the number of open files to top out, the left and right
numbers will be the same. Only then, will the middle number be the
number of files available to be opened. In general, though,

number-of-open-files = left - middle

number-of-files-available-for-opening = right -
number-of-open-files
= right - left + middle

And this is the number you really need to know.

This is my first post to a newsgroup! Please let me know if this
article was useful to you.

Konrad Michels

unread,
Aug 13, 2001, 7:24:25 AM8/13/01
to
Damn useful post Doug! I'm sure though, that there is a way to have
file-max pre-set to a higher number by altering a parameter in one of
the kernel's include files before compiling. As you know, changing
parameters in the proc file system only lasts until the next reboot.

You could probably set it from rc.local, but its still not as neat as
having it hard-coded.

Maybe someone can enlighten us on which parameter in which include file
we would need to be changing?

Later
Konrad

Radek Bochenek

unread,
Aug 15, 2001, 8:35:02 PM8/15/01
to
Konrad Michels <kon...@overnetdata.com> wrote:
> Maybe someone can enlighten us on which parameter in which include file
> we would need to be changing?

I believe it is _not a good idea_. Someone put it in procfs to allow
changing in an easy way instead of alerting kernel sources. I would
prefer to put command in initscripts if you want to make them permanent
(well not actually :)).

Additional documents that might help understanding file-nr (in kernel
source tree):
Documentation/sysctl/fs.txt
Documentation/filesystems/proc.txt

--
(( e-signature ))
( e-name: Radek Bochenek )
( e-mail: rad.n...@irc.pl )
( e-hint: delete '.nospam' )

0 new messages