I'm reading through an example of page tables and just found this:
Consider a system with a 32-bit logical address space. If the page size in such a system is 4 KB (2^12), then a page table may consist of up to 1 million entries (2^32/2^12). Assuming that each entry consists of 4 bytes, each process may need up to 4 MB of physical address space for the page table alone.
I don't really understand what this 4MB result represents. Does it represent the space the actual page table takes up?
Number of frames = 2^26/2^12 = 2^14 frames. ∴ Page Table Size = 2^20×14-bits ≈ 2^20×16-bits ≈ 2^20×2B = 2MB.
Since we have a virtual address space of 2^32 and each page size is 2^12, we can store (2^32/2^12) = 2^20 pages. Since each entry into this page table has an address of size 4 bytes, then we have 2^20*4 = 4MB. So the page table takes up 4MB in memory.
My explanation uses elementary building blocks that helped me to understand. Note I am leveraging @Deepak Goyal's answer above since he provided clarity:
We were given a logical 32-bit address space (i.e. We have a 32 bit computer)
Consider a system with a 32-bit logical address space
We were also told that
each page size is 4 KB
As Depaak said, we calculate the number of pages in the page table with this formula:
Num_Pages_in_PgTable = Total_Possible_Logical_Address_Entries / page size Num_Pages_in_PgTable = 2^32 / 2^12 Num_Pages_in_PgTable = 2^20 (i.e. 1 million)
The authors go on to give the case where each entry in the page table takes 4 bytes. That means that the total size of the page table in physical memory will be 4MB:
Memory_Required_Per_Page = Size_of_Page_Entry_in_bytes x Num_Pages_in_PgTable Memory_Required_Per_Page = 4 x 2^20 Memory_Required_Per_Page = 4 MB (Megabytes)
So yes, each process would require at least 4MB of memory to run, in increments of 4MB.
Now if a professor wanted to make the question a bit more challenging than the explanation from the book, they might ask about a 64-bit computer. Let's say they want memory in bits. To solve the question, we'd follow the same process, only being sure to convert MB to Mbits.
Let's step through this example.
- Logical address space: 64-bit
- Page Size: 4KB
- Entry_Size_Per_Page: 4 bytes
Recall: A 64-bit entry can point to one of 2^64 physical page frames - Since Page size is 4 KB, then we still have 2^12 byte page sizes
- 1 KB (kilobyte) = 1 x 1024 bytes = 2^10 bytes
- Size of each page = 4 x 1024 bytes = 2^2 x 2^10 bytes = 2^12 bytes
`Num_Pages_in_PgTable = Total_Possible_Logical_Address_Entries / page size Num_Pages_in_PgTable = 2^64 / 2^12 Num_Pages_in_PgTable = 2^52 Num_Pages_in_PgTable = 2^2 x 2^50 Num_Pages_in_PgTable = 4 x 2^50 `
Memory_Required_Per_Page = Size_of_Page_Entry_in_bytes x Num_Pages_in_PgTable Memory_Required_Per_Page = 4 bytes x 8 bits/byte x 2^52 Memory_Required_Per_Page = 32 bits x 2^2 x 2^50 Memory_Required_Per_Page = 32 bits x 4 x 2^50 Memory_Required_Per_Page = 128 Petabits
[2]: Operating System Concepts (9th Ed) - Gagne, Silberschatz, and Galvin
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With