# Question on Virtual memory and Physical memory

This is the question where I'm stuck: With a 32-bit virtual address, 4 KB pages(12 offset bits), and 4 bytes per page table entry, we can compute the total page table size:

Number of page table entries = 2^(32-12) = 2^20 Size of page table is 2^20 * 2 = 4MB

I understand this, but what I don't get is that each page table entry is of 4 bytes which is 32 bits. That would make the Physical address= 32+ 12 (offset bits)= 44 bits. Wouldn't it?

I've read and understood the point that Virtual Memory size should be bigger than Physical address because that's when the Virtual memory can hold more memory value (Main memory+Disk, though virtually) than the physical address. Am I right?

Also, I've found a block diagram showing all virtual addresses pointing to physical through a page table, and from there they are mapped to main memory and disk address; mapped to disk if valid bit is 0 or else mapped to main memory.

Let me know if I'm wrong anywhere.

• Answers please! Have been desperate. Commented Aug 27, 2016 at 9:11

The page entry contains other things than the base of the physical page. Typically:

• a present or absent bit (to handle the case where the page is not present in the memory: is on disk or just does not exist)

• access right: may the process read, write, execute the page

• some kind of use count (to help the OS makes its choice when there is a need page out)

and obviously some bits may be unused or reserved for future usage.

Note that, although in 64-bit system we are in a phase where the virtual address space is bigger than the physical address space, historically on architectures which lived long enough that tends to be followed by a phase where the physical address space is bigger than the virtual one. The additional memory may be visible only by the OS (which will put other processes there), or even made available to user processes with some kind of bank switching (see extended and expanded memory or more recently PAE in x86 world, some other architectures have had similar things)

Each page table entry is 4 bytes, i.e., 32 bits, but not all of those bits may be used. For instance, 20 bits might be used to hold a physical frame (top 20 bits of physical address) and the other 12 bits might be unused or used for other things (storing permissions, reserved for future use, etc.). If only 20 bits are used, then physical addresses would be 20+12 = 32 bits.

If only 20 bits are used for storing the physical address, why would we take up an entire 4 bytes for the page table entry? Well, it leaves us some bits for other things. And, more importantly, it is useful for a page table entry to be an integer multiple of the word size (4 bytes) long; that way we don't have to deal with unaligned memory accesses.