sysctl maxfiles

Oliver Fromme olli at lurza.secnetix.de
Sat Sep 27 21:41:14 UTC 2008


Miroslav Lachman wrote:
 > I don't know what files are "really" open in the meaning of 
 > kern.maxfiles. I have webserver with about 100 hosted domains and there 
 > is some numbers:
 > 
 > root at roxy ~/# fstat -u www | wc -l
 >      9931
 > root at roxy ~/# fstat -u root | wc -l
 >       718
 > root at roxy ~/# fstat | grep httpd | wc -l
 >      6379
 > root at roxy ~/# fstat | grep httpd | wc -l
 >      6002
 > root at roxy ~/# fstat -u www | wc -l
 >      4691
 > root at roxy ~/# sysctl kern.openfiles
 > kern.openfiles: 846
 > 
 > All above taken within few seconds.
 > 
 > Can somebody explain the difference between kern.openfiles and fstat?

Those are different things:  fstat lists file descriptors,
while kern.openfiles counts open file objects, which are
often shared among processes.

For example, when the apache master process forks its
children, the children inherit the open file objects from
the parent process.  While every child has its own set of
file descriptors (listed separately by fstat), they
reference the same underlying open file objects, so they
don't contribute separately to kern.openfiles.

In the same way, fstat lists stdin + stdout + stderr for
almost every process, but in most cases they are not
separate file objects because they were inherited from the
parent process.

Best regards
   Oliver

-- 
Oliver Fromme, secnetix GmbH & Co. KG, Marktplatz 29, 85567 Grafing b. M.
Handelsregister: Registergericht Muenchen, HRA 74606,  Geschäftsfuehrung:
secnetix Verwaltungsgesellsch. mbH, Handelsregister: Registergericht Mün-
chen, HRB 125758,  Geschäftsführer: Maik Bachmann, Olaf Erb, Ralf Gebhart

FreeBSD-Dienstleistungen, -Produkte und mehr:  http://www.secnetix.de/bsd

"In My Egoistical Opinion, most people's C programs should be indented
six feet downward and covered with dirt."
        -- Blair P. Houghton


More information about the freebsd-stable mailing list