Can FD_SETSIZE be increased to more than 1024?

Solution Verified - Updated -

Environment

  • Red Hat Enterprise Linux 10
  • Red Hat Enterprise Linux 9
  • Red Hat Enterprise Linux 8
  • Red Hat Enterprise Linux 7
  • Red Hat Enterprise Linux 6

Issue

  • What is FD_SETSIZE and what's used for?
  • When using GNU C Library's select(), is it possible to increase FD_SETSIZE to more than 1024?

Resolution

  • As per the GNU C Library 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, consider using poll() or epoll() interfaces, 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 or libevents to select() what's limited by the FD_SETSIZE in order to make their application more flexible and robust.

Diagnostic Steps

  • FD_SETSIZE in definied in the header file /usr/include/bits/typesizes.h, from glibc-headers package in RHEL9 and glibc-devel in RHEL10:

    # rpm -qf /usr/include/bits/typesizes.h --queryformat "%{NAME}\n"
    glibc-headers
    
    # grep -B1 "FD_SETSIZE" /usr/include/bits/typesizes.h
    /* Number of descriptors that can fit in an `fd_set'.  */
    #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