I’m writing a program using epoll_wait to wait for file descriptors on 64-bit Linux, and I try to put some information together with the file descriptor in the epoll_event user data.
I know in practice it’s unlikely that file descriptor will exceed 32 bits. Just wanna know is that kernel guarantees that file descriptors have a specific range, or it just counts from small and unlikely to get very big?
The
epoll_ctl(2)interface to add new filedescriptors takes anint fdargument, so you’re already limited to 32-bit range (at least on the Linux platforms I’m familiar with).You’re further limited by
/proc/sys/fs/file-maxsystem-wide limit on the number of open files for all processes;/proc/sys/fs/file-maxis currently595956on my system.Each process is further limited via the
setrlimit(2)RLIMIT_NOFILEper-process limit on the number of open files. 1024 is a commonRLIMIT_NOFILElimit. (It’s very easy to change this limit via/etc/security/limits.conf.)It’s a rare application that needs more than 1024. The full 32 bits seems unlikely as well, since each open file will take some kernel memory to represent — four billion ~280 byte
struct inodestructures (at the minimum) is a lot of pinned memory.