Max. number of opened files, efficiency

Tait freebsd at t41t.com
Sun Aug 17 22:39:44 UTC 2008


> How many files can I open under FreeBSD, at the same time?
> ...
> I tried to open 1000 temporary files and I could do so within one second.
>
> Another interesting (offtopic) question is that I could not open 10 000
> files under Windows XP. Error was "too many open file". How to overcome
> this?

The maximum number of files is controlled by kern.maxfilesperproc in
/etc/sysctl.conf. It appears (on my 7.0 system) that the default is 2599.

The maximum number of files per process for Windows XP is controlled in
stdio.h and is set to 512 (with three eaten by stdin/stdout/stderr). On
earlier versions of Windows, this number was much lower.

The way to "overcome" this is almost always to redesign your
program. You're not spawning 1000 threads (I hope) to write to every file
simultaneously, so you can probably move the open/write/close-file inside
your 1-to-1000 for loop and only need one file open at once, which is
much more reasonable. If the size of your temporary files is small, you
might look at using in-memory variables instead of files.

Tait



More information about the freebsd-questions mailing list