Page MenuHomeFreeBSD

Streamline the operations when acquiring the lock on an INP after a lookup
ClosedPublic

Authored by jtl on Nov 2 2017, 2:42 PM.

Details

Summary

A few of the INP lookup operations that lock INPs after the lookup do so using this mechanism (to maintain lock ordering):

  1. Lock lookup structure.
  2. Find INP.
  3. Acquire reference on INP.
  4. Drop lock on lookup structure.
  5. Acquire INP lock.
  6. Drop reference on INP.

This change provides a slightly shorter path for cases where the INP lock is uncontested:

  1. Lock lookup structure.
  2. Find INP.
  3. Try to acquire the INP lock.
  4. If successful, drop lock on lookup structure.

Of course, if the INP lock is contested, the functions will need to revert to the previous way of switching locks safely.

Test Plan

Tested at high scale with no ill effects.

Diff Detail

Repository
rS FreeBSD src repository
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

jtl created this revision.Nov 2 2017, 2:42 PM
jtl added subscribers: network, gnn.Nov 2 2017, 4:18 PM
jch added a subscriber: jch.Nov 2 2017, 4:49 PM
rwatson requested changes to this revision.Nov 13 2017, 8:03 PM

I like this change, and have not yet spotted any problems with it. The one change I might make is to add a few assertions before the final return(inp) in each case to assert that the held lock matches the requested lock.

This revision now requires changes to proceed.Nov 13 2017, 8:03 PM
jtl updated this revision to Diff 40505.Mar 20 2018, 4:59 PM

Add assertions suggested by @rwatson.

This revision was not accepted when it landed; it landed in state Needs Review.Mar 21 2018, 3:55 PM
This revision was automatically updated to reflect the committed changes.