address_space对象是文件系统中关于内存中页高速缓存的核心数据结构。这篇博客以address_space对象为切入点,分析文件系统的页高速缓存。
1背景
在文件系统中,内存中存在着dentry和inode结构,其中其分别的作用可以见我另一篇博客《dentry与inode》。由于这些结构要反复使用,所以内存里开辟了目录项高速缓存以及索引结点高速缓存,提高其访问速度。但这里要提到的是另一种高速缓存:页高速缓存,它是一种对完整的数据页进行操作的磁盘高速缓存,即把磁盘的数据块缓存在页高速缓存中。而address_space对页高速缓存进行管理。
2页高速缓存介绍
linux中几乎所有文件的读和写操作都依赖于页高速缓存。只有在O_DIRECT标志置为才会出现意外:此时,I/O数据的传送绕过了页高速缓存而使用了进程用户态地址空间的缓冲区;另外,少量的数据库软件为了采用自己的磁盘高速缓存算法而使用了O_DIRECT标志。
why设计页高速缓存?
答:1.快速定位所有者相关数据页的位置(基树)。2.区分不同所有者页的不同读写操作,如普通文件、块设备文件、交换区文件读一个数据页必须使用不同的方式实现,故内核根据页的不同所有者进行不同的操作。
3address_space对象
每一个所有者(可以理解为一个具体的文件,一个inode指向的文件)对应着一个address_space对象,页高速缓存的多个页可能属于一个所有者,从而可以链接到一个address_space对象。那么一个页(page)怎么和一个address_space产生关联的呢?
page中有两个字段:mapping和index。其中mapping指向该页所有者的address_mapping(内存inode结构有一个i_mapping指向对应address_space对象),index字段表示所有者地址空间中以页大小为单位的偏移量。用这两个字段就能在页高速缓存中查找也。(这里注意一点,一个页中所包含的磁盘块在物理上不一定是相邻的)
address_space中有一个host字段,该字段指向其所属的inode,也就是address_space中的host字段 与 对应inode中的 i_data字段形成互相指向的关系。若为普通文件,那么inode结点和address_space结构的相应指针的指向关系如下图:
4基树
linux支持TB级的文件,ext4甚至支持到了PB级文件,访问大文件时,高速缓存中存在着有关该文件太多的页,故设计了基树这个结构来加快查找。一个address_space对象对应一个基树。
address_space中有一个字段(page_tree)指向是基树的根(radix_tree_node)。基树根中的rnode指向基树的最高层节点(radix_tree_node),基树节点都是radix_tree_node结构,节点中存放的都是指针,叶子节点的指针指向页描述符,上层节点指向存放其他节点的指针。一般一个radix_tree_node最多可以有64个指针,字段count表示该radix_tree_node已用节点数。
怎么快速找到所需页在基树中的位置呢?
回顾本科所学知识:分页系统如何利用页表实现线性地址到物理地址的转换?线性地址的最高20位分为两个10为的字段:第一个字段是页目录的偏移,第二个字段是页目录所指向也表的偏移。
在基树中,类比此方法。若基树深度为1,则只能表示从0至63的索引,则页索引(上文提高的index字段)的低6位进行解析,从而对应成radix_tree_node结构中的slot下标,找到对应的页;若基树深度为2,则页索引的低12位分成0~5,6~11两个字段进行解析。分别找到第一层slot字段和第二层slot字段的值。
2022年8月28日 19: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.
2022年8月29日 19:13
Buy Twitter PVA Accounts
The website is looking a bit flashy and it catches the visitor's eyes. The design is pretty simple and has a good user-friendly interface.
2022年8月29日 21:19
UK Board 10th Previous Question Paper are very important for the Preparation of Public Exam of UBSE for the Students. 10th Students of can easily get their Latest and most valuable Mock Test Paper from this website. UK Board Question Paper Students only have to Download the UBSE 10th Mock Test Paper 2023 for all the important subjects are available Including the Hindi, English, Social Science, Mathematics, Science, Home Science, Sanskrit, Painting etc. Boardmodelpaper.com Provide UBSE Board 10th Class Latest and Last Year Exam Study Material for Syllabus , Question Paper etc, Hindi, English Medium Pdf Format.
2022年8月30日 02:09
Very useful post. This is the first time I am visiting here. I found so much interesting stuff in your blog, especially its discussion. Really it's a great article. Keep it up.
2022年8月30日 03:32
Buy Instagram PVA Accounts
Great info! I recently came across your blog and have been reading along. I thought I would leave my first comment. I don’t know what to say except that I have.
2022年8月30日 16:29
buy gmail PVA accounts
Thank you very much for sharing these links. Will definitely check this out.
2022年8月30日 17:36
Instagram pva accounts
Very useful post. This is the first time I am visiting here. I found so much interesting stuff in your blog, especially its discussion. Really it's a great article. Keep it up.
2022年9月02日 03:08
Buy YouTube Pva Accounts
The information you have posted is very useful. The sites you have referred were good. Thanks for sharing this.
2022年9月02日 03:08
Buy YouTube Pva Accounts
The information you have posted is very useful. The sites you have referred were good. Thanks for sharing this.
2022年9月06日 17:49
Buy pva instagram accounts
Wonderful illustrated information. I thank you for that. No doubt it will be very useful for my future projects. Would like to see some other posts on the same subject!
2022年9月14日 13:05
Buy Twitter pva accounts
Great info! I recently came across your blog and have been reading along. I thought I would leave my first comment. I don’t know what to say except that I have.
2022年9月14日 13:29
Buy Instagram pva accounts
You know your projects stand out from the herd. There is something special about them. It seems to me all of them are really brilliant!
2022年9月14日 14:00
afro hair and beauty store
I love this blog! The flash up the top is awesome!
2022年9月20日 14:46
Buy instagram pva accounts
Thanks for the post and great tips. Even, I also think that hard work is the most important aspect of getting success.
2022年9月20日 19:11
Buy Bulk Gmail Accounts
I highly appreciate this post. It’s hard to find the good from the bad sometimes. but I think you’ve nailed it! would you mind updating your blog with more information?
2022年9月26日 01:18
Buy Gmail PVA Accounts
Thanks for the post and great tips. Even, I also think that hard work is the most important aspect of getting success.
2022年9月26日 01:19
Buy Gmail PVA Accounts
Thanks for the tips and information. I really appreciate it.
2022年9月27日 19:45
hair beauty products online
This is a great inspiring article. I am pretty much pleased with your good work. You put really very helpful information.
2022年10月02日 18:00
buy gmail pva accounts
Wow-what Great Information about World Day is a very nice informative post. Thanks for the post.
2022年10月02日 21:20
Instagram pva accounts
Great survey. I'm sure you're getting a great response.
2022年10月14日 00:41
Rail Road Safety in Nevada
Excellent and very exciting site. Love to watch. Keep Rocking.
2022年10月16日 00:23
I am very happy to discover your post as it will become on top of my collection of favorite blogs to visit.
2022年10月28日 20:48
all you can eat baden baden
I read that Post and got it fine and informative. Please share more like that.
2022年10月31日 00:41
It's a great pleasure reading your post. It's full of information I am looking for and I love to post a comment that "The content of your post is awesome" Great work.
2022年10月31日 23:32
Digital transaction facilities are gaining popularity in India and the whole world. The online money transfer methods allow users to send and receive money fast and on inconvenient platforms. UPI Registration Failed BHIM app is a significant money transfer platform that provides ease in transacting funds between various bank accounts. The app is available on mobile devices, making it a suitable banking method for many Indian residents.
2022年11月03日 04:56
Great to have you here, Here you will find more information about a private detective. Foglight PI is #1 private detective agency in the world.
2022年11月06日 18:40
LG Refrigerator Repair
I am no expert. But I believe you just made an excellent point. You certainly fully understand what you are speaking about. and I can truly get behind that.
2022年11月25日 13:26
Superbly written article. If only all bloggers offered the same content as you. the internet would be a far better place.
2022年11月25日 23:55
Digital Design Agency
You know your projects stand out from the herd. There is something special about them. It seems to me all of them are really brilliant!
2022年12月01日 16:04
office space for rent
Yes, I am totally agreed with this article and I just want to say that this article is a very nice and very informative article. I will make sure to be reading your blog more. You made a good point but I can't help but wonder. what about the other side? Thanks!
2022年12月11日 15:36
eichler roof construction
I would like to say that this blog really convinced me to do it! Thanks. Very good post.
2022年12月24日 05:23
GM Web Solutions have a highly
the skilled team of developers. We
take care of your business with
the proper tools and modern
techniques.
2022年12月24日 05:24
Publish your passions your way.
Whether you''d like to share your
knowledge, experiences or the
latest news, create a unique and
beautiful blog.
2022年12月24日 05:25
Great to have you here, Here you
will find more information about
a private detective. Foglight PI
is #1 private detective agency
in the world
2023年3月08日 17:34
Foxhills Realty offers a wide variety of real estate services including buying, selling, and leasing properties. We have experts in every field to help you with all of your needs. Fox Hills Realty
2023年4月27日 03:48
Instagram pva accounts
This is very educational content and written well for a change. It's nice to see that some people still understand how to write a quality post!
2023年4月27日 04:04
Instagram pva accounts
Positive site. Where did you come up with the information on this posting? I'm pleased I discovered it though. I will be checking back soon to find out what additional posts you include.
2023年4月28日 08:34
I think that thanks for the valuable information and insights you have so provided here.
2023年5月25日 00:31
Buy bulk gmail accounts
I have read your article. It is very informative and helpful for me. I admire the valuable information you offer in your articles. Thanks for posting it.
2023年5月25日 01:56
buy Facebook pva accounts
Thanks for posting this info. I just want to let you know that I just check out your site and I find it very interesting and informative. I can't wait to read lots of your posts.