tcp: Remove check in __tcp_push_pending_frames
Subsystems (3)
PATCH 1/3 tcp: Remove check in __tcp_push_pending_frames
From: Krishna Kumar <[email protected]>
tcp_push checks tcp_send_head and calls __tcp_push_pending_frames, which again checks tcp_send_head, and this unnecessary check is done for every other caller of __tcp_push_pending_frames.
Remove tcp_send_head check in __tcp_push_pending_frames and add the check to tcp_push_pending_frames. Other functions call __tcp_push_pending_frames only when tcp_send_head would evaluate to true.
--- include/net/tcp.h | 16 +++++++++------- net/ipv4/tcp_output.c | 5 ----- 2 files changed, 9 insertions(+), 12 deletions(-)
include/net/tcp.h +9 -7
@@ -857,13 +857,6 @@ static inline void tcp_check_probe_timer icsk->icsk_rto, TCP_RTO_MAX); } -static inline void tcp_push_pending_frames (struct sock *sk) -{ -struct tcp_sock *tp =tcp_sk (sk); - -__tcp_push_pending_frames (sk,tcp_current_mss (sk), tp->nonagle); -} -static inline void tcp_init_wl (struct tcp_sock *tp,u32 seq) { tp->snd_wl1 = seq;
@@ -1366,6 +1359,15 @@ static inline int tcp_write_queue_empty(return skb_queue_empty (&sk->sk_write_queue); } +static inline void tcp_push_pending_frames (struct sock *sk) +{ +if (tcp_send_head (sk)) { +struct tcp_sock *tp =tcp_sk (sk); + +__tcp_push_pending_frames (sk,tcp_current_mss (sk), tp->nonagle); + } +} +/* Start sequence of the highest skb with SACKed bit, valid only if * sacked > 0 or when the caller has ensured validity by itself. */
net/ipv4/tcp_output.c +0 -5
@@ -1799,11 +1799,6 @@ static int tcp_write_xmit(struct sock *svoid __tcp_push_pending_frames (struct sock *sk,unsigned int cur_mss,int nonagle) { -struct sk_buff *skb =tcp_send_head (sk); - -if (!skb) -return ; -/* If we are closed, the bytes will have to remain here. * In time closedown will finish, we empty the write queue and * all will be happy.
PATCH 2/3 tcp: Remove unrequired operations in tcp_push()
From: Krishna Kumar <[email protected]>
Remove unrequired operations in tcp_push()
--- net/ipv4/tcp.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-)
net/ipv4/tcp.c +8 -7
@@ -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,15 @@ static inline void tcp_mark_urg(struct tstatic 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); -if (!(flags &MSG_MORE ) ||forced_push (tp)) +struct tcp_sock *tp =tcp_sk (sk); + +if (!(flags &MSG_MORE ) ||forced_push (tp)) { +struct sk_buff *skb =tcp_write_queue_tail (sk); +tcp_mark_push (tp, skb); -tcp_mark_urg (tp, flags, skb); + } +tcp_mark_urg (tp, flags);__tcp_push_pending_frames (sk, mss_now, (flags &MSG_MORE ) ?TCP_NAGLE_CORK : nonagle); }
Re: [PATCH 2/3] tcp: Remove unrequired operations in tcp_push()
Quoted 27 lines · Krishna Kumar
From: Krishna Kumar <[email protected]>
Remove unrequired operations in
tcp_push()Signed-off-by Krishna Kumar <[email protected]>--- net/ipv4/tcp.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-)diff -ruNp
org/net/ipv4/tcp.cnew/net/ipv4/tcp.cnet/ipv4/tcp.c +1
-3@@ -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,15 @@ static inline void tcp_mark_urg(struct tstatic inline void tcp_push (struct sock *sk,int flags,int mss_now,int nonagle) { -struct tcp_sock *tp =tcp_sk (sk);
net/ipv4/tcp.c static inline void tcp_mark_urg(struct t · line 554
Quoted 10 lines
net/ipv4/tcp.c +5
-3-if (tcp_send_head (sk)) { -struct sk_buff *skb =tcp_write_queue_tail (sk); -if (!(flags &MSG_MORE ) ||forced_push (tp)) +struct tcp_sock *tp =tcp_sk (sk); + +if (!(flags &MSG_MORE ) ||forced_push (tp)) { +struct sk_buff *skb =tcp_write_queue_tail (sk); +tcp_mark_push (tp, skb);
I suppose one could kill the temporary variable completely then?
Quoted 6 lines
net/ipv4/tcp.c +2
-1-tcp_mark_urg (tp, flags, skb); + } +tcp_mark_urg (tp, flags);__tcp_push_pending_frames (sk, mss_now, (flags &MSG_MORE ) ?TCP_NAGLE_CORK : nonagle); }
Signature · 1 line
i.
Re: [PATCH 2/3] tcp: Remove unrequired operations in tcp_push()
"Ilpo Järvinen" <[email protected]> wrote on 12/10/2009 01:40:51 PM:
Quoted 19 lines
Re: [PATCH 2/3] tcp: Remove unrequired operations in
tcp_push()Quoted 4 lines
static inline void tcp_push(struct sock *sk, int flags, int
mss_now,
int nonagle)
{net/ipv4/tcp.c +0
-1-struct tcp_sock *tp =tcp_sk (sk);net/ipv4/tcp.c static inline void tcp_mark_urg(struct t · line 554
Quoted 10 lines
net/ipv4/tcp.c +5
-3-if (tcp_send_head (sk)) { -struct sk_buff *skb =tcp_write_queue_tail (sk); -if (!(flags &MSG_MORE ) ||forced_push (tp)) +struct tcp_sock *tp =tcp_sk (sk); + +if (!(flags &MSG_MORE ) ||forced_push (tp)) { +struct sk_buff *skb =tcp_write_queue_tail (sk); +tcp_mark_push (tp, skb);I suppose one could kill the temporary variable completely then?
I did consider that, but kept it this way for readability reasons. Should I change it?
Thanks,
- KK
Re: [PATCH 2/3] tcp: Remove unrequired operations in tcp_push()
Quoted 23 lines · On Thu, 10 Dec 2009, Krishna Kumar2 wrote:
"Ilpo Järvinen" <[email protected]> wrote on 12/10/2009 01:40:51 PM:
Quoted 19 lines
Re: [PATCH 2/3] tcp: Remove unrequired operations in
tcp_push()Quoted 4 lines
static inline void tcp_push(struct sock *sk, int flags, int
mss_now,
int nonagle)
{net/ipv4/tcp.c +0
-1-struct tcp_sock *tp =tcp_sk (sk);net/ipv4/tcp.c static inline void tcp_mark_urg(struct t · line 554
Quoted 10 lines
net/ipv4/tcp.c +5
-3-if (tcp_send_head (sk)) { -struct sk_buff *skb =tcp_write_queue_tail (sk); -if (!(flags &MSG_MORE ) ||forced_push (tp)) +struct tcp_sock *tp =tcp_sk (sk); + +if (!(flags &MSG_MORE ) ||forced_push (tp)) { +struct sk_buff *skb =tcp_write_queue_tail (sk); +tcp_mark_push (tp, skb);I suppose one could kill the temporary variable completely then?
Quoted 2 lines
I did consider that, but kept it this way for readability reasons. Should I change it?
Honestly that doesn't look that fuzzy code even if you'd stick it into the tcp_mark_push line (nor should be even close to 80 limit). ...I was even thinking of getting totally rid of that skb arg of tcp_mark_push as I think it's always tcp_write_queue_tail(sk) that is put there.
Signature · 1 line
i.
Re: [PATCH 2/3] tcp: Remove unrequired operations in tcp_push()
"Ilpo Järvinen" <[email protected]> wrote on 12/10/2009 03:56:59 PM:
Quoted 5 lines
Re: [PATCH 2/3] tcp: Remove unrequired operations in
tcp_push()Quoted 1 line · On Thu, 10 Dec 2009, Krishna Kumar2 wrote:
"Ilpo Järvinen" <[email protected]> wrote on 12/10/2009
01:40:51
Quoted 6 lines
Quoted 6 lines
PM:
Quoted 4 lines
Re: [PATCH 2/3] tcp: Remove unrequired operations in
tcp_push()Quoted 1 line
static inline void tcp_push(struct sock *sk, int flags, int
mss_now,
Quoted 16 lines
Quoted 16 lines
Quoted 15 lines
net/ipv4/tcp.c static inline void tcp_mark_urg(struct t · line 554
Quoted 13 lines
int nonagle)
{net/ipv4/tcp.c +5
-4-struct tcp_sock *tp =tcp_sk (sk); -if (tcp_send_head (sk)) { -struct sk_buff *skb =tcp_write_queue_tail (sk); -if (!(flags &MSG_MORE ) ||forced_push (tp)) +struct tcp_sock *tp =tcp_sk (sk); + +if (!(flags &MSG_MORE ) ||forced_push (tp)) { +struct sk_buff *skb =tcp_write_queue_tail (sk); +tcp_mark_push (tp, skb);I suppose one could kill the temporary variable completely then?
Quoted 4 lines
Quoted 2 lines
I did consider that, but kept it this way for readability reasons. Should I change it?
Honestly that doesn't look that fuzzy code even if you'd stick it into
the
Quoted 3 lines
tcp_mark_pushline (nor should be even close to 80 limit). ...I was even thinking of getting totally rid of that skb arg oftcp_mark_pushas I think it's alwaystcp_write_queue_tail(sk)that is put there.
Yes, the skb is always the one at the tail. But in 4/5 cases, the skb pointer is already available, so may be OK to pass the skb. I will resubmit with the change you suggested (remove the temporary variable).
Also, for the NETIF_F_SG patch, I will try to put a meaningful explanation and resubmit.
Thanks for your review,
- KK
Re: [PATCH 2/3] tcp: Remove unrequired operations in tcp_push()
Quoted 35 lines · On Thu, 10 Dec 2009, Krishna Kumar2 wrote:
"Ilpo Järvinen" <[email protected]> wrote on 12/10/2009 03:56:59 PM:
Quoted 5 lines
Re: [PATCH 2/3] tcp: Remove unrequired operations in
tcp_push()Quoted 1 line · On Thu, 10 Dec 2009, Krishna Kumar2 wrote:
"Ilpo Järvinen" <[email protected]> wrote on 12/10/2009
01:40:51
Quoted 6 lines
Quoted 6 lines
PM:
Quoted 4 lines
Re: [PATCH 2/3] tcp: Remove unrequired operations in
tcp_push()Quoted 1 line
static inline void tcp_push(struct sock *sk, int flags, int
mss_now,Quoted 19 lines
Quoted 18 lines
Quoted 7 lines
Quoted 7 lines
int nonagle)
{net/ipv4/tcp.c +0
-4-struct tcp_sock *tp =tcp_sk (sk); -if (tcp_send_head (sk)) { -struct sk_buff *skb =tcp_write_queue_tail (sk); -if (!(flags &MSG_MORE ) ||forced_push (tp))Quoted 8 lines
net/ipv4/tcp.c static inline void tcp_mark_urg(struct t · line 554
Quoted 6 lines
net/ipv4/tcp.c +5
-0+struct tcp_sock *tp =tcp_sk (sk); + +if (!(flags &MSG_MORE ) ||forced_push (tp)) { +struct sk_buff *skb =tcp_write_queue_tail (sk); +tcp_mark_push (tp, skb);I suppose one could kill the temporary variable completely then?
I did consider that, but kept it this way for readability reasons. Should I change it?
Quoted 8 lines
Quoted 1 line
Honestly that doesn't look that fuzzy code even if you'd stick it into
the
Quoted 3 lines
tcp_mark_pushline (nor should be even close to 80 limit). ...I was even thinking of getting totally rid of that skb arg oftcp_mark_pushas I think it's alwaystcp_write_queue_tail(sk)that is put there.Yes, the skb is always the one at the tail. But in 4/5 cases, the skb pointer is already available, so may be OK to pass the skb.
...which was exactly why I didn't immediately suggest it :-).
Quoted 2 lines
Also, for the
NETIF_F_SGpatch, I will try to put a meaningful explanation and resubmit.
Thanks.
Signature · 1 line
i.
PATCH 3/3 tcp: Slightly optimize tcp_sendmsg
In reply to Krishna KumarFrom: Krishna Kumar <[email protected]>
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) {--- net/ipv4/tcp.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-)
net/ipv4/tcp.c +9 -8
@@ -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, strustruct 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, struif (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
Re: [PATCH 3/3] tcp: Slightly optimize tcp_sendmsg
Quoted 10 lines · Krishna Kumar
From: Krishna Kumar <[email protected]>
Slightly optimize
tcp_sendmsgsinceNETIF_F_SGis 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) {
I can see that you make this change from the patch itself but could you give a justification on why dropping the !i is possible? ...I couldn't see what would allow that.
Quoted 69 lines
Signed-off-by Krishna Kumar <[email protected]>--- net/ipv4/tcp.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-)diff -ruNp
org/net/ipv4/tcp.cnew/net/ipv4/tcp.cnet/ipv4/tcp.c +9
-9@@ -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, strustruct 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, struif (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 -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Signature · 1 line
i.
Re: [PATCH 3/3] tcp: Slightly optimize tcp_sendmsg
Hi Ilpo,
"Ilpo Järvinen" <[email protected]> wrote on 12/10/2009 01:47:30 PM:
Quoted 11 lines
Subject: Re: [PATCH 3/3] tcp: Slightly optimize
tcp_sendmsg>Quoted 8 lines
Slightly optimize
tcp_sendmsgsinceNETIF_F_SGis 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) {
Quoted 3 lines
I can see that you make this change from the patch itself but could you give a justification on why dropping the !i is possible? ...I couldn't see what would allow that.
From what *I understood*, this code (other than the MAX_SKB_FRAGS case) executes only due to the else part of "if (skb_tailroom(skb) > 0) {" - 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 to add a fragment (i == 0 since skb_fill_page_desc cannot be called when !SG).
thanks,
- KK
Re: [PATCH 3/3] tcp: Slightly optimize tcp_sendmsg
Quoted 20 lines · On Thu, 10 Dec 2009, Krishna Kumar2 wrote:
Hi Ilpo,
"Ilpo Järvinen" <[email protected]> wrote on 12/10/2009 01:47:30 PM:
Quoted 11 lines
Subject: Re: [PATCH 3/3] tcp: Slightly optimize
tcp_sendmsg>Quoted 8 lines
Slightly optimize
tcp_sendmsgsinceNETIF_F_SGis 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) {Quoted 3 lines
I can see that you make this change from the patch itself but could you give a justification on why dropping the !i is possible? ...I couldn't see what would allow that.
Quoted 5 lines
From what *I understood*, this code (other than the
MAX_SKB_FRAGScase) executes only due to the else part of "if (skb_tailroom(skb)> 0) {" - 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 to add a fragment (i == 0 sinceskb_fill_page_desccannot be called when !SG).
Please put this description into the patch description then :-). ...After some more thinking, reading and verification it seems right, however, it certainly wassn't immediately obvious from the code.
...You can add my Acked-by: Ilpo Järvinen <[email protected]> for the resubmission.
Signature · 1 line
i.
Quoted 55 lines · Krishna Kumar
From: Krishna Kumar <[email protected]>
tcp_pushcheckstcp_send_headand calls__tcp_push_pending_frames, which again checkstcp_send_head, and this unnecessary check is done for every other caller of__tcp_push_pending_frames.Remove
tcp_send_headcheck in__tcp_push_pending_framesand add the check totcp_push_pending_frames. Other functions call__tcp_push_pending_framesonly whentcp_send_headwould evaluate to true.Signed-off-by Krishna Kumar <[email protected]>--- include/net/tcp.h | 16 +++++++++------- net/ipv4/tcp_output.c | 5 ----- 2 files changed, 9 insertions(+), 12 deletions(-)diff -ruNp
org/include/net/tcp.hnew/include/net/tcp.hinclude/net/tcp.h +9
-7@@ -857,13 +857,6 @@ static inline void tcp_check_probe_timer icsk->icsk_rto, TCP_RTO_MAX); } -static inline void tcp_push_pending_frames (struct sock *sk) -{ -struct tcp_sock *tp =tcp_sk (sk); - -__tcp_push_pending_frames (sk,tcp_current_mss (sk), tp->nonagle); -} -static inline void tcp_init_wl (struct tcp_sock *tp,u32 seq) { tp->snd_wl1 = seq;@@ -1366,6 +1359,15 @@ static inline int tcp_write_queue_empty(return skb_queue_empty (&sk->sk_write_queue); } +static inline void tcp_push_pending_frames (struct sock *sk) +{ +if (tcp_send_head (sk)) { +struct tcp_sock *tp =tcp_sk (sk); + +__tcp_push_pending_frames (sk,tcp_current_mss (sk), tp->nonagle); + } +} +/* Start sequence of the highest skb with SACKed bit, valid only if * sacked > 0 or when the caller has ensured validity by itself. */ diff -ruNp
org/net/ipv4/tcp_output.cnew/net/ipv4/tcp_output.cnet/ipv4/tcp_output.c +0
-0@@ -1799,11 +1799,6 @@ static int tcp_write_xmit(struct sock *s void __tcp_push_pending_frames(struct sock *sk, unsigned int cur_mss,
net/ipv4/tcp_output.c static int tcp_write_xmit(struct sock *s · line 1804
Quoted 10 lines
net/ipv4/tcp_output.c +0
-5int nonagle) { -struct sk_buff *skb =tcp_send_head (sk); - -if (!skb) -return ; -/* If we are closed, the bytes will have to remain here. * In time closedown will finish, we empty the write queue and * all will be happy.
Signature · 1 line
i.
From: Krishna Kumar <[email protected]>
Date: Wed, 09 Dec 2009 13:56:13 +0530
Quoted 6 lines
From: Krishna Kumar <[email protected]>
tcp_pushcheckstcp_send_headand calls__tcp_push_pending_frames, which again checkstcp_send_head, and this unnecessary check is done for every other caller of__tcp_push_pending_frames.
Quoted 6 lines
Remove
tcp_send_headcheck in__tcp_push_pending_framesand add the check totcp_push_pending_frames. Other functions call__tcp_push_pending_framesonly whentcp_send_headwould evaluate to true.Signed-off-by Krishna Kumar <[email protected]>
Applied.