From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753154Ab0J3Jxu (ORCPT ); Sat, 30 Oct 2010 05:53:50 -0400 Received: from mail-ww0-f44.google.com ([74.125.82.44]:48740 "EHLO mail-ww0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751967Ab0J3Jxr (ORCPT ); Sat, 30 Oct 2010 05:53:47 -0400 DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=subject:from:to:cc:in-reply-to:references:content-type:date :message-id:mime-version:x-mailer:content-transfer-encoding; b=CTgKJpI2NMRuTtWys4mYoiL/Hqxc5pgEtSfOQWCIdrxZC9B9k/3gFFvxXWCcXOapJI RVnYJQbMbFxkgRrhlcTKA/IhTv2zNtq8KmcgMcNIVlDZ/zYoUlGwDXETHkfnw3WE6XzH 5jfxynvMaolibmeCqdgUzTj7Mqk9jrNrXv//s= Subject: [PATCH] af_unix: optimize unix_dgram_poll() From: Eric Dumazet To: Davide Libenzi Cc: Alban Crequy , "David S. Miller" , Stephen Hemminger , Cyrill Gorcunov , Alexey Dobriyan , netdev@vger.kernel.org, Linux Kernel Mailing List , Pauli Nieminen , Rainer Weikusat In-Reply-To: References: <20101029191857.5f789d56@chocolatine.cbg.collabora.co.uk> <1288380431.2680.3.camel@edumazet-laptop> Content-Type: text/plain; charset="UTF-8" Date: Sat, 30 Oct 2010 11:53:40 +0200 Message-ID: <1288432420.2680.933.camel@edumazet-laptop> Mime-Version: 1.0 X-Mailer: Evolution 2.30.3 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Le vendredi 29 octobre 2010 à 13:46 -0700, Davide Libenzi a écrit : > Also, why not using the existing wait->key instead of adding a poll2()? Indeed, if wait is not null, we have in wait->key the interest of poller. If a particular poll() function is expensive, it can test these bits. Thanks ! Note: I chose the 'goto skip_write' to make this patch really obvious. [PATCH] af_unix: optimize unix_dgram_poll() 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 Reported-by: Alban Crequy Signed-off-by: Eric Dumazet --- net/unix/af_unix.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c index 3c95304..dcb84fe 100644 --- a/net/unix/af_unix.c +++ b/net/unix/af_unix.c @@ -2090,6 +2090,9 @@ static unsigned int unix_dgram_poll(struct file *file, struct socket *sock, return mask; } + if (wait && !(wait->key & (POLLWRBAND | POLLWRNORM | POLLOUT))) + goto skip_write; + /* writable? */ writable = unix_writable(sk); if (writable) { @@ -2111,6 +2114,7 @@ static unsigned int unix_dgram_poll(struct file *file, struct socket *sock, else set_bit(SOCK_ASYNC_NOSPACE, &sk->sk_socket->flags); +skip_write: return mask; }