86b7e1ff3b99f2cd564fcaf2296cb957ed9bb8d9
[openwrt.git] / target / linux / generic / patches-3.10 / 656-skb_reduce_truesize-helper.patch
1 From 4593a806e31119c5bd3faa00c7210ad862d515af Mon Sep 17 00:00:00 2001
2 From: Dave Taht <dave.taht@bufferbloat.net>
3 Date: Mon, 31 Dec 2012 10:02:21 -0800
4 Subject: [PATCH 3/7] skb_reduce_truesize: helper function for shrinking skbs
5  whenever needed
6
7 On embedded devices in particular, large queues of small packets from the rx
8 path with a large truesize can exist. Reducing their size can reduce
9 memory pressure. skb_reduce_truesize is a helper function for doing this,
10 when needed.
11 ---
12  include/linux/skbuff.h |   18 ++++++++++++++++++
13  1 file changed, 18 insertions(+)
14
15 --- a/include/linux/skbuff.h
16 +++ b/include/linux/skbuff.h
17 @@ -1898,6 +1898,24 @@ static inline void pskb_trim_unique(stru
18         BUG_ON(err);
19  }
20  
21 +/*
22 + * Caller wants to reduce memory needs before queueing skb
23 + * The (expensive) copy should not be be done in fast path.
24 + */
25 +static inline struct sk_buff *skb_reduce_truesize(struct sk_buff *skb)
26 +{
27 +       if (skb->truesize > 2 * SKB_TRUESIZE(skb->len)) {
28 +               struct sk_buff *nskb;
29 +               nskb = skb_copy_expand(skb, skb_headroom(skb), 0,
30 +                       GFP_ATOMIC | __GFP_NOWARN);
31 +               if (nskb) {
32 +                       __kfree_skb(skb);
33 +                       skb = nskb;
34 +               }
35 +       }
36 +       return skb;
37 +}
38 +
39  /**
40   *     skb_orphan - orphan a buffer
41   *     @skb: buffer to orphan