1. ## virtual memory system

Hello i am studying for my operating system programming exam, we been provided with a sample exam but no answers have been given.
i answered this question but not sure if i am right, it would be much appreciated if you could check if i am right and if i am wrong could you explain how to get the right answer.

Consider a virtual memory system with the following parameters:
• 4-kbyte virtual page size
• 32-bit page table entry (PTE)
• 2-gbyte physical memory

(a) draw a diagram of the 32-bit address showing the length and placement of all bit fields i.e. the offset in the page(O), and the page number(P).

page number | offset
PPPPPPPPPPPPPPPPPPPP|OOOOOOOOOOOO

(b) how many virtual pages are available in this system?

2^20 = 1 048 576 virtual pages

(c) how many physical frames are available in this system?

2^12 = 4096*2028 = 8 306 688 physical frames

(d) name TWO fields of the page table entry.

- page frame number
- valid bit(set if page is in memory)
- other flags: modified(dirty), referenced, protection bits

any help would be appreciated

2. Take this with a grain of salt, it's been a lot of years since I've really had to deal with this kind of stuff

a, b and d all look correct

c makes me suspicious, mainly because of the 2028, which is not a power of two. In fact, it's somewhat "awkward" expressed in binary: 11111101100.

You have 32 bits available for the PTE. The virtual page number is the index into the table, which is irrespective of the 32 bits for each PTE. That means you have 32 bits for status bits (e.g. valid, dirty, protection, etc).

If you are dealing with only pages in RAM (i.e. nothing swapped to disk), then the answer is easy. You simply divide the physical memory size by page size:
2GB / 4KB = 2^31 / 2^12 = 2^19 = 524 288 frames
That means you need 19 bits of the PTE for physical page size, leaving 32 - 19 = 13 bits for status, etc. That's more than enough

If you have to consider swapping to disk, then it's a bit trickier. Since disk is typically much, much larger than RAM, you could probably easily fill all 32 bits of the PTE with physical (RAM or disk) frame addresses. So then the question is: how many bits of the PTE are used for status info? Remove those from the total, and that is how many bits you have left to address physical pages (frames). So Let's say you have 5 status bits total: valid, dirty and 3 for protection (read, write, execute). That gives
32 - 5 = 27 bits; 2^27 = 134 217 728 frames

Hope that makes sense and clears up any issues. Feel free to post back if you have more questions, and maybe somebody else with better knowledge will come along to lend a hand.

3. Thank you so much, your help was really appreciated.

4. Originally Posted by invinceable

Consider a virtual memory system with the following parameters:
• 4-kbyte virtual page size
• 32-bit page table entry (PTE)
• 2-gbyte physical memory

(a) draw a diagram of the 32-bit address showing the length and placement of all bit fields i.e. the offset in the page(O), and the page number(P).