public inbox for netdev@vger.kernel.org 
 help / color / mirror / Atom feed
From: Krishna Kumar <krkumar2@in•ibm.com>
To: davem@davemloft•net
Cc: netdev@vger•kernel.org, Krishna Kumar <krkumar2@in•ibm.com>
Subject: [PATCH 3/3] tcp: Slightly optimize tcp_sendmsg
Date: Wed, 09 Dec 2009 13:56:24 +0530	[thread overview]
Message-ID: <20091209082624.19055.99645.sendpatchset@localhost.localdomain> (raw)
In-Reply-To: <20091209082613.19055.58864.sendpatchset@localhost.localdomain>

From: Krishna Kumar <krkumar2@in•ibm.com>

Slightly optimize tcp_sendmsg since NETIF_F_SG is used many
times iteratively in the loop. The only other modification is
to change:
			} else if (i == MAX_SKB_FRAGS ||
				   (!i &&
				   !(sk->sk_route_caps & NETIF_F_SG))) {
	to:
			} else if (i == MAX_SKB_FRAGS || !sg) {

Signed-off-by: Krishna Kumar <krkumar2@in•ibm.com>
---
 net/ipv4/tcp.c |   17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

diff -ruNp org/net/ipv4/tcp.c new/net/ipv4/tcp.c
--- org/net/ipv4/tcp.c	2009-12-09 10:01:35.000000000 +0530
+++ new/net/ipv4/tcp.c	2009-12-09 10:26:42.000000000 +0530
@@ -878,12 +878,12 @@ ssize_t tcp_sendpage(struct socket *sock
 #define TCP_PAGE(sk)	(sk->sk_sndmsg_page)
 #define TCP_OFF(sk)	(sk->sk_sndmsg_off)
 
-static inline int select_size(struct sock *sk)
+static inline int select_size(struct sock *sk, int sg)
 {
 	struct tcp_sock *tp = tcp_sk(sk);
 	int tmp = tp->mss_cache;
 
-	if (sk->sk_route_caps & NETIF_F_SG) {
+	if (sg) {
 		if (sk_can_gso(sk))
 			tmp = 0;
 		else {
@@ -907,7 +907,7 @@ int tcp_sendmsg(struct kiocb *iocb, stru
 	struct sk_buff *skb;
 	int iovlen, flags;
 	int mss_now, size_goal;
-	int err, copied;
+	int sg, err, copied;
 	long timeo;
 
 	lock_sock(sk);
@@ -935,6 +935,8 @@ int tcp_sendmsg(struct kiocb *iocb, stru
 	if (sk->sk_err || (sk->sk_shutdown & SEND_SHUTDOWN))
 		goto out_err;
 
+	sg = sk->sk_route_caps & NETIF_F_SG;
+
 	while (--iovlen >= 0) {
 		int seglen = iov->iov_len;
 		unsigned char __user *from = iov->iov_base;
@@ -960,8 +962,9 @@ new_segment:
 				if (!sk_stream_memory_free(sk))
 					goto wait_for_sndbuf;
 
-				skb = sk_stream_alloc_skb(sk, select_size(sk),
-						sk->sk_allocation);
+				skb = sk_stream_alloc_skb(sk,
+							  select_size(sk, sg),
+							  sk->sk_allocation);
 				if (!skb)
 					goto wait_for_memory;
 
@@ -998,9 +1001,7 @@ new_segment:
 					/* We can extend the last page
 					 * fragment. */
 					merge = 1;
-				} else if (i == MAX_SKB_FRAGS ||
-					   (!i &&
-					   !(sk->sk_route_caps & NETIF_F_SG))) {
+				} else if (i == MAX_SKB_FRAGS || !sg) {
 					/* Need to add new fragment and cannot
 					 * do this because interface is non-SG,
 					 * or because all the page slots are

  parent reply	other threads:[~2009-12-09  8:26 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-12-09  8:26 [PATCH 1/3] tcp: Remove check in __tcp_push_pending_frames Krishna Kumar
2009-12-09  8:26 ` [PATCH 2/3] tcp: Remove unrequired operations in tcp_push() Krishna Kumar
2009-12-10  8:10   ` Ilpo Järvinen
2009-12-10  9:06     ` Krishna Kumar2
2009-12-10 10:26       ` Ilpo Järvinen
2009-12-10 11:59         ` Krishna Kumar2
2009-12-10 12:03           ` Ilpo Järvinen
2009-12-09  8:26 ` Krishna Kumar [this message]
2009-12-10  8:17   ` [PATCH 3/3] tcp: Slightly optimize tcp_sendmsg Ilpo Järvinen
2009-12-10 10:29     ` Krishna Kumar2
2009-12-10 10:42       ` Ilpo Järvinen
2009-12-10  8:05 ` [PATCH 1/3] tcp: Remove check in __tcp_push_pending_frames Ilpo Järvinen
2009-12-23 22:15 ` David Miller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20091209082624.19055.99645.sendpatchset@localhost.localdomain \
    --to=krkumar2@in$(echo .)ibm.com \
    --cc=davem@davemloft$(echo .)net \
    --cc=netdev@vger$(echo .)kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox