Page MenuHomeFreeBSD

kqueue: simplify knote_fdclose() and avoid a possible fork-deadlock
ClosedPublic

Authored by kevans on Wed, Apr 1, 3:08 AM.
Tags
None
Referenced Files
F151092006: D56210.id174710.diff
Sun, Apr 5, 11:32 PM
F150995733: D56210.diff
Sun, Apr 5, 9:02 AM
Unknown Object (File)
Sat, Apr 4, 11:47 PM
Unknown Object (File)
Thu, Apr 2, 8:49 PM
Unknown Object (File)
Thu, Apr 2, 1:15 PM
Unknown Object (File)
Thu, Apr 2, 11:44 AM
Subscribers

Details

Summary

kqueue_fork_copy() is likely to have transitioned at least one knote
through a flux state, so it's worth checking whether we need to wake
anything up on the way out.

The influx logic in knote_fdclose() is a little misguided, the resulting
wakeup() call should always be redundant: knote_drop_detached() will
always issue a wakeup before it returns, so anything waiting on *that*
knote that had entered fluxwait should have been woken up then. This is
the obvious divergence from the other influx/wakeup pattern in the
implementation, which will kn_influx-- and then issue the wakeup after
it has processed all of the knotes it can make progress on.

While we're here, the kq_knlist cannot shrink, so we can avoid that
condition in the loop and avoid potentially excessive wakeups from
fluxwait on kqueues that we didn't touch.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

kevans requested review of this revision.Wed, Apr 1, 3:08 AM

I think that kqueue_fork_copy() should be committed separately (no need for the new review, I am only asking for splitting the commit).

This revision is now accepted and ready to land.Wed, Apr 1, 3:30 AM
In D56210#1285782, @kib wrote:

I think that kqueue_fork_copy() should be committed separately (no need for the new review, I am only asking for splitting the commit).

Sure, I'll split the commit message the sensible way (with the first paragraph re-worded slightly):

kqueue: avoid a possible fork-deadlock

kqueue_fork_copy() is likely to have transitioned at least one knote
through a flux state, so we should check whether we need to wake
anything up on the way out to avoid a possible deadlock.