How much Page Tables / PTEs are needed for xyz amount of memory?
TL;DR;
For m bytes virtual memory (up to 256T), you need
1 + m/2M + m/1G + m/512G
pagetables on all levels, each taking 4K in space.
Pagetables take roughly 1/512
proportion to virtual memory size.
base: we suppose we have:
- 4K page.
- 48bits Virtual Address, 4 level paging.
- Each pagetable takes exactly one page and is page aligned.
- Each pagetable entry (or translation table descriptor) takes 8 bytes.
- i.e. Each pagetable has exactly 512 entries.
- we name the translation phrases from L0 to L3 (see below)
- Notations:
⌊x⌋
and⌈x⌉
are integer floor and ceiling ofx
, repectively.
Virtual Address (48):
| 9 | 9 | 9 | 9 | 12 |
+----------+----------+----------+----------+--------------
| L0 index | L1 index | L2 index | L3 index | in page idx |
Calculations
For `n` pages (i.e. `n * 4KiB` memory):
---------------------------------------
L3 Entries : n
L3 Tables : ⌈ n/512 ⌉
L2 Entries : ⌈ n/512 ⌉
L2 Tables : ⌈ n/(512^2) ⌉
L1 Entries : ⌈ n/(512^2) ⌉
L1 Tables : ⌈ n/(512^3) ⌉
L0 Entries : ⌈ n/(512^3) ⌉
L0 Tables : 1 # per 48bit address space
# Memory Size increment in 4K
----------------------------------------------------------------
V Mem(m)| [4K,2M] (2M,1G] (1G,512G] (512G,256T]
----------------------------------------------------------------
#L3 ENT | [1,512] (512,512^2] (512^2, 512^3] (512^3, 512^4]
#L3 TBL | 1 (1 ,512 ] (512, 512^2] (512^2, 512^3]
----------------------------------------------------------------
#L2 ENT | 1 (1 ,512 ] (512, 512^2] (512^2, 512^3]
#L2 TBL | 1 1 (1, 512 ] (512 , 512^2]
----------------------------------------------------------------
#L1 ENT | 1 1 1 (512 , 512*2)
#L1 TBL | 1 1 1 (1 , 512 ]
----------------------------------------------------------------
#L0 ENT | 1 1 1 (1 , 512 ]
#L0 TBL | 1 1 1 1
----------------------------------------------------------------
#SUMTBLs| 4 3 + m/2M 2+m/2M+m/1G 1 + m/2M + m/1G + m/512G
#SZTBLs | 16K (16K,2060K] (2060K, 1050632K] (262658K, 537921544K]
~1026M ~513G
[+] click to leave a comment [+]
>> SEND COMMENT <<