-
alloc_skb_from_cache()
日期:2007-12-20 | 分类:网络编程
版权声明:转载时请以超链接形式标明文章原始出处和作者信息及本声明
http://scudong.blogbus.com/logs/12357873.html
The post-2.6.10 mainline kernel contains a set of patches designed to help with the merging of the Xen virtual architecture. One of them is an enhancement to the networking API which could have uses beyond Xen.The "socket buffer" (SKB) is the core kernel data structure used to represent packets as they pass through the system. The SKB API has been described for 2.4 in LDD2; this interface has changed little since then. SKB structures are allocated in various ways by the networking layer; the Xen patches add a new way:
struct sk_buff *alloc_skb_from_cache(kmem_cache_t *cache, unsigned int size, int gfp_mask);This function will allocate an SKB of the given size from the slab cache provided. It assumes that the cache will provide a chunk of memory of sufficient size for the buffer - and various bits of overhead imposed by the SKB structure itself.
The new allocation function might speed things slightly for network drivers which allocate large numbers of buffers of the same size - though the existing allocation interfaces are already pretty fast. Xen has an interesting use for this capability, however: fast networking between virtual machines. By using the slab cache, Xen can ensure that every packet is allocated a one-page buffer. When that packet is sent to another virtual machine, the associated page can be unmapped from the source system and mapped into the address space of the destination. It is, in other words, a fairly straightforward zero-copy networking scheme. As a side benefit, the Xen monitor benefits from the knowledge that the pages in question have been used for network packets - since the contents of the packet could be read by third parties while it is in transit, there is no real point in worrying about zeroing out the data afterward.
如果想了解清楚slab内存分配机制,可以看博客里的另一篇详细介绍slab的文章
历史上的今天:
snort-0.96 一个用libpcap包实现的简单sniffer 2007-12-20Network block devices and OOM safety 2007-12-20The kernel and character set encodings 2007-12-20Ext3 for large filesystems 2007-12-20Network transmit batching 2007-12-20随机文章:
来自师兄的忠告 2008-03-01Distributed storage 2007-12-20基于 linux 平台的 libpcap 源代码分析 2007-12-12高性能UNIX网络编程 2007-12-07网络协议的层层分析 2007-10-14
收藏到:Del.icio.us







