Can FD_SETSIZE be increased to more than 1024?

Solution Verified - Updated -

Environment

  • Red Hat Enterprise Linux 7
  • Red Hat Enterprise Linux 6

Issue

  • When using glibc select(), is it possible to increase FD_SETSIZE to more than 1024?
  • What is FD_SETSIZE?

Resolution

  • As per the glibc documentation:
Macro: int FD_SETSIZE

    The value of this macro is the maximum number of file descriptors that a fd_set object can hold information about. On systems with a fixed maximum number, FD_SETSIZE is at least that number. On some systems, including GNU, there is no absolute limit on the number of descriptors open, but this macro still has a constant value which controls the number of bits in an fd_set; if you get a file descriptor with a value as high as FD_SETSIZE, you cannot put that descriptor into an fd_set. 
  • FD_SETSIZE is hardcoded to 1024 in /usr/include/bits/typesizes.h and can not be changed.
  • As a workaround, poll() or epoll() can be used instead of select().

Root Cause

  • It's the responsibility of application vendors to make sure alternatives are available in their code (such as using epoll/libevents) to select() what's limited by the FD_SETSIZE in order to make their application more flexible and robust.

Diagnostic Steps

  • Red Hat Enterprise Linux 7
$ rpm -qf /usr/include/bits/typesizes.h 
glibc-headers-2.17-157.el7_3.1.x86_64

$ vi /usr/include/bits/typesizes.h +/FD_SET
 85 /* Number of descriptors that can fit in an `fd_set'.  */
 86 #define __FD_SETSIZE            1024
  • Red Hat Enterprise Linux 6
$ rpm -qf /usr/include/bits/typesizes.h 
glibc-headers-2.12-1.209.el6_9.1.x86_64

$ vi /usr/include/bits/typesizes.h +/FD_SET
 62 /* Number of descriptors that can fit in an `fd_set'.  */
 63 #define __FD_SETSIZE            1024

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.

Comments