Skip to content

Commit bffa72c

Browse files
edumazetdavem330
authored andcommitted
net: sk_buff rbnode reorg
skb->rbnode shares space with skb->next, skb->prev and skb->tstamp Current uses (TCP receive ofo queue and netem) need to save/restore tstamp, while skb->dev is either NULL (TCP) or a constant for a given queue (netem). Since we plan using an RB tree for TCP retransmit queue to speedup SACK processing with large BDP, this patch exchanges skb->dev and skb->tstamp. This saves some overhead in both TCP and netem. v2: removes the swtstamp field from struct tcp_skb_cb Signed-off-by: Eric Dumazet <edumazet@google.com> Cc: Soheil Hassas Yeganeh <soheil@google.com> Cc: Wei Wang <weiwan@google.com> Cc: Willem de Bruijn <willemb@google.com> Acked-by: Soheil Hassas Yeganeh <soheil@google.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent a38b2fa commit bffa72c

File tree

4 files changed

+17
-39
lines changed

4 files changed

+17
-39
lines changed

include/linux/skbuff.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -661,21 +661,21 @@ struct sk_buff {
661661
struct sk_buff *prev;
662662

663663
union {
664-
ktime_t tstamp;
665-
u64 skb_mstamp;
664+
struct net_device *dev;
665+
/* Some protocols might use this space to store information,
666+
* while device pointer would be NULL.
667+
* UDP receive path is one user.
668+
*/
669+
unsigned long dev_scratch;
666670
};
667671
};
668672
struct rb_node rbnode; /* used in netem & tcp stack */
669673
};
670674
struct sock *sk;
671675

672676
union {
673-
struct net_device *dev;
674-
/* Some protocols might use this space to store information,
675-
* while device pointer would be NULL.
676-
* UDP receive path is one user.
677-
*/
678-
unsigned long dev_scratch;
677+
ktime_t tstamp;
678+
u64 skb_mstamp;
679679
};
680680
/*
681681
* This is the control buffer. It is free to use for every

include/net/tcp.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -797,12 +797,6 @@ struct tcp_skb_cb {
797797
u16 tcp_gso_segs;
798798
u16 tcp_gso_size;
799799
};
800-
801-
/* Used to stash the receive timestamp while this skb is in the
802-
* out of order queue, as skb->tstamp is overwritten by the
803-
* rbnode.
804-
*/
805-
ktime_t swtstamp;
806800
};
807801
__u8 tcp_flags; /* TCP header flags. (tcp[13]) */
808802

net/ipv4/tcp_input.c

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4266,11 +4266,6 @@ static void tcp_sack_remove(struct tcp_sock *tp)
42664266
tp->rx_opt.num_sacks = num_sacks;
42674267
}
42684268

4269-
enum tcp_queue {
4270-
OOO_QUEUE,
4271-
RCV_QUEUE,
4272-
};
4273-
42744269
/**
42754270
* tcp_try_coalesce - try to merge skb to prior one
42764271
* @sk: socket
@@ -4286,7 +4281,6 @@ enum tcp_queue {
42864281
* Returns true if caller should free @from instead of queueing it
42874282
*/
42884283
static bool tcp_try_coalesce(struct sock *sk,
4289-
enum tcp_queue dest,
42904284
struct sk_buff *to,
42914285
struct sk_buff *from,
42924286
bool *fragstolen)
@@ -4311,10 +4305,7 @@ static bool tcp_try_coalesce(struct sock *sk,
43114305

43124306
if (TCP_SKB_CB(from)->has_rxtstamp) {
43134307
TCP_SKB_CB(to)->has_rxtstamp = true;
4314-
if (dest == OOO_QUEUE)
4315-
TCP_SKB_CB(to)->swtstamp = TCP_SKB_CB(from)->swtstamp;
4316-
else
4317-
to->tstamp = from->tstamp;
4308+
to->tstamp = from->tstamp;
43184309
}
43194310

43204311
return true;
@@ -4351,9 +4342,6 @@ static void tcp_ofo_queue(struct sock *sk)
43514342
}
43524343
p = rb_next(p);
43534344
rb_erase(&skb->rbnode, &tp->out_of_order_queue);
4354-
/* Replace tstamp which was stomped by rbnode */
4355-
if (TCP_SKB_CB(skb)->has_rxtstamp)
4356-
skb->tstamp = TCP_SKB_CB(skb)->swtstamp;
43574345

43584346
if (unlikely(!after(TCP_SKB_CB(skb)->end_seq, tp->rcv_nxt))) {
43594347
SOCK_DEBUG(sk, "ofo packet was already received\n");
@@ -4365,8 +4353,7 @@ static void tcp_ofo_queue(struct sock *sk)
43654353
TCP_SKB_CB(skb)->end_seq);
43664354

43674355
tail = skb_peek_tail(&sk->sk_receive_queue);
4368-
eaten = tail && tcp_try_coalesce(sk, RCV_QUEUE,
4369-
tail, skb, &fragstolen);
4356+
eaten = tail && tcp_try_coalesce(sk, tail, skb, &fragstolen);
43704357
tcp_rcv_nxt_update(tp, TCP_SKB_CB(skb)->end_seq);
43714358
fin = TCP_SKB_CB(skb)->tcp_flags & TCPHDR_FIN;
43724359
if (!eaten)
@@ -4420,10 +4407,6 @@ static void tcp_data_queue_ofo(struct sock *sk, struct sk_buff *skb)
44204407
return;
44214408
}
44224409

4423-
/* Stash tstamp to avoid being stomped on by rbnode */
4424-
if (TCP_SKB_CB(skb)->has_rxtstamp)
4425-
TCP_SKB_CB(skb)->swtstamp = skb->tstamp;
4426-
44274410
/* Disable header prediction. */
44284411
tp->pred_flags = 0;
44294412
inet_csk_schedule_ack(sk);
@@ -4451,7 +4434,7 @@ static void tcp_data_queue_ofo(struct sock *sk, struct sk_buff *skb)
44514434
/* In the typical case, we are adding an skb to the end of the list.
44524435
* Use of ooo_last_skb avoids the O(Log(N)) rbtree lookup.
44534436
*/
4454-
if (tcp_try_coalesce(sk, OOO_QUEUE, tp->ooo_last_skb,
4437+
if (tcp_try_coalesce(sk, tp->ooo_last_skb,
44554438
skb, &fragstolen)) {
44564439
coalesce_done:
44574440
tcp_grow_window(sk, skb);
@@ -4502,7 +4485,7 @@ static void tcp_data_queue_ofo(struct sock *sk, struct sk_buff *skb)
45024485
__kfree_skb(skb1);
45034486
goto merge_right;
45044487
}
4505-
} else if (tcp_try_coalesce(sk, OOO_QUEUE, skb1,
4488+
} else if (tcp_try_coalesce(sk, skb1,
45064489
skb, &fragstolen)) {
45074490
goto coalesce_done;
45084491
}
@@ -4554,7 +4537,7 @@ static int __must_check tcp_queue_rcv(struct sock *sk, struct sk_buff *skb, int
45544537

45554538
__skb_pull(skb, hdrlen);
45564539
eaten = (tail &&
4557-
tcp_try_coalesce(sk, RCV_QUEUE, tail,
4540+
tcp_try_coalesce(sk, tail,
45584541
skb, fragstolen)) ? 1 : 0;
45594542
tcp_rcv_nxt_update(tcp_sk(sk), TCP_SKB_CB(skb)->end_seq);
45604543
if (!eaten) {

net/sched/sch_netem.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,6 @@ struct netem_sched_data {
146146
*/
147147
struct netem_skb_cb {
148148
psched_time_t time_to_send;
149-
ktime_t tstamp_save;
150149
};
151150

152151

@@ -561,7 +560,6 @@ static int netem_enqueue(struct sk_buff *skb, struct Qdisc *sch,
561560
}
562561

563562
cb->time_to_send = now + delay;
564-
cb->tstamp_save = skb->tstamp;
565563
++q->counter;
566564
tfifo_enqueue(skb, sch);
567565
} else {
@@ -629,7 +627,10 @@ static struct sk_buff *netem_dequeue(struct Qdisc *sch)
629627
qdisc_qstats_backlog_dec(sch, skb);
630628
skb->next = NULL;
631629
skb->prev = NULL;
632-
skb->tstamp = netem_skb_cb(skb)->tstamp_save;
630+
/* skb->dev shares skb->rbnode area,
631+
* we need to restore its value.
632+
*/
633+
skb->dev = qdisc_dev(sch);
633634

634635
#ifdef CONFIG_NET_CLS_ACT
635636
/*

0 commit comments

Comments
 (0)