Skip to content

Commit fd19f32

Browse files
bcrldavem330
authored andcommitted
[AF_UNIX]: Convert to use a spinlock instead of rwlock
From: Benjamin LaHaise <[email protected]> In af_unix, a rwlock is used to protect internal state. At least on my P4 with HT it is faster to use a spinlock due to the simpler memory barrier used to unlock. This patch raises bw_unix to ~690K/s. Signed-off-by: David S. Miller <[email protected]>
1 parent 4947d3e commit fd19f32

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

include/net/af_unix.h

+5-5
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,10 @@ struct unix_skb_parms {
5858
#define UNIXCB(skb) (*(struct unix_skb_parms*)&((skb)->cb))
5959
#define UNIXCREDS(skb) (&UNIXCB((skb)).creds)
6060

61-
#define unix_state_rlock(s) read_lock(&unix_sk(s)->lock)
62-
#define unix_state_runlock(s) read_unlock(&unix_sk(s)->lock)
63-
#define unix_state_wlock(s) write_lock(&unix_sk(s)->lock)
64-
#define unix_state_wunlock(s) write_unlock(&unix_sk(s)->lock)
61+
#define unix_state_rlock(s) spin_lock(&unix_sk(s)->lock)
62+
#define unix_state_runlock(s) spin_unlock(&unix_sk(s)->lock)
63+
#define unix_state_wlock(s) spin_lock(&unix_sk(s)->lock)
64+
#define unix_state_wunlock(s) spin_unlock(&unix_sk(s)->lock)
6565

6666
#ifdef __KERNEL__
6767
/* The AF_UNIX socket */
@@ -76,7 +76,7 @@ struct unix_sock {
7676
struct sock *other;
7777
struct sock *gc_tree;
7878
atomic_t inflight;
79-
rwlock_t lock;
79+
spinlock_t lock;
8080
wait_queue_head_t peer_wait;
8181
};
8282
#define unix_sk(__sk) ((struct unix_sock *)__sk)

net/unix/af_unix.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,7 @@ static struct sock * unix_create1(struct socket *sock)
564564
u = unix_sk(sk);
565565
u->dentry = NULL;
566566
u->mnt = NULL;
567-
rwlock_init(&u->lock);
567+
spin_lock_init(&u->lock);
568568
atomic_set(&u->inflight, sock ? 0 : -1);
569569
init_MUTEX(&u->readsem); /* single task reading lock */
570570
init_waitqueue_head(&u->peer_wait);

0 commit comments

Comments
 (0)