[clug] nr-file question

Peter Barker pbarker at barker.dropbear.id.au
Sat Oct 23 22:33:11 GMT 2004

On Sun, 24 Oct 2004, Andrew wrote:

> The kernel documents say that the first value of file-nr (from sysctl
> -a) is dynamically set by the kernel (up to a maxium of the third
> value).  Am I correct to assume that if the second value goes close to
> the first, then the first will raise automatically without giving
> errors? Or is there some intervention required on my part?  I am trying
> to work out why a system I am looking after sometimes gives "Too many
> files open" errors in php -  There seems to be a huge capacity here?

You might like to look in
/usr/src/linux/Documentation/filesystems/proc.txt; search for file-nr:

The three  values  in file-nr denote the number of allocated file handles,
number of  used file handles, and the maximum number of file handles. When
allocated file  handles  come close to the maximum, but the number of
used ones  is  far  behind,  you've  encountered  a peak in your usage of
handles and you don't need to increase the maximum.

> fs.file-nr = 2264       425     104032

> Any thoughts?

Yes, that's a whole heap of filehandles you allow on your system. You
/can/ raise that by poking new values into /proc/sys/fs/file-max, but
that's not your problem here :)

You possibly have two problems here.

The first is that you're possibly leaking file descriptiors; 2264 is a
whole heap. /Should/ your application have that many open? If your
application is long lived (php indicates it probably is), then over many
runnings of your script in the same process a fdile descriptor leak is
cumulative. What this basically means is - look for an open(...)
unbalanced by a close(...). Failing finding one of those, socket() calls
and various other bits and pieces will allocate file descriptors.

At a guess, the limit you are hitting is the per-process file desciptor
limit. Type "ulimit -a" in a shell and it will give you what your
/shell's/ per-process limits are (they might be different for your
script). open-files is what you're looking at.

Oh, one more thing; while the process is running, /proc/<pid>/fd contains
a list of descriptors this process has open (also, /proc/self/pid, which
is handy for self-diagnosis :)).

> Andrew.

Peter Barker                          |   N    _--_|\ /---- Barham, Vic
Programmer,Sysadmin,Geek              | W + E /     /\
pbarker at barker.dropbear.id.au         |   S   \_,--?_*<-- Canberra
You need a bigger hammer.             |             v    [35S, 149E]
Thu Jan  8 12:27:35 2004  	nigelw - Comments added
[pbarker - Wed Jan  7 18:23:13 2004]:
> You are in a maze of twisty semantics. You have: a hammer.
You miss the semantic. \The semantic hits you. \You are permenantly confused.

More information about the linux mailing list