tcp: remove redundant rcv_nxt update
Subsystems (3)
PATCH 1/2 tcp: remove redundant rcv_nxt update
tcp_rcv_nxt_update() is already executed in tcp_data_queue(). This line is redundant.
See bellow,
tcp_queue_rcv tcp_rcv_nxt_update(tcp_sk(sk), TCP_SKB_CB(skb)->end_seq); tcp_rcv_nxt_update(tp, TCP_SKB_CB(skb)->end_seq); <<<< redundant
--- net/ipv4/tcp_input.c | 1 - 1 file changed, 1 deletion(-)
net/ipv4/tcp_input.c +0 -1
@@ -4695,7 +4695,6 @@ static void tcp_data_queue(struct sock *sk, struct sk_buff *skb) } eaten =tcp_queue_rcv (sk, skb,0 , &fragstolen); -tcp_rcv_nxt_update (tp,TCP_SKB_CB (skb)->end_seq);if (skb->len)tcp_event_data_recv (sk, skb);if (TCP_SKB_CB (skb)->tcp_flags &TCPHDR_FIN )
Signature · 1 line
1.8.3.1
PATCH 2/2 tcp: refactor tcp_queue_rcv
There're are some code similar to tcp_queue_rcv() in tcp_ofo_queue(), so refactor tcp_queue_rcv() to make it be used in tcp_ofo_queue().
After this change, skb->sk is set when skb is moved from ofo queue into receive queue instead of when queued into ofo queue.
--- net/ipv4/tcp_input.c | 52 ++++++++++++++++++++++------------------------------ 1 file changed, 22 insertions(+), 30 deletions(-)
net/ipv4/tcp_input.c +22 -30
@@ -4367,6 +4367,21 @@ static void tcp_drop(struct sock *sk, struct sk_buff *skb)__kfree_skb (skb); } +static int __must_check +tcp_queue_rcv (struct sock *sk,struct sk_buff *skb,bool *fragstolen) +{ +int eaten; +struct sk_buff *tail =skb_peek_tail (&sk->sk_receive_queue); + + eaten = tail &&tcp_try_coalesce (sk, tail, skb, fragstolen); +tcp_rcv_nxt_update (tcp_sk (sk),TCP_SKB_CB (skb)->end_seq); +if (!eaten) { +__skb_queue_tail (&sk->sk_receive_queue, skb); +skb_set_owner_r (skb, sk); + } +return eaten; +} +/* This one checks to see if we can put data from the * out_of_order queue into the receive_queue. */
@@ -4375,7 +4390,7 @@ static void tcp_ofo_queue(struct sock *sk)struct tcp_sock *tp =tcp_sk (sk);__u32 dsack_high = tp->rcv_nxt;bool fin, fragstolen, eaten; -struct sk_buff *skb, *tail; +struct sk_buff *skb;struct rb_node *p; p =rb_first (&tp->out_of_order_queue);
@@ -4402,13 +4417,9 @@ static void tcp_ofo_queue(struct sock *sk) tp->rcv_nxt,TCP_SKB_CB (skb)->seq, TCP_SKB_CB(skb)->end_seq); - tail =skb_peek_tail (&sk->sk_receive_queue); - eaten = tail &&tcp_try_coalesce (sk, tail, skb, &fragstolen); -tcp_rcv_nxt_update (tp,TCP_SKB_CB (skb)->end_seq); + eaten =tcp_queue_rcv (sk, skb, &fragstolen); fin =TCP_SKB_CB (skb)->tcp_flags &TCPHDR_FIN ; -if (!eaten) -__skb_queue_tail (&sk->sk_receive_queue, skb); -else +if (eaten)kfree_skb_partial (skb, fragstolen);if (unlikely (fin)) {
@@ -4573,28 +4584,9 @@ static void tcp_data_queue_ofo(struct sock *sk, struct sk_buff *skb)if (skb) {tcp_grow_window (sk, skb);skb_condense (skb); -skb_set_owner_r (skb, sk); } } -static int __must_check tcp_queue_rcv (struct sock *sk,struct sk_buff *skb,int hdrlen, -bool *fragstolen) -{ -int eaten; -struct sk_buff *tail =skb_peek_tail (&sk->sk_receive_queue); - -__skb_pull (skb, hdrlen); - eaten = (tail && -tcp_try_coalesce (sk, tail, - skb, fragstolen)) ?1 :0 ; -tcp_rcv_nxt_update (tcp_sk (sk),TCP_SKB_CB (skb)->end_seq); -if (!eaten) { -__skb_queue_tail (&sk->sk_receive_queue, skb); -skb_set_owner_r (skb, sk); - } -return eaten; -} -int tcp_send_rcvq (struct sock *sk,struct msghdr *msg,size_t size) {struct sk_buff *skb;
@@ -4634,7 +4626,7 @@ int tcp_send_rcvq(struct sock *sk, struct msghdr *msg, size_t size)TCP_SKB_CB (skb)->end_seq =TCP_SKB_CB (skb)->seq + size;TCP_SKB_CB (skb)->ack_seq =tcp_sk (sk)->snd_una -1 ; -if (tcp_queue_rcv (sk, skb,0 , &fragstolen)) { +if (tcp_queue_rcv (sk, skb, &fragstolen)) {WARN_ON_ONCE (fragstolen);/* should not happen */ __kfree_skb (skb); }
@@ -4694,7 +4686,7 @@ static void tcp_data_queue(struct sock *sk, struct sk_buff *skb) goto drop; } - eaten =tcp_queue_rcv (sk, skb,0 , &fragstolen); + eaten =tcp_queue_rcv (sk, skb, &fragstolen);if (skb->len)tcp_event_data_recv (sk, skb);if (TCP_SKB_CB (skb)->tcp_flags &TCPHDR_FIN )
@@ -5529,8 +5521,8 @@ void tcp_rcv_established(struct sock *sk, struct sk_buff *skb)NET_INC_STATS (sock_net (sk),LINUX_MIB_TCPHPHITS );/* Bulk data transfer: receiver */ - eaten =tcp_queue_rcv (sk, skb, tcp_header_len, - &fragstolen); +__skb_pull (skb, tcp_header_len); + eaten =tcp_queue_rcv (sk, skb, &fragstolen);tcp_event_data_recv (sk, skb);
Signature · 1 line
1.8.3.1
Re: [PATCH net-next 2/2] tcp: refactor tcp_queue_rcv
Hi Yafang
Quoted 6 lines · Yafang Shao
There're are some code similar to
tcp_queue_rcv()intcp_ofo_queue(), so refactortcp_queue_rcv()to make it be used intcp_ofo_queue().After this change,
skb->skis set when skb is moved from ofo queue into receive queue instead of when queued into ofo queue.
Why would you do that ???
I urge you to test this on hosts connected to the wild Internet :/
Quoted 10 lines · Yafang Shao
tcp_rcv_nxt_update()is already executed intcp_data_queue(). This line is redundant.See bellow,
tcp_queue_rcv tcp_rcv_nxt_update(tcp_sk(sk), TCP_SKB_CB(skb)->end_seq); tcp_rcv_nxt_update(tp, TCP_SKB_CB(skb)->end_seq); <<<< redundantSigned-off-by Yafang Shao <[email protected]>---
This patch is fine (but not the following)
Thanks.