儒雅

在点点滴滴中进步;在细致细微处成长!

2007-10-15 12:22

dev_alloc_skb()

    dev_alloc_skb()也是一个缓冲区分配函数,它主要被设备驱动使用,通常用在中断上下文中。这是一个alloc_skb()的包装函数,它会在请求分配的大小上增加16字节的空间以优化缓冲区的读写效率,它的分配要求使用原子操作(GFP_ATOMIC),这是因为它是在中断处理函数中被调用的。
    dev_alloc_skb(length) uses the function alloc_skb() to create a socket buffer. The length of this socket buffer's packet data space is length + 16 bytes. Subsequently, skb_reserve(skb, 16) is used to move the currently valid packet data space 16 bytes backwards. This means that the packet has now a headroom of 16 bytes and a tailroom of length bytes.


/usr/src/linux-2.6.19/include/linux/skbuff.h
static inline struct sk_buff *dev_alloc_skb(unsigned int length)
{
     return __dev_alloc_skb(length, GFP_ATOMIC);
}

/usr/src/linux-2.6.19/include/linux/skbuff.h
static inline struct sk_buff *__dev_alloc_skb(unsigned int length,
                          gfp_t gfp_mask)
{
    struct sk_buff *skb = alloc_skb(length + NET_SKB_PAD, gfp_mask);
    if (likely(skb))
        skb_reserve(skb, NET_SKB_PAD);
    return skb;
}


/usr/src/linux-2.6.19/include/linux/skbuff.h
#ifndef NET_SKB_PAD
#define NET_SKB_PAD 16
#endif

评论