sk_buff's allocated from private pools
Subsystems (2)
PATCH 1/1 sk_buff's allocated from private pools
Hello,
I'm submitting this patch for inclusion in the Linux kernel if deemed generally useful.
The purpose of this patch is to add a new function called alloc_skb_custom() (or whatever) that allows the data portion of an sk_buff to reside in any memory region, not just a region returned by kmalloc(). For example, if a networking device has a restriction on where receive buffers may reside, then the device driver can avoid copying every incoming packet if it is able to create an sk_buff that points to the receive buffer memory.
Basically this amounts to adding a 'free_data' function pointer to the sk_buff structure. By default this points to kfree() but in general could point to anywhere.
FYI FreeBSD has had equivalent functionality in its 'struct mbuf' for many years (I'm also a FreeBSD developer).
Thanks for your review.
Cheers,
-Archie
__________________________________________________________________________
Archie Cobbs * Precision I/O * http://www.precisionio.com
Index: include/linux/skbuff.h
===================================================================
RCS file: /home/cvs/linux-2.4.20/include/linux/skbuff.h,v retrieving revision 1.1.1.1
retrieving revision 1.2
linux/skbuff.h +3 -0
@@ -193,6 +193,7 @@unsigned char *tail;/* Tail pointer */ unsigned char *end;/* End pointer */ +void (*free_data)(const void *);/* Free data buffer function */ void (*destructor)(struct sk_buff *);/* Destruct function */ #ifdef CONFIG_NETFILTER /* Can be used for communication between hooks. */
@@ -230,6 +231,8 @@extern void __kfree_skb (struct sk_buff *skb);extern struct sk_buff *alloc_skb (unsigned int size,int priority); +extern struct sk_buff *alloc_skb_custom (unsigned int size,int priority, +void (*free_data)(const void *),u8 *data);extern void kfree_skbmem (struct sk_buff *skb);extern struct sk_buff *skb_clone (struct sk_buff *skb,int priority);extern struct sk_buff *skb_copy (const struct sk_buff *skb,int priority);
Index: net/netsyms.c
===================================================================
RCS file: /home/cvs/linux-2.4.20/net/netsyms.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
netsyms.c +1 -0
@@ -489,6 +489,7 @@EXPORT_SYMBOL (eth_copy_and_sum);#endif EXPORT_SYMBOL (alloc_skb); +EXPORT_SYMBOL (alloc_skb_custom);EXPORT_SYMBOL (__kfree_skb);EXPORT_SYMBOL (skb_clone);EXPORT_SYMBOL (skb_copy);
Index: net/core/skbuff.c
===================================================================
RCS file: /home/cvs/linux-2.4.20/net/core/skbuff.c,v retrieving revision 1.1
retrieving revision 1.3
core/skbuff.c +52 -11
117 lines not on this page · raw message
PATCH 1/1 sk_buff's allocated from private pools
Quoted 12 lines · Archie Cobbs
Hello,
I'm submitting this patch for inclusion in the Linux kernel if deemed generally useful.
The purpose of this patch is to add a new function called
alloc_skb_custom()(or whatever) that allows the data portion of ansk_buffto reside in any memory region, not just a region returned bykmalloc(). For example, if a networking device has a restriction on where receive buffers may reside, then the device driver can avoid copying every incoming packet if it is able to create ansk_buffthat points to the receive buffer memory.
Quoted 3 lines
Basically this amounts to adding a '
free_data' function pointer to thesk_buffstructure. By default this points tokfree()but in general could point to anywhere.
FYI.
The skb recycling patches I play with uses the same callback and has an implementation for private buffers and sync's with outstanding callback marked skb's etc.
ftp://robur.slu.se/pub/Linux/net-development/skb_recycling/recycle19.pat ftp://robur.slu.se/pub/Linux/net-development/skb_recycling/e1000-RC-030217.pat
Also for SMP it marks in skb header in which cpu skb_headerinit was done so callback has a chance to re-route skb to the origin CPU to minimize cache bouncing in case of recycling. Also skb_headerinit is moved to be the first operation the a skb life of skb not last.
Current implementation uses only kmalloc for data part so your alloc_skb_custom add some new value.
Cheers.
--ro