# If the virtual address space can be larger than the physical address space, how are the address mappings stored in memory?

Let's say we are working with a system that has 40 physical address bits. The total physical address space (assuming byte-addressable memory) is $2^{40}$ bytes, or 1 TiB. And if virtual addresses are 48 bits in length, that means there are more addresses available to virtual memory than there are locations in physical memory.

This makes sense to me, because the "excess" addresses could refer to hard disk locations as well. However, what I don't understand is how the translation between virtual and physical addresses occurs. I assume there is a mapping stored somewhere which links VAS locations to the physical locations. If there are more virtual address locations than physical locations, how can all of these mappings possibly be stored in memory? At minimum you would need 48 bits to store each virtual address, and then another 40 to store the physical location it maps to. So obviously you cannot just store a 1:1 mapping of each virtual address to its physical counterpart, as mapping every location would take more memory than physical memory itself.

What exactly am I missing here?

• You can't do that even with a small amount of memory and address space. If you had 16-bit physical addresses and 16-bit virtual addresses you still wouldn't be able to store all of the 1:1 mappings! Dec 4 '17 at 2:00
• The problem is more complex even than you are thinking. Computers rarely have TB of memory, so physical memory is WAY less than virtual address space. Worse again: Each process has it's entirely separate virtual address space! Dec 4 '17 at 5:44
• In addition to hard disk locations you just have bits/space to spare to waste. For example you can have large region below stack unmapped to prevent undetected overflows. You can randomize what you load where preventing another class of attacks. Want to denote by a single bit if address belongs to kernel or user - go ahead even though you are wasting half of space. While most textbooks concentrate on paging out aspect of virtual memory there is a lot more to it. Dec 4 '17 at 8:18
• (Also note that addresses may alias, which is sometimes useful, so VA A and address B refer to same PA P even though A != B.) Dec 4 '17 at 8:18