posts - 403, comments - 310, trackbacks - 0, articles - 7
            BlogJava :: 首頁(yè) :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理

          讀核筆記(6) - 虛擬存儲(chǔ)

          Posted on 2008-02-27 23:29 ZelluX 閱讀(704) 評(píng)論(4)  編輯  收藏 所屬分類: LinuxSystem

          本來(lái)想看完pagefault的處理的,不過(guò)實(shí)驗(yàn)室有事情了,只能先把這一半放上來(lái)了。

          頁(yè)面的分配與回收使用了一個(gè)叫做buddy allocator的機(jī)制,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{} 中保存了一個(gè)free_area_t數(shù)組,這個(gè)數(shù)組記錄了各種大小的空閑內(nèi)存塊的信息。
          include/linux/mmzone.h:


          free_area_struct {}

          頁(yè)面分配時(shí),找到適合大小的free_area_struct{},然后從free_list中找有沒(méi)有空閑的內(nèi)存塊,如果沒(méi)有就找更大的free_area_struct{},因?yàn)榇笮《际?^n,很容易把大塊內(nèi)存拆開(kāi),一塊分配給請(qǐng)求,剩下的保存到對(duì)應(yīng)大小的隊(duì)列中。
          頁(yè)面回收時(shí)主要的問(wèn)題是如何解決過(guò)多的內(nèi)存碎片。當(dāng)頁(yè)面塊被釋放時(shí),先檢查是否有相同大小的相鄰空閑塊存在,如果有的話就結(jié)合起來(lái)(遞歸過(guò)程)。

          評(píng)論

          # re: 讀核筆記(6) - 虛擬存儲(chǔ)  回復(fù)  更多評(píng)論   

          2008-03-13 13:49 by Kommit
          來(lái)踩踩~~~

          # re: 讀核筆記(6) - 虛擬存儲(chǔ)  回復(fù)  更多評(píng)論   

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

          # re: 讀核筆記(6) - 虛擬存儲(chǔ)  回復(fù)  更多評(píng)論   

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

          # re: 讀核筆記(6) - 虛擬存儲(chǔ)  回復(fù)  更多評(píng)論   

          2008-03-14 16:25 by ZelluX
          @luohandsome
          看的是那本邊干邊學(xué),差不多兩星期沒(méi)看過(guò)了
          主站蜘蛛池模板: 泗水县| 津市市| 左权县| 泰来县| 德格县| 泰宁县| 蓝山县| 泗阳县| 黎平县| 南昌县| 贞丰县| 抚远县| 清远市| 珠海市| 白银市| 民和| 三河市| 绥中县| 柳林县| 公主岭市| 定安县| 彭山县| 大石桥市| 冷水江市| 西平县| 苍南县| 正镶白旗| 涿鹿县| 大方县| 蒙城县| 乳山市| 望谟县| 东山县| 石渠县| 平罗县| 新沂市| 凌海市| 广水市| 五家渠市| 舟山市| 天峨县|