OpenBSD file descriptor limits

Are you seeing messages like this in your logs?:

error: can't create socket: Too many open files

OpenBSD seems to come configured by default with a really low file descriptor limit (128) so increasing it is needed for daemons which are going to open a lot of network connections.

The limits are configured in two places; the system global limit (total files open by all processes) is set in a sysctl:

sysctl kern.maxfiles=7030

The per-login/process limits are set via /etc/login.conf via the openfiles directive. This is further split into openfiles-cur and openfiles-max (current, e.g. the initial value for a new login, and maximum, which is the largest value you can then increase the limit to using ulimit -n)

E.g.

default:\
...
:openfiles-cur=1024:\
:openfiles-max=4096:\
...

daemon:\
...
:openfiles=4096:\
...

Would set a limit of file descriptors for daemons (started by root, or via /etc/rc) of 4096 initial, 4096 maximum and for all otherwise unclassified users to 1024 initial and 4096 maximum. Settings take effect on next login.

For performance you can compile /etc/login.conf into a database using cap_mkdb, e.g.:

cap_mkdb /etc/login.conf
Advertisements