Skip to content

Commit 1def923

Browse files
Eric Dumazetdavem330
Eric Dumazet
authored andcommitted
net_sched: more precise pkt_len computation
One long standing problem with TSO/GSO/GRO packets is that skb->len doesn't represent a precise amount of bytes on wire. Headers are only accounted for the first segment. For TCP, thats typically 66 bytes per 1448 bytes segment missing, an error of 4.5 % for normal MSS value. As consequences : 1) TBF/CBQ/HTB/NETEM/... can send more bytes than the assigned limits. 2) Device stats are slightly under estimated as well. Fix this by taking account of headers in qdisc_skb_cb(skb)->pkt_len computation. Packet schedulers should use qdisc pkt_len instead of skb->len for their bandwidth limitations, and TSO enabled devices drivers could use pkt_len if their statistics are not hardware assisted, and if they don't scratch skb->cb[] first word. Both egress and ingress paths work, thanks to commit fda55ec (net: introduce skb_transport_header_was_set()) : If GRO built a GSO packet, it also set the transport header for us. Signed-off-by: Eric Dumazet <[email protected]> Cc: Jamal Hadi Salim <[email protected]> Cc: Stephen Hemminger <[email protected]> Cc: Paolo Valente <[email protected]> Cc: Herbert Xu <[email protected]> Cc: Patrick McHardy <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 3d55b32 commit 1def923

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

net/core/dev.c

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2532,6 +2532,26 @@ struct netdev_queue *netdev_pick_tx(struct net_device *dev,
25322532
return netdev_get_tx_queue(dev, queue_index);
25332533
}
25342534

2535+
static void qdisc_pkt_len_init(struct sk_buff *skb)
2536+
{
2537+
const struct skb_shared_info *shinfo = skb_shinfo(skb);
2538+
2539+
qdisc_skb_cb(skb)->pkt_len = skb->len;
2540+
2541+
/* To get more precise estimation of bytes sent on wire,
2542+
* we add to pkt_len the headers size of all segments
2543+
*/
2544+
if (shinfo->gso_size) {
2545+
unsigned int hdr_len = skb_transport_offset(skb);
2546+
2547+
if (likely(shinfo->gso_type & (SKB_GSO_TCPV4 | SKB_GSO_TCPV6)))
2548+
hdr_len += tcp_hdrlen(skb);
2549+
else
2550+
hdr_len += sizeof(struct udphdr);
2551+
qdisc_skb_cb(skb)->pkt_len += (shinfo->gso_segs - 1) * hdr_len;
2552+
}
2553+
}
2554+
25352555
static inline int __dev_xmit_skb(struct sk_buff *skb, struct Qdisc *q,
25362556
struct net_device *dev,
25372557
struct netdev_queue *txq)
@@ -2540,7 +2560,7 @@ static inline int __dev_xmit_skb(struct sk_buff *skb, struct Qdisc *q,
25402560
bool contended;
25412561
int rc;
25422562

2543-
qdisc_skb_cb(skb)->pkt_len = skb->len;
2563+
qdisc_pkt_len_init(skb);
25442564
qdisc_calculate_pkt_len(skb, q);
25452565
/*
25462566
* Heuristic to force contended enqueues to serialize on a

0 commit comments

Comments
 (0)