0
votes

Consider a 32-bit virtual and physical address space with physical page size of 4KB. Assume that a process has just been created and its program copied into memory. Size of program is 1 KB. How much memory will be required to store the page tables of this process?

I did this : .

PTE size for 32bit physical address = 32 bits = 4 bytes. no of PTEs in single level page table = virtual pages= virtual address space / page = 2^32 / 2^ = 2^20

so no of pages = 2^20.

But in the solution they have also written as:

"#Pages in single level page table = #PTEs x PTE size / page size = 2^20 x 4 bytes / 2^12 bytes = 2^10. " as far as I understand page table is an array of page table entries ,one per virtual page . So no of page table entries should be equal to no of Pages. so then why #Pages is equal to 2^10??

Another thing what is "with physical page size of 4KB." ?? Pages are virtual address so does that mean a page occupy 4KB of space on physical memory??

Any sort of help will be appreciated.

1
I remain puzzled why students are subjected to exercises like this. This problem is totally FUed. The program size is just 1KB????? If we assume that this one KB has been crammed into one page (not a valid assumption), that means only one page table entry is needed for the process. The number of page table entries is a function of the process size; not the virtual address size. Thus, unless the page table entries are huge (the page table entry size being another unspecified value), you only need one page to store the one page table entries needed for a process running a 1KB program.user3344003

1 Answers

0
votes

For a single level of page tables; the virtual address space is 4 GiB and a page is 4 KiB so you will need "4 GiB/4 KiB = 1048576 pages = 1048576 page table entries". This is the answer you came up with (2^20 page table entries).

If there are 1048576 page table entries and you have no idea how large a page table entry is, then the total amount of memory needed for all page table entries will be "1048576 * unknown = unknowable".

However, with a 32-bit physical address space size and 4 KiB page size we know that 12 bits of an address will be used for "offset within page" and the remaining 20 bits of an address will be used for "page number"; therefore we know that a page table entry must be at least 20 bits, so we know that the total amount of memory needed for all page table entries will be at least "1048576 * 20 bits = 20971520 bits = 2560 KiB".

If we make random potentially false assumptions (based on educated guesses) and decide that maybe a page table entry is 4 bytes, we could say that the total amount of memory needed for all page table entries will probably be "1048576 * 4 bytes = 4 MiB".

If the total amount of memory needed for all page table entries is 4 MiB and a physical page is 4 KiB; then you will need "4 MiB / 4 KiB = 1024 pages" to store all the page table entries. This is the answer they came up with (2^10 pages).

Another thing what is "with physical page size of 4KB." ?? Pages are virtual address so does that mean a page occupy 4KB of space on physical memory??

Pages aren't virtual addresses; and there are both virtual pages and physical pages.

The basic idea is to split a virtual address into two parts (with masking/AND and shifting) so that "(virtual_page_number << K) + offset_within_page = virtual_address", then use "virtual_page_number" (and page tables) to find "physical_page_number", then do "physical_address = (physical_page_number << K) + offset_within_page".

For this to work, the size of a virtual page must be the same as the size of a physical page; so the words "page size" are used to refer to both the virtual page size and the physical page size.