In linux_close.c - and similarily in bsd_close.c and aix_close.c - an array (fdTable) is used to keep an information record and a mutex per opened file descriptor. This array gets allocated at the start of the process.
In order to guess on the size of the table, getrlimit(RLIMIT_NO_FILE) is used.
There are some problems with this approach:
1) There is no handling for an infinite limit. Depending on what the numerical value is for RLIM_INFINITY, allocation of the file descriptor table may fail at this point (RLIM_INFINITY=-1) or be very small (RLIM_INFINITY=0). This may lead to file descriptors not covered by the whole wakeup mechanism implemented in this file, and hence to hanging threads.
2) For large - but not infinite - values of RLIMIT_NO_FILE, the memory usage is excessive. On Linux x64, each entry in the table is ~ 50Bytes; for a limit of 1000000, this eats up 50MB. Most of this memory is usually never used.