Skip to content

Commit

Permalink
[AF_UNIX]: Remove superfluous reference counting in unix_stream_sendmsg
Browse files Browse the repository at this point in the history
AF_UNIX stream socket performance on P4 CPUs tends to suffer due to a
lot of pipeline flushes from atomic operations.  The patch below
removes the sock_hold() and sock_put() in unix_stream_sendmsg().  This
should be safe as the socket still holds a reference to its peer which
is only released after the file descriptor's final user invokes
unix_release_sock().  The only consideration is that we must add a
memory barrier before setting the peer initially.

Signed-off-by: Benjamin LaHaise <benjamin.c.lahaise@intel.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Benjamin LaHaise authored and David S. Miller committed Jan 3, 2006
1 parent c1cbe4b commit 830a1e5
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions net/unix/af_unix.c
Original file line number Diff line number Diff line change
Expand Up @@ -1063,10 +1063,12 @@ static int unix_stream_connect(struct socket *sock, struct sockaddr *uaddr,
/* Set credentials */
sk->sk_peercred = other->sk_peercred;

sock_hold(newsk);
unix_peer(sk) = newsk;
sock->state = SS_CONNECTED;
sk->sk_state = TCP_ESTABLISHED;
sock_hold(newsk);

smp_mb__after_atomic_inc(); /* sock_hold() does an atomic_inc() */
unix_peer(sk) = newsk;

unix_state_wunlock(sk);

Expand Down Expand Up @@ -1414,7 +1416,7 @@ static int unix_stream_sendmsg(struct kiocb *kiocb, struct socket *sock,
} else {
sunaddr = NULL;
err = -ENOTCONN;
other = unix_peer_get(sk);
other = unix_peer(sk);
if (!other)
goto out_err;
}
Expand Down Expand Up @@ -1476,7 +1478,6 @@ static int unix_stream_sendmsg(struct kiocb *kiocb, struct socket *sock,
other->sk_data_ready(other, size);
sent+=size;
}
sock_put(other);

scm_destroy(siocb->scm);
siocb->scm = NULL;
Expand All @@ -1491,8 +1492,6 @@ static int unix_stream_sendmsg(struct kiocb *kiocb, struct socket *sock,
send_sig(SIGPIPE,current,0);
err = -EPIPE;
out_err:
if (other)
sock_put(other);
scm_destroy(siocb->scm);
siocb->scm = NULL;
return sent ? : err;
Expand Down

0 comments on commit 830a1e5

Please sign in to comment.