Can FD_SETSIZE be increased to more than 1024?
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_SETSIZEand what's used for? - When using GNU C Library's
select(), is it possible to increaseFD_SETSIZEto 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_SETSIZEis hardcoded to 1024 in/usr/include/bits/typesizes.hand can not be changed. -
As a workaround, consider using
poll()orepoll()interfaces, instead ofselect().
Root Cause
- It's the responsibility of application vendors to make sure alternatives are available in their code, such as using
epollorlibeventstoselect()what's limited by theFD_SETSIZEin order to make their application more flexible and robust.
Diagnostic Steps
-
FD_SETSIZEin definied in the header file/usr/include/bits/typesizes.h, fromglibc-headerspackage in RHEL9 andglibc-develin 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