[erlang-questions] clipping of max# of file descriptors by erts when kernel poll is enabled

Joel Reymont joelr1@REDACTED
Fri Aug 22 19:56:46 CEST 2008

I believe there's a "bug" in the current implementation of  
erts_poll_init in erts/emulator/sys/common/erl_poll.c. This bug  
prevents Erlang from using more than 1024 file descriptors regardless  
of whether kernel poll is available and used.

This happens on Mac OSX Leopard but should affect other platforms as  

This is the relevant chunk of code from erts/emulator/sys/common/ 

     if (max_fds > FD_SETSIZE)
         max_fds = FD_SETSIZE;

ERTS will successfully grab the maximum # of open files from the  
kernel so long as SYSCONF is present, i.e.

     max_fds = sysconf(_SC_OPEN_MAX);

What happens then is that even if kernell poll is enabled, the maximum  
number of file descriptors (max_fds) gets clipped to FD_SETSIZE, 1024  
on Mac OSX Leopard.

The code needs to look like this instead:

#if ERTS_POLL_USE_SELECT && defined(FD_SETSIZE) && ! 
     if (max_fds > FD_SETSIZE)
         max_fds = FD_SETSIZE;

ERTS appears to compile erl_poll.c twice, with and without kernell  
poll enabled. It then uses erts_poll_init_kp (kpoll) or  
erts_poll_init_nkp, depending on whether -K true was given.

I believe that the lack of && !ERTS_POLL_USE_KERNEL_POLL above is just  
oversight and no harm is caused by adding it.

	Thanks, Joel


More information about the erlang-questions mailing list