aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVijay Subramanian <subramanian.vijay@gmail.com>2014-10-02 13:00:43 -0400
committerDavid S. Miller <davem@davemloft.net>2014-10-04 20:34:25 -0400
commitc8753d55afb436fd6a25c8bbe8d783f6dcf1c9f8 (patch)
tree4d0cffb662c877a9a15bdf7bb84f2db35f4c33ec
parent9fab426de78140dc5cb0b85bbee6042c9c3d5ca5 (diff)
net: Cleanup skb cloning by adding SKB_FCLONE_FREE
SKB_FCLONE_UNAVAILABLE has overloaded meaning depending on type of skb. 1: If skb is allocated from head_cache, it indicates fclone is not available. 2: If skb is a companion fclone skb (allocated from fclone_cache), it indicates it is available to be used. To avoid confusion for case 2 above, this patch replaces SKB_FCLONE_UNAVAILABLE with SKB_FCLONE_FREE where appropriate. For fclone companion skbs, this indicates it is free for use. SKB_FCLONE_UNAVAILABLE will now simply indicate skb is from head_cache and cannot / will not have a companion fclone. Signed-off-by: Vijay Subramanian <subramanian.vijay@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--include/linux/skbuff.h7
-rw-r--r--net/core/skbuff.c8
2 files changed, 8 insertions, 7 deletions
diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
index 7c5036d11feb..3a5ec7638627 100644
--- a/include/linux/skbuff.h
+++ b/include/linux/skbuff.h
@@ -339,9 +339,10 @@ struct skb_shared_info {
339 339
340 340
341enum { 341enum {
342 SKB_FCLONE_UNAVAILABLE, 342 SKB_FCLONE_UNAVAILABLE, /* skb has no fclone (from head_cache) */
343 SKB_FCLONE_ORIG, 343 SKB_FCLONE_ORIG, /* orig skb (from fclone_cache) */
344 SKB_FCLONE_CLONE, 344 SKB_FCLONE_CLONE, /* companion fclone skb (from fclone_cache) */
345 SKB_FCLONE_FREE, /* this companion fclone skb is available */
345}; 346};
346 347
347enum { 348enum {
diff --git a/net/core/skbuff.c b/net/core/skbuff.c
index a0b312fa3047..28916e47f959 100644
--- a/net/core/skbuff.c
+++ b/net/core/skbuff.c
@@ -265,7 +265,7 @@ struct sk_buff *__alloc_skb(unsigned int size, gfp_t gfp_mask,
265 skb->fclone = SKB_FCLONE_ORIG; 265 skb->fclone = SKB_FCLONE_ORIG;
266 atomic_set(&fclones->fclone_ref, 1); 266 atomic_set(&fclones->fclone_ref, 1);
267 267
268 fclones->skb2.fclone = SKB_FCLONE_UNAVAILABLE; 268 fclones->skb2.fclone = SKB_FCLONE_FREE;
269 fclones->skb2.pfmemalloc = pfmemalloc; 269 fclones->skb2.pfmemalloc = pfmemalloc;
270 } 270 }
271out: 271out:
@@ -542,7 +542,7 @@ static void kfree_skbmem(struct sk_buff *skb)
542 fclones = container_of(skb, struct sk_buff_fclones, skb2); 542 fclones = container_of(skb, struct sk_buff_fclones, skb2);
543 543
544 /* Warning : We must perform the atomic_dec_and_test() before 544 /* Warning : We must perform the atomic_dec_and_test() before
545 * setting skb->fclone back to SKB_FCLONE_UNAVAILABLE, otherwise 545 * setting skb->fclone back to SKB_FCLONE_FREE, otherwise
546 * skb_clone() could set clone_ref to 2 before our decrement. 546 * skb_clone() could set clone_ref to 2 before our decrement.
547 * Anyway, if we are going to free the structure, no need to 547 * Anyway, if we are going to free the structure, no need to
548 * rewrite skb->fclone. 548 * rewrite skb->fclone.
@@ -553,7 +553,7 @@ static void kfree_skbmem(struct sk_buff *skb)
553 /* The clone portion is available for 553 /* The clone portion is available for
554 * fast-cloning again. 554 * fast-cloning again.
555 */ 555 */
556 skb->fclone = SKB_FCLONE_UNAVAILABLE; 556 skb->fclone = SKB_FCLONE_FREE;
557 } 557 }
558 break; 558 break;
559 } 559 }
@@ -874,7 +874,7 @@ struct sk_buff *skb_clone(struct sk_buff *skb, gfp_t gfp_mask)
874 return NULL; 874 return NULL;
875 875
876 if (skb->fclone == SKB_FCLONE_ORIG && 876 if (skb->fclone == SKB_FCLONE_ORIG &&
877 n->fclone == SKB_FCLONE_UNAVAILABLE) { 877 n->fclone == SKB_FCLONE_FREE) {
878 n->fclone = SKB_FCLONE_CLONE; 878 n->fclone = SKB_FCLONE_CLONE;
879 /* As our fastclone was free, clone_ref must be 1 at this point. 879 /* As our fastclone was free, clone_ref must be 1 at this point.
880 * We could use atomic_inc() here, but it is faster 880 * We could use atomic_inc() here, but it is faster