Re: [理工] 計概 Memory計算問題
※ 引述《wayneshiau (Wayne)》之銘言:
: 跟朋友看到一題計概題目如下:
: https://imgur.com/a/byDFqa6
: 有點沒有頭緒該如何計算
: 目前已知A小題應該分別是
: 36 (64GB=2^36)
: 2^36/2^12 = 2^24 Frames
: 2^32/2^12=2^20
: 想請問 B C小題應該要如何計算?
: 謝謝
有錯請指正
由題目得知page size 為 4kb(12bits)
因此 32bits virtual address 一定可以先分割成
------------------
| 20bits | 12bits |
------------------
但是 physical space 實際上為 64GB, virtual space 為4GB
所以要完整利用 physical space, 因此實際上分為 64/4 = 16個區塊
因此可以用 4 bits 來表示區塊offset
--------------------------
| 4bits | 16 bits | 12bits |
---------------------------
因此這樣就完成 single level mapping :
用 2^16 個 size 為 8bytes 的 mapping entries 組成的 page table
來指向 64GB physical memory
block 8bytes physical mem
----- -------- --------------
| 0 |----> | 0 | ---------> | |
----- -------- | 4KB |
| ... | | 1 | |-------------
----- --------
| 15 | | .... | ......
----- -------- -------------
| 2^16-1 | | |
--------- | 4KB |
--------------
因為 single level page table 需要一次放在memory 中太大了
共需要 2^16 * 8bytes = 2^19 = 512KB
因此假若我把 page table 當成一般的資料看待, 我一樣把page table切塊
每一塊大小依然是 4KB, 因此可以切成 512KB/4KB = 128 個 pages
換句話說也就是 16bits - 7bits = 9 bits
也就是說多加一層的 2 level mapping 會產生:
上層為一個 2^9 個 entries 的 mapping table
而上層 mapping table 的每個 entries 可指到下一層大小為 128 entries 的mapping
而 bottom mapping table 共有 512 個
若我使用 demand paging
實際上我在 memory 中只要放一個完整的 upper mapping + 一個 bottom mapping
共消耗 512*8bytes + 128*8bytes = 5120bytes
也就是下面圖
---------------------------------
| 4bits | 9bits | 7bits | 12bits|
--------------------------------
block upper bottom phy mem
------ -------- ------- ---------
| 0 | ---> | 0 | -----> | 0 | --------> | |
------- --------- ------- | 4kb |
| ... | | 1 | | 1 | |------- |
------- -------- ------- | |
| 15 | | ..... | | .... | | .... |
------- --------- -------- | |
| 511 | --- | 127 | --------
--------- | --------- | |
| | 4kb |
| | |
| ---------
--> ---------
| 0 |
-------
| 1 |
-------
| ..... |
---------
| 127 |
---------
然後繼續切成 level 3(以最後的mapping對齊)
-----------------------------------------
| 4bits | 2bits | 7bits | 7bits | 12bits |
------------------------------------------
因此應該是可以形成 3 level mapping
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 1.175.69.238 (臺灣)
※ 文章網址: https://www.ptt.cc/bbs/Grad-ProbAsk/M.1603524355.A.51C.html
推
10/25 09:23,
3年前
, 1F
10/25 09:23, 1F
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 2 之 2 篇):