这是从myjesky的一个帖子中截取出来的的内容
http://topic.csdn.net/t/20050420/13/3951787.html
内存复制占用很多时间的,为什么还要用mbuf这样一个结构?
简单的说,如果传指针,那么上层用户如果无意之中释放了某块内存,那么整个协议栈就可能会崩溃,而导致内核的崩溃(协议栈中保持着大量的mbuf链表。BSD和linux内核只信任内核本身。
mbuf在层与层之间,就是传递指针的,至于为什么不直接使用应用层buf,有几个原因:
1. 应用层buf不一定能够满足需要,比方说,我需要在前面加上IP头,可是前面没有空间了。
2. 发送过程是一直延伸到物理层的,也就是说,假如直接使用应用层buf,那么直到驱动的芯片发送完报文之前,系统必须锁定这块内存,你的应用层能接受这种等待么,要知道某些链路的速度是很慢的,而CPU快得多,所有比较合理的方法是,将数据复制到mbuf中,然后后面的发送过程使用mbuf,程序则可以快速 返回。
下面是手册中对mbuf的描述:
An mbuf is a basic unit of memorymanagement in the kernel IPC subsystem.
Network packets and socket buffers arestored in mbufs. A network packet
may span multiple mbufs arranged into a mbufchain (linked list), which
allows adding or trimming network headerswith little overhead.
While a developer should not bother with mbufinternals without serious
reason in order to avoid incompatibilitieswith future changes, it is
useful to understand the general structureof an mbuf.
An mbuf consists of a variable-sizedheader and a small internal buffer
for data.The total size of an mbuf, MSIZE, is a constant defined in
<sys/param.h>. The mbuf header includes:
m_next (struct mbuf *) A pointer to the next mbufin the mbuf
chain.
m_nextpkt (struct mbuf *) A pointer to the next mbufchain in the
queue
m_data (caddr_t) A pointer to data attached tothis mbuf.
m_len (int) The length of the data.
m_type (short) The type of the data.
m_flags (int) The mbuf flags.
分享到:
相关推荐
bsd架设管理与应用
深度学习、数字图像处理常用数据集BSD68,BSD100,分别为68张灰度图,大小不一;100张彩色图像,大小不一。
描述了BSD中的arp实现。主要侧重于具体实现。有代码示例进行的解说。
学习BSD的朋友有福了,可以下下来学习学习,不错的资料
图像处理BSD68测试集灰度图像。图像处理(image processing),用计算机对图像进行分析,以达到所需结果的技术。又称影像处理。图像处理一般指数字图像处理。数字图像是指用工业相机、摄像机、扫描仪等设备经过拍摄...
KAME网络软件被网络界认为是IPv6的稳定的参考实现。就像BSD操作系统中的IPv4协议栈源代码极大地帮助了人们理解...最后介绍BSD特有的数据结构mbuf,以及KAME实现中对mbuf的扩展,这些信息被后面的章节多次引用和使用。
BSD500数据集包括图像分割和轮廓提取的Ground Truth,训练集和测试集各200张,验证集100张。
iOS中BSD socket的客户端的简单实现,希望对大家有帮助
The Design and Implementation of the 4.4BSD Operating System Marshall Kirk McKusick Keith Bostic Michael J. Karels John S. Quarterman Copyright © 1996 Addison-Wesley Longman, Inc The second ...
bsd_type.h
BSD hacks techniques
TCP/IP详解卷2中涉及到的4.4BSD-Lite源码,详见该书1.13节的说明。
bsd 的 rc.d 介绍 pdf english
百顺达BSD保安对讲机写频
当应用ISE 给FPGA的外界PROMS下载过程中,通过iMPACT边界扫描设备。结果扫描结果是一个FPGA(xc6slx9)和一个unknown device(说明:硬件资源:FPGA,是Xilinx的xc6slx9);PROMs,这里用的是Xilinx的xcf04s)。按理...
BSD A8驱动板 安卓系统 广告机 数据规格及事项
这是BSD中游戏源代码的。大家可以去下载这个操作系统的全部源代码,包括该部分代码,当然也可以直接在这边下载,只是要提供点积分而已^_^
中网的选择:放弃Linux转向BSD.pdf
86BSD压力传感器的IIC驱动代码和说明文档,代码中包含了温度和压力的计算公式,可参考附带文档,可交流
BSD的TCP/IP协议栈BSD的TCP/IP协议栈BSD的TCP/IP协议栈BSD的TCP/IP协议栈