]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/commit
If the INP lock is uncontested, avoid taking a reference and jumping
authorjtl <jtl@FreeBSD.org>
Wed, 21 Mar 2018 15:54:46 +0000 (15:54 +0000)
committerjtl <jtl@FreeBSD.org>
Wed, 21 Mar 2018 15:54:46 +0000 (15:54 +0000)
commitee029a5d0be42ce6d5988e8ac031f60c38c9edb8
treee56ec7b912bf2723597d68983ee4817f1ee6446a
parent77f4d6e93205782a0925190c620bcc2696ec4f23
If the INP lock is uncontested, avoid taking a reference and jumping
through the lock-switching hoops.

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.

This saves a few atomic operations when the INP lock is uncontested.

Discussed with: gallatin, rrs, rwatson
MFC after: 2 weeks
Sponsored by: Netflix, Inc.
Differential Revision: https://reviews.freebsd.org/D12911
sys/netinet/in_pcb.c
sys/netinet6/in6_pcb.c