- 论坛徽章:
- 0
|
原帖由 思一克 于 2007-6-20 19:44 发表于 22楼
没有bh的原因是block的大小等于page大小.
你前边说linux ext2 block大小一般是1024. 不是的, 一般是4096.
>>没有bh的原因是block的大小等于page大小.
我想不是这样的,这个可以通过源码来证明。以读为例子,我们从regluar file的read操作中和page cache打交道的函数do_generic_mapping_read()开始(这里只列出了和page cache相关的函数):
do_generic_mapping_read() --->find_get_page() ---->radix_tree_lookup() ---->__lookup_slot()
上述就是read操作在page cache中查找对应page的过程,整个过程中我们可以看出,kernel是以radix_tree_node 这个结构来管理以页为单位的page cache的,它是直接查找radix树,不涉及到buffer page(也就是包含bh结构的page)。
对于bh存在的理由,我们用一段ULK上的话来解释:
- In old versions of the Linux kernel, there were two different main disk caches: the page cache, which stored whole pages of disk data resulting from accesses to the contents of the disk files, and the buffer cache , which was used to keep in memory the contents of the blocks accessed by the VFS to manage the disk-based filesystems.
- Starting from stable version 2.4.10, the buffer cache does not really exist anymore. In fact, for reasons of efficiency, block buffers are no longer allocated individually; instead, they are stored in dedicated pages called "buffer pages ," which are kept in the page cache.
- [color=Red]Formally, a buffer page is a page of data associated with additional descriptors called "buffer heads ," whose main purpose is to quickly locate the disk address of each individual block in the page. In fact, the chunks of data stored in a page belonging to the page cache are not necessarily adjacent on disk[/color]
复制代码
可以看出,bh的主要目的在于一个page中包含的block在disk不相邻的情况。这种不相邻的情况就是我说的文件的hole(对于regular file)。
此外,我的印象中记得linux默认的block是1024字节,但刚才查了查资料又看看了源码,没有找到证明。版主说是4k,什么地方能查到呢?我认为4k的block对于设备来说太大了,因为DMA操作多以segment为单位,一个segment包含多个sector。硬件规定了segment中的sector必须物理上连续,所以如果一个block太大的话,包含不连续sector的概率就会增大,这样很可能一个次I/O要拆分成多次dma,毕竟block是VFS管理文件的单位。 |
|