teach-ict.com logo

THE education site for computer science and ICT

7. Virtual memory

RAM has billions of memory locations but sometimes even that is not enough room for all the data the CPU needs. When RAM gets too full, the computer's operating system can help out by temporarily marking sections of secondary storage for the CPU to use as a kind of extra memory.

These sections are called virtual memory. The operating system creates a 'swap file' in this area which is used to hold data the CPU does not need immediately. Both Windows and Linux support virtual memory.

Virtual memory is volatile. If the computer is turned off, the operating system loses track of what was kept where in virtual memory. The data is lost.

But even though the CPU can directly access virtual memory, it is slow. When the CPU needs data held in virtual memory, it asks the operating system to first load it into RAM, which is quick to access.

 

swapping between ram and virtual memory

 

Less-used data is moved from RAM to virtual memory. Data that the CPU needs to use right now moves from virtual memory to RAM.

This is a slow process, so if virtual memory is in heavy use, the computer seems slower and you may hear the hard disk spinning. This excessive use of the hard disk as virtual memory is called disk thrashing. If the computer seems slow, it is worth checking how much RAM is in use with an utility such as Task Manager (in Windows). The diagram below shows a computer that is using 62% of its RAM.

task manager

 

If memory use is very high then you need more RAM to handle all the programs you are trying to run at the same time.

 

Challenge see if you can find out one extra fact on this topic that we haven't already told you

Click on this link: Virtual memory