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 of x, 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
created 29.01.2024
EOF
[+] click to leave a comment [+]
the comment system on this blog works via email. The button
below will generate a mailto: link based on this page's url 
and invoke your email client - please edit the comment there!

[optional] even better, encrypt the email with my public key

- don't modify the subject field
- specify a nickname, otherwise your comment will be shown as   
  anonymous
- your email address will not be disclosed
- you agree that the comment is to be made public.
- to take down a comment, send the request via email.

>> SEND COMMENT <<




the greater struggle via serocell - media feed March 30, 2024

Screenshot: New Device via Detritus March 18, 2024

Idiot's guide to resource migration in Terraform via Archive Fever by Edwin Wenink March 15, 2024
Sometimes we need to migrate resources that are managed in Terraform. Terraform is a declarative language to manage cloud infrastructure from code, which allows you to reliably automate your deployments and put your infrastructure configuration under versi…

Generated by openring from webring