What is virtual memory?

1.03K views

I have a vague idea of what is, but I really have no idea on how it works with physical memory and what it actually does. I also would like to know how virtual memory, physical memory, virtual address space are related and what is the job of MMU.

In: Engineering

3 Answers

Anonymous 0 Comments

Every program has a memory space which is however big the operating system decides it to be (nowadays at least 2^32).

This space limitation presents a problem when your program requires more memory above the approximately 4GB. I am leaving out some details for simplicity.

To address this you would just increase the size of the memory each process gets, which if you are on a 64bit machine is relatively trivial since you can represent addresses much larger than 2^32.

The problem becomes how you manage to cram so much memory for each program into your machine and having your operating system manage all of this. (We don’t have 2^64-1 byte memory sized machines…) This is where virtual memory spaces come in.

A virtual memory space is really the operating system promising the program it has a certain amount of linear memory space, which doesn’t actually physically exist. The virtual memory space allows the program to have a simple linear view of its memory while the underlying hardware and operating system do magic, which is done with pages.

Pages are typically 4KB chunks (there are larger ones on supercomputers) of memory which are allocated to a single program and moved between the hard drive and the random access memory. The MMU handles the translation from a virtual address space address to a physical address in the RAM or potentially triggers a load from a hard drive. (I am leaving out caching entirely).

Pages are really the bit of this that allow the flexibility required. It allows sharing of pages to save memory instead of loading common libraries many times. And the flexibility for you to “have” 2^64 bytes, but not actually needing to allocate these in physical memory.

Swapping memory which is the process of saving pages onto the hard drive is usually a bad idea. Performance is severely affected. It prevents out of memory errors, but it is not a viable way to actually use a computer.

You are viewing 1 out of 3 answers, click here to view all answers.