656-skb_reduce_truesize-helper.patch 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. On embedded devices in particular, large queues of small packets from the rx
  7. path with a large truesize can exist. Reducing their size can reduce
  8. memory pressure. skb_reduce_truesize is a helper function for doing this,
  9. when needed.
  10. ---
  11. include/linux/skbuff.h | 18 ++++++++++++++++++
  12. 1 file changed, 18 insertions(+)
  13. --- a/include/linux/skbuff.h
  14. +++ b/include/linux/skbuff.h
  15. @@ -2068,6 +2068,24 @@ static inline void pskb_trim_unique(stru
  16. BUG_ON(err);
  17. }
  18. +/*
  19. + * Caller wants to reduce memory needs before queueing skb
  20. + * The (expensive) copy should not be be done in fast path.
  21. + */
  22. +static inline struct sk_buff *skb_reduce_truesize(struct sk_buff *skb)
  23. +{
  24. + if (skb->truesize > 2 * SKB_TRUESIZE(skb->len)) {
  25. + struct sk_buff *nskb;
  26. + nskb = skb_copy_expand(skb, skb_headroom(skb), 0,
  27. + GFP_ATOMIC | __GFP_NOWARN);
  28. + if (nskb) {
  29. + __kfree_skb(skb);
  30. + skb = nskb;
  31. + }
  32. + }
  33. + return skb;
  34. +}
  35. +
  36. /**
  37. * skb_orphan - orphan a buffer
  38. * @skb: buffer to orphan