9
22
2014
14

buffer_head理解、解析

在上一篇博客介绍address_space中,我们有提到,内存中一个page所包含的磁盘块在物理上不一定是相邻的。那么page中不同的磁盘块怎么管理呢?这里就涉及到了buffer_head结构。

把块存放在页高速缓存中就会涉及到块缓存区和缓冲区首部。

每个buffer_head管理的单元是内存页中对应的一个物理块,也就是说buffer_head管理单元是 “页”的一个子集。

下面以页的大小为4k,block大小为1k来描述这个问题。在这种情况下,一个页中就会有四个缓冲区对应着四个buffer_head结构管理。页描述符page 中private指针指向其中一个缓冲区首部,缓冲区首部内部通过链表结构(b_this_page)链接该页对应的四个缓冲区。缓冲区首部(buffer_head)的b_page指针指向对应的page结构,b_data指向数据在对应的页中的位置。

如下图:

 

下面部分结合代码内容分析如何将buffer_head所管理的缓冲区转化成下发到磁盘的io请求。

首先submit_bh()函数,其作用:根据缓冲区首部的内容创建一个bio,在该函数中通过buffer_head传进来的信息对bio的信息赋值。如下

 

	bio->bi_sector = bh->b_blocknr * (bh->b_size >> 9); //扇区号
	bio->bi_bdev = bh->b_bdev; //设备,如分区
	bio->bi_io_vec[0].bv_page = bh->b_page; //对应页
	bio->bi_io_vec[0].bv_len = bh->b_size;  //块大小
	bio->bi_io_vec[0].bv_offset = bh_offset(bh); //buffer_head指向的缓存区相对于其所在页的偏移

 

然后submit_hb()调用submit_bio(),把rw数据传输方向赋值。

在submit_bio()中调用generic_make_request()函数。通过generic_make_request()函数把bio递交到通用块层。有关generic_make_request的函数解析,参照:

http://blog.chinaunix.net/uid-9988622-id-1995526.html

http://www.powerlinuxchina.net/club/viewthread.php?action=printable&tid=1239

generic_make_request()函数式递交一个bio的开始。每个进程的task_struct中,都包含两个变量: struct bio *bio_list,**bio_tail,该函数就是通过维护这两个变量来维护待添加的bio链表。generic_make_request函数调用__generic_make_request函数完成。而在__generic_make_request会调用make_request_fn,make_request_fn可能自行实现时递归调用generic_make_request,有了栈的深度有限,英雌通过genenric的设计,是的递归调用深度不超过1,具体是:一旦开始把当前的bio链表下发,则新到的bio不能加入正在下发的链表中。

generic_make_request函数调用__generic_make_request.

__generic_make_request做的事情很简单,先通过blk_partition_remap检查设备是否为磁盘分区,然后把相对于分区的起始扇区号转化为相对于整个磁盘的扇区号,然后调用q->make_request_fn()到达IO调度层,而make_request_fn主要是通过__make_request()函数实现的

Category: 文件系统 | Tags: | Read Count: 8723
Avatar_small
aaaa 说:
2019年9月04日 15:22

<script>alert('xxx')</script>

Avatar_small
HBSE Question Paper 说:
2022年9月03日 15:33

Haryana Board Model Paper 2023 Class 3 Pdf Download with Answers for English Medium, Hindi Medium, Urdu Medium & Students for Small Answers, Long Answer, Very Long Answer Questions, and Essay Type Questions to Term1 & Term2 Exams at official website. HBSE Question Paper Class 3 New Exam Scheme or Question Pattern for Sammittive Assignment Exams (SA1 & SA2): Very Long Answer (VLA), Long Answer (LA), Small Answer (SA), Very Small Answer (VSA), Single Answer, Multiple Choice and etc.

Avatar_small
Alyssa 说:
2022年12月18日 20:44

A buffer is a temporary storage area in a computer's memory that is used to hold data that is being transferred from one place to another. The buffer is lupus contagious head is the part of the buffer that is responsible for managing the data as it is being transferred. This involves keeping track of where the data is in the buffer, how much data has been transferred, and how much space is left in the buffer.

Avatar_small
Website 说:
2023年1月20日 01:44

Instagram PVA accounts
I found that site very useful and this survey is very curious. I've never seen a blog that demands a survey for these actions. Very curious.

Avatar_small
Website 说:
2023年1月20日 01:55

Buy Gmail pva accounts
Thank you for taking the time to publish this information very useful.

Avatar_small
Website 说:
2023年1月20日 02:13

Buy Gmail pva accounts
Very interesting post. This is my first-time visiting here. I found so much interesting stuff in your blog, especially its discussion. Thanks for the post!

Avatar_small
Free CIBIL score 说:
2023年1月21日 22:14

CIBIL is an organization and an entity gathers all the consumer’s loan, credit, payment and money related transaction, and this gives a general behavior example and statics allowing to generate a score for each customer also calls as CIBIL score. Free CIBIL score Check CIBIL score is before you try to apply for a home loan, want to buy something new on EMI, or need to request any credit facility for a loan, then the primary thing they would look for is what is your CIBIL score to be precise.

Avatar_small
Website 说:
2023年1月25日 02:27

Buy Instagram PVA Accounts
It is imperative that we read blog posts very carefully. I am already done with it and find that this post is really amazing.

Avatar_small
Website 说:
2023年1月25日 02:45

Buy Gmail Accounts
Great article lots of information to Read. Great Man Keep Posting and update to People. Thanks.

Avatar_small
Website 说:
2023年1月25日 03:03

Buy Gmail PVA Accounts
This is the first time I am visiting here and I found so much interesting stuff in your blog, especially its discussion. Thank you.

Avatar_small
Website 说:
2023年1月25日 23:20

Viking Range Repair
Thanks for sharing the info. Keep up the good work going. I really enjoyed exploring your site. Good resource.

Avatar_small
Website 说:
2023年2月02日 01:56

Bathroom remodeling services in los altos
Excellent website you have here. So much cool information!

Avatar_small
198.168.o.1 说:
2023年2月03日 14:29

Internet is something we all use in our daily life to experience different things from Entertainment in our personal life to getting extensive work done in the office life as well, but in order to do this you might turn to your Internet connection via the Wi-Fi which is only accessible if you have a router that allows to give you Wireless connection. 198.168.o.1 there are a lot of routers all across the world that use different Internet Protocol Gateways to access the Admin panel and some of these routers use the IP Address 192.168.0.1.


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter

Host by is-Programmer.com | Power by Chito 1.3.3 beta | Theme: Aeros 2.0 by TheBuckmaker.com