Commit ad405857 authored by Willem de Bruijn's avatar Willem de Bruijn Committed by David S. Miller

udp: better wmem accounting on gso

skb_segment by default transfers allocated wmem from the gso skb
to the tail of the segment list. This underreports real truesize
of the list, especially if the tail might be dropped.

Similar to tcp_gso_segment, update wmem_alloc with the aggregate
list truesize and make each segment responsible for its own
share by setting skb->destructor.

Clear gso_skb->destructor prior to calling skb_segment to skip
the default assignment to tail.
Signed-off-by: default avatarWillem de Bruijn <willemb@google.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent bec1f6f6
...@@ -191,6 +191,8 @@ struct sk_buff *__udp_gso_segment(struct sk_buff *gso_skb, ...@@ -191,6 +191,8 @@ struct sk_buff *__udp_gso_segment(struct sk_buff *gso_skb,
netdev_features_t features, netdev_features_t features,
unsigned int mss, __sum16 check) unsigned int mss, __sum16 check)
{ {
struct sock *sk = gso_skb->sk;
unsigned int sum_truesize = 0;
struct sk_buff *segs, *seg; struct sk_buff *segs, *seg;
unsigned int hdrlen; unsigned int hdrlen;
struct udphdr *uh; struct udphdr *uh;
...@@ -201,9 +203,15 @@ struct sk_buff *__udp_gso_segment(struct sk_buff *gso_skb, ...@@ -201,9 +203,15 @@ struct sk_buff *__udp_gso_segment(struct sk_buff *gso_skb,
hdrlen = gso_skb->data - skb_mac_header(gso_skb); hdrlen = gso_skb->data - skb_mac_header(gso_skb);
skb_pull(gso_skb, sizeof(*uh)); skb_pull(gso_skb, sizeof(*uh));
/* clear destructor to avoid skb_segment assigning it to tail */
WARN_ON_ONCE(gso_skb->destructor != sock_wfree);
gso_skb->destructor = NULL;
segs = skb_segment(gso_skb, features); segs = skb_segment(gso_skb, features);
if (unlikely(IS_ERR_OR_NULL(segs))) if (unlikely(IS_ERR_OR_NULL(segs))) {
gso_skb->destructor = sock_wfree;
return segs; return segs;
}
for (seg = segs; seg; seg = seg->next) { for (seg = segs; seg; seg = seg->next) {
uh = udp_hdr(seg); uh = udp_hdr(seg);
...@@ -214,8 +222,14 @@ struct sk_buff *__udp_gso_segment(struct sk_buff *gso_skb, ...@@ -214,8 +222,14 @@ struct sk_buff *__udp_gso_segment(struct sk_buff *gso_skb,
if (!seg->next) if (!seg->next)
csum_replace2(&uh->check, htons(mss), csum_replace2(&uh->check, htons(mss),
htons(seg->len - hdrlen - sizeof(*uh))); htons(seg->len - hdrlen - sizeof(*uh)));
seg->destructor = sock_wfree;
seg->sk = sk;
sum_truesize += seg->truesize;
} }
refcount_add(sum_truesize - gso_skb->truesize, &sk->sk_wmem_alloc);
return segs; return segs;
} }
EXPORT_SYMBOL_GPL(__udp_gso_segment); EXPORT_SYMBOL_GPL(__udp_gso_segment);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment