Benjamin LaHaise a écrit : > On Tue, Sep 13, 2005 at 09:04:32AM +0200, Eric Dumazet wrote: > >>I wish a process param could allow open() to take any free fd available, >>not the lowest one. One can always use fcntl(fd, F_DUPFD, slot) to move a >>fd on a specific high slot and always keep the 64 first fd slots free to >>speedup the kernel part at open()/dup()/socket() time. > > > The overhead is easy to avoid by making use of dup2() and close() to keep > the lowest file descriptors in the table free, allowing open() and socket() > to always return 3 or 4. Yes, this is what I described :) Maybe this was not clear. > > Alternatively, the kernel could track available file descriptors using a > tree to efficiently insert freed slots into an ordered list of free > regions (something similar to the avl tree used in vmas). Is it worth > doing? Well no, since a user app can manage itself this part if it happens to be performance critical. Sample of a user land lib : Each time a new fd is returned by open()/socket()/pipe()/accept()... the thread should call fd = fdcache_dupfd(fd); And close the file using fdcache_closefd(fd) instead of close(fd); Eric