netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 2/3 Ver2] tcp: Remove unrequired operations in tcp_push()
@ 2009-12-10 17:16 Krishna Kumar
  2009-12-10 17:16 ` [PATCH 3/3 Ver2] tcp: Slightly optimize tcp_sendmsg Krishna Kumar
  2009-12-23 22:15 ` [PATCH 2/3 Ver2] tcp: Remove unrequired operations in tcp_push() David Miller
  0 siblings, 2 replies; 4+ messages in thread
From: Krishna Kumar @ 2009-12-10 17:16 UTC (permalink / raw)
  To: davem; +Cc: netdev, Krishna Kumar

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

Remove unrequired operations in tcp_push()

Changelog:
	Removed a temporary skb variable from tcp_push()

Signed-off-by: Krishna Kumar <krkumar2@in.ibm.com>
Acked-by: Ilpo Järvinen <ilpo.jarvinen@helsinki.fi>
---
 net/ipv4/tcp.c |   13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

diff -ruNp org/net/ipv4/tcp.c new/net/ipv4/tcp.c
--- org/net/ipv4/tcp.c	2009-12-10 21:12:15.000000000 +0530
+++ new/net/ipv4/tcp.c	2009-12-10 21:22:41.000000000 +0530
@@ -536,8 +536,7 @@ static inline void skb_entail(struct soc
 		tp->nonagle &= ~TCP_NAGLE_PUSH;
 }
 
-static inline void tcp_mark_urg(struct tcp_sock *tp, int flags,
-				struct sk_buff *skb)
+static inline void tcp_mark_urg(struct tcp_sock *tp, int flags)
 {
 	if (flags & MSG_OOB)
 		tp->snd_up = tp->write_seq;
@@ -546,13 +545,13 @@ static inline void tcp_mark_urg(struct t
 static inline void tcp_push(struct sock *sk, int flags, int mss_now,
 			    int nonagle)
 {
-	struct tcp_sock *tp = tcp_sk(sk);
-
 	if (tcp_send_head(sk)) {
-		struct sk_buff *skb = tcp_write_queue_tail(sk);
+		struct tcp_sock *tp = tcp_sk(sk);
+
 		if (!(flags & MSG_MORE) || forced_push(tp))
-			tcp_mark_push(tp, skb);
-		tcp_mark_urg(tp, flags, skb);
+			tcp_mark_push(tp, tcp_write_queue_tail(sk));
+
+		tcp_mark_urg(tp, flags);
 		__tcp_push_pending_frames(sk, mss_now,
 					  (flags & MSG_MORE) ? TCP_NAGLE_CORK : nonagle);
 	}

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 3/3 Ver2] tcp: Slightly optimize tcp_sendmsg
  2009-12-10 17:16 [PATCH 2/3 Ver2] tcp: Remove unrequired operations in tcp_push() Krishna Kumar
@ 2009-12-10 17:16 ` Krishna Kumar
  2009-12-23 22:16   ` David Miller
  2009-12-23 22:15 ` [PATCH 2/3 Ver2] tcp: Remove unrequired operations in tcp_push() David Miller
  1 sibling, 1 reply; 4+ messages in thread
From: Krishna Kumar @ 2009-12-10 17:16 UTC (permalink / raw)
  To: davem; +Cc: netdev, Krishna Kumar

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) {

The reason why this change is correct: this code (other than
the MAX_SKB_FRAGS case) executes only due to the else part
of: "if (skb_tailroom(skb) > 0) {" - i.e. there was no space
in the skb to put the data inline. Hence SG is false is a
sufficient condition, and there is no way a fragment can be
added to the skb.

Changelog:
	- Added the above explanation for the change

Signed-off-by: Krishna Kumar <krkumar2@in.ibm.com>
Acked-by: Ilpo Järvinen <ilpo.jarvinen@helsinki.fi>
---
 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-10 21:22:41.000000000 +0530
+++ new/net/ipv4/tcp.c	2009-12-10 21:32:06.000000000 +0530
@@ -876,12 +876,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 {
@@ -905,7 +905,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);
@@ -933,6 +933,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;
@@ -958,8 +960,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;
 
@@ -996,9 +999,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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 2/3 Ver2] tcp: Remove unrequired operations in tcp_push()
  2009-12-10 17:16 [PATCH 2/3 Ver2] tcp: Remove unrequired operations in tcp_push() Krishna Kumar
  2009-12-10 17:16 ` [PATCH 3/3 Ver2] tcp: Slightly optimize tcp_sendmsg Krishna Kumar
@ 2009-12-23 22:15 ` David Miller
  1 sibling, 0 replies; 4+ messages in thread
From: David Miller @ 2009-12-23 22:15 UTC (permalink / raw)
  To: krkumar2; +Cc: netdev

From: Krishna Kumar <krkumar2@in.ibm.com>
Date: Thu, 10 Dec 2009 22:46:52 +0530

> From: Krishna Kumar <krkumar2@in.ibm.com>
> 
> Remove unrequired operations in tcp_push()
> 
> Changelog:
> 	Removed a temporary skb variable from tcp_push()
> 
> Signed-off-by: Krishna Kumar <krkumar2@in.ibm.com>
> Acked-by: Ilpo Järvinen <ilpo.jarvinen@helsinki.fi>

Applied.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 3/3 Ver2] tcp: Slightly optimize tcp_sendmsg
  2009-12-10 17:16 ` [PATCH 3/3 Ver2] tcp: Slightly optimize tcp_sendmsg Krishna Kumar
@ 2009-12-23 22:16   ` David Miller
  0 siblings, 0 replies; 4+ messages in thread
From: David Miller @ 2009-12-23 22:16 UTC (permalink / raw)
  To: krkumar2; +Cc: netdev

From: Krishna Kumar <krkumar2@in.ibm.com>
Date: Thu, 10 Dec 2009 22:46:59 +0530

> 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) {
> 
> The reason why this change is correct: this code (other than
> the MAX_SKB_FRAGS case) executes only due to the else part
> of: "if (skb_tailroom(skb) > 0) {" - i.e. there was no space
> in the skb to put the data inline. Hence SG is false is a
> sufficient condition, and there is no way a fragment can be
> added to the skb.
> 
> Changelog:
> 	- Added the above explanation for the change
> 
> Signed-off-by: Krishna Kumar <krkumar2@in.ibm.com>
> Acked-by: Ilpo Järvinen <ilpo.jarvinen@helsinki.fi>

Applied.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2009-12-23 22:16 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-12-10 17:16 [PATCH 2/3 Ver2] tcp: Remove unrequired operations in tcp_push() Krishna Kumar
2009-12-10 17:16 ` [PATCH 3/3 Ver2] tcp: Slightly optimize tcp_sendmsg Krishna Kumar
2009-12-23 22:16   ` David Miller
2009-12-23 22:15 ` [PATCH 2/3 Ver2] tcp: Remove unrequired operations in tcp_push() David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).