posts - 403, comments - 310, trackbacks - 0, articles - 7
  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理

读核笔记(6) - 虚拟存储

Posted on 2008-02-27 23:29 ZelluX 阅读(671) 评论(4)  编辑  收藏 所属分类: LinuxSystem

本来想看完pagefault的处理的,不过实验室有事情了,只能先把这一半放上来了。

页面的分配与回收使用了一个叫做buddy allocator的机制,kernelnewbies上的解释
The memory allocation scheme used in the kernel. A vector of lists of free pages is kept, ordered by the size of the chunk (in powers of two). When a chunk is allocated, it is removed from the relevant list. When a chunk is freed back to the free pages pool, it is placed in the relevant list, starting from the top. If it is physically contiguous with a present chunk, they are merged and placed in the list above (i.e. where the chunks are twice the size), and this operation percolates up the vector. As regions are merged whenever possible, this design helps to reduce memory fragmentation.

首先在zone_struct{} 中保存了一个free_area_t数组,这个数组记录了各种大小的空闲内存块的信息。
include/linux/mmzone.h:


free_area_struct {}

页面分配时,找到适合大小的free_area_struct{},然后从free_list中找有没有空闲的内存块,如果没有就找更大的free_area_struct{},因为大小都是2^n,很容易把大块内存拆开,一块分配给请求,剩下的保存到对应大小的队列中。
页面回收时主要的问题是如何解决过多的内存碎片。当页面块被释放时,先检查是否有相同大小的相邻空闲块存在,如果有的话就结合起来(递归过程)。

评论

# re: 读核笔记(6) - 虚拟存储  回复  更多评论   

2008-03-13 13:49 by Kommit
来踩踩~~~

# re: 读核笔记(6) - 虚拟存储  回复  更多评论   

2008-03-13 14:37 by ZelluX
@Kommit
哇,版大 @.@

# re: 读核笔记(6) - 虚拟存储  回复  更多评论   

2008-03-14 13:53 by luohandsome
page fault很有意思。尤其是exception table和fix code
土问,你看的是ULK?

# re: 读核笔记(6) - 虚拟存储  回复  更多评论   

2008-03-14 16:25 by ZelluX
@luohandsome
看的是那本边干边学,差不多两星期没看过了

只有注册用户登录后才能发表评论。


网站导航: