net: skb_segment() provides list head and tail
authorEric Dumazet <edumazet@google.com>
Sat, 4 Oct 2014 03:59:19 +0000 (20:59 -0700)
committerDavid S. Miller <davem@davemloft.net>
Mon, 6 Oct 2014 04:37:30 +0000 (00:37 -0400)
Its unfortunate we have to walk again skb list to find the tail
after segmentation, even if data is probably hot in cpu caches.

skb_segment() can store the tail of the list into segs->prev,
and validate_xmit_skb_list() can immediately get the tail.

Signed-off-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/core/dev.c
net/core/skbuff.c

index 1a90530f83ffd7afc2b748dccea730218f4b2f40..7d5691cc1f479ee4f1bb46b06d35fe8cf43b21dc 100644 (file)
@@ -2724,22 +2724,25 @@ struct sk_buff *validate_xmit_skb_list(struct sk_buff *skb, struct net_device *d
 {
        struct sk_buff *next, *head = NULL, *tail;
 
-       while (skb) {
+       for (; skb != NULL; skb = next) {
                next = skb->next;
                skb->next = NULL;
+
+               /* in case skb wont be segmented, point to itself */
+               skb->prev = skb;
+
                skb = validate_xmit_skb(skb, dev);
-               if (skb) {
-                       struct sk_buff *end = skb;
+               if (!skb)
+                       continue;
 
-                       while (end->next)
-                               end = end->next;
-                       if (!head)
-                               head = skb;
-                       else
-                               tail->next = skb;
-                       tail = end;
-               }
-               skb = next;
+               if (!head)
+                       head = skb;
+               else
+                       tail->next = skb;
+               /* If skb was segmented, skb->prev points to
+                * the last segment. If not, it still contains skb.
+                */
+               tail = skb->prev;
        }
        return head;
 }
index 9a423e2c57661ba15390cfe4b639fd4a107faff4..7b3df0d518abfa5da3440d614ce5fa9e65bb06e6 100644 (file)
@@ -3083,6 +3083,11 @@ perform_csum_check:
                }
        } while ((offset += len) < head_skb->len);
 
+       /* Some callers want to get the end of the list.
+        * Put it in segs->prev to avoid walking the list.
+        * (see validate_xmit_skb_list() for example)
+        */
+       segs->prev = tail;
        return segs;
 
 err: