Tuesday, April 16, 2013

When to use skb_clone versus skb_copy

Using skb_copy will copy both the sk_buff and the packet to new memory. Meaning when the kernel frees the other one, the copy will not be affected.
skb_clone in the other hand copies the sk_buff structure to new memory, but not the packet. Meaning when the old one is freed, your copy will have the packet also freed.

In most cases please try to use skb_clone() as it will save your system the additional overhead of copying an entire packet. This may not seem like much but under heavy loads this can severely affect performance and even lead to soft-lockups.