On Sat, Oct 31, 2015 at 02:23:31PM -0700, Linus Torvalds wrote:
The other stuff we probably can't do all that much about. Unless we
decide to go for some complicated lockless optimistic file descriptor
allocation scheme with retry-on-failure instead of locks. Which I'm
sure is possible, but I'm equally sure is painful.
The interesting part is dup2() - we'd have to do something like
serialize against other dup2
was_claimed = atomically set and test bit in bitmap
if was_claimed
tofree = fdt->fd[fd];
if (!tofree)
fail with EBUSY
install into ->fd[...]
end of critical area
in there; __alloc_fd() could be made retry-on-failure, but I don't see
how to cope with dup2 vs. dup2 without an explicit exclusion.