Skip to content

Commit

Permalink
af_unix: optimize unix_dgram_poll()
Browse files Browse the repository at this point in the history
unix_dgram_poll() is pretty expensive to check POLLOUT status, because
it has to lock the socket to get its peer, take a reference on the peer
to check its receive queue status, and queue another poll_wait on
peer_wait. This all can be avoided if the process calling
unix_dgram_poll() is not interested in POLLOUT status. It makes
unix_dgram_recvmsg() faster by not queueing irrelevant pollers in
peer_wait.

On a test program provided by Alan Crequy :

Before:

real    0m0.211s
user    0m0.000s
sys     0m0.208s

After:

real    0m0.044s
user    0m0.000s
sys     0m0.040s

Suggested-by: Davide Libenzi <davidel@xmailserver.org>
Reported-by: Alban Crequy <alban.crequy@collabora.co.uk>
Acked-by: Davide Libenzi <davidel@xmailserver.org>
Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Eric Dumazet authored and David S. Miller committed Nov 8, 2010
1 parent 5456f09 commit 973a34a
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions net/unix/af_unix.c
Original file line number Diff line number Diff line change
Expand Up @@ -2091,6 +2091,10 @@ static unsigned int unix_dgram_poll(struct file *file, struct socket *sock,
return mask;
}

/* No write status requested, avoid expensive OUT tests. */
if (wait && !(wait->key & (POLLWRBAND | POLLWRNORM | POLLOUT)))
return mask;

writable = unix_writable(sk);
other = unix_peer_get(sk);
if (other) {
Expand Down

0 comments on commit 973a34a

Please sign in to comment.