Does OpenBSD have a limit to the number of file descriptors

file-descriptorslimitopenbsd

What's the maximum number of file descriptors that a process can get on OpenBSD successfully?

For example, there is an openfiles limit in login.conf(5) in OpenBSD. If I want to have as many file descriptors as possible, but still don't let a runaway process to bog down the system, what would be a sensible value to set?

E.g. if I specify, say, 20000, will the kernel be capable of giving my application all of these 20000 FDs? What if I'm running multiple instances of a given application (e.g. multiple worker processes)?

Best Answer

Taking a look at the source code, to get the default value of max open files:

Well documented code

extern int maxfiles;                 /* kernel limit on number of open files */

maxfiles, on param.c defines the formula to maxfiles

int maxfiles = 5 * (NPROCESS + MAXUSERS) + 80;

OK, we found it.

NPROCESS =

#define NPROCESS (30 + 16 * MAXUSERS)

MAXUSERS = - Lets take amd64 architecture as an example:

machine         amd64
include         "../../../conf/GENERIC"
maxusers        80                      # estimated number of users

Lets sum all the stuff:

maxfiles = 5 * ((30 + 16 * 80) + 80) + 80
maxfiles = 5 * ((30 + 1280) + 80) + 80
maxfiles = 5 * (1390) + 80
maxfiles = 6950 + 80
maxfiles = 7030

To increase the total of max open files, you will need first of all to increase the max open files kernel limit with sysctl kern.maxfiles=20000 and increase the number of files a process/user can open, editing login.conf. This Tor daemon setup have both examples for you.

Related Question