struct buffer_head 效率低下
有人能说出为什么 Linux Kernel 2.4 之前使用的 struct buffer_head 结构效率低下的原因以及从内核 2.5.1 开始重新设计的新块层中使用的 struct bio 结构中实现了哪些内容吗?
Can anybody tell the reason why the struct buffer_head structure which were used till Linux Kernel 2.4 is inefficient and what things are implemented in the struct bio structure used in the new redesigned block layer from kernel 2.5.1 ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在 2.5 之前的内核中,buffer_head 曾经是 IO 的单位。然而,根据 buffer_head 进行 IO 可能效率很低。例如,跨越多个块的单个写入将导致创建多个 buffer_head 对象,从而浪费空间和时间。因此,buffer_head 结构最适合提供块到物理内存的映射,这正是它从 2.5 开始所做的事情(也是它所做的唯一事情)内核开始。
另一方面,struct bio 被设计为后续内核版本中的 IO 单元。 **它代表当前内核中的活动 IO strong>.** 请注意,块到内存的映射仍然保留在 buffer_head 中。然而,buffer_head 现在并没有因包含当前活动 IO 信息的字段而过载。因此,当文件系统等更高级别的代码发出 IO 时,请求就会添加到 request_queue 中。该请求又包含指向 bio 结构的指针。设备驱动程序控制发出 IO 的设备,接收请求并为其提供服务。
struct bio 结构还用于分割 IO,例如,通过 RAID 磁盘设备驱动程序。查看 struct bio 定义,您会发现它维护了一个 io_vector 数组(它们只不过是内存页的偏移量)。此外,bi_idx 用于索引这些 io_vec。通过对不同的磁盘使用不同的 bi_idx 值,每个磁盘将拾取一组不同的 io_vec 进行写入(或读取),因此 IO 将以真正的并行方式完成。
In pre-2.5 kernels, buffer_head used to be the unit of IO . However, doing IO in terms of buffer_head can be inefficient. For example, a single write spanning multiple blocks would result in creation of multiple buffer_head objects, thus wasting space and time. So, a buffer_head struct is best used for providing the block-to-physical memory mapping, which is exactly what it does (and the only thing that it does) from 2.5 kernel onwards.
On the other hand, struct bio is designed to be the unit of IO in later kernel releases. **It represents the active IOs currently in the kernel.** Note that the mapping of block-to-memory is still maintained in buffer_head. However, the buffer_head is now not overloaded with the fields that contain info about currently active IO. So, when higher level code such as filesystem, issues an IO, a request is added to the request_queue. The request in turn contains a pointer to the bio structure. The device driver that controls the device on which IO is issued, picks up the request and serves it.
The struct bio structure is also used for splitting IOs, for example, by RAID disk device drivers. Look at the struct bio definition and you will find that it maintains an array of io_vectors (which are nothing but offsets into memory pages). Also, bi_idx is used to index into these io_vec. By using a different bi_idx value for different disk, each disk will pick up a different set of io_vec to write (or read), and thus the IO would be done in a true parallel fashion.
使用来源,卢克!
来自
include/linux/buffer_head.h
:以及来自
linux/include/bio.h
:这两个解耦 I/O 特性和“更高级别”的操作(I/ O 通过文件系统)和“低级别”(I/O 通过块开发)。这可以实现更高的性能,因为在某处等待的缓冲层不会阻止块层在其他地方执行工作。关于它的一些解释可以在此处找到,Jens Axboe 对此进行了讨论在这次采访中简要介绍。
Use the source, luke !
From
include/linux/buffer_head.h
:And from
linux/include/bio.h
:The two decouple I/O characteristics and operations for "higher levels" (I/O through filesystems) and "low levels" (I/O through block devs). This allows for higher performance because a buffer layer waiting somewhere doesn't stop the block layer from performing work elsewhere. Some explanation about it can be found here, and Jens Axboe talks about it in this interview briefly.
Robert Love 的 LKD 3rd 对此有非常详细的解释。
Robert Love's LKD 3rd have a very detail explanation on this.