Re: spinlock contention of files->file_lock

From: Al Viro
Date: Mon Sep 30 2013 - 21:54:31 EST


On Mon, Sep 30, 2013 at 06:05:03PM -0700, Eric Dumazet wrote:
> Speaking of spinlock contention, the files->file_lock is a good example.
>
> Multi threaded programs hit this spinlock three times per fd :
>
> alloc_fd() / fd_install() / close()
>
> I think fd_install() could be done without this spinlock.

The problem is dup2(), not table resize... I'm not saying it can't be
done, but it won't be trivial and you seem to be looking for potential
trouble in the wrong place. dup2() semantics is the real bitch.
What we want is
* dup2() over unused descriptor => insert and be done with that
* dup2() over opened one => replace and do equivalent of close()
for what had been there before
The trouble is, what to do with dup2() over reserved, but still not
installed descriptor? We handle that as -EBUSY and we use ->file_lock
to get atomicity wrt transitions between those states.

And yes, dup2() is a lousy API in multithreaded situation. It's still
there... See comments in do_dup2() for some amusement.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/