3.3 Data storage

Show All Section Notes

Virtual Memory

Virtual Memory is a feature of an operating system that allows a computer to compensate for shortages of physical RAM by temporarily transferring data from random access memory (RAM) to disk storage.

The Reason for Virtual Memory

When you try to run more applications than your physical RAM can hold, the computer would normally crash or refuse to open new programs. Virtual Memory prevents this by using a section of the Secondary Storage (HDD/SSD) to act as an "overflow" area for the RAM.

Pages

Memory is divided into fixed-size units called Pages. Programs are broken into these pages so they can be moved between RAM and storage easily.

Swapping

The process of moving a "page" of data from RAM to the Hard Disk (and vice versa) to make room for the data currently needed by the CPU.

Disk Thrashing: This occurs when the computer spends more time "swapping" pages between the RAM and Disk than actually executing instructions. This causes the system to become extremely slow or unresponsive.

The Desk Analogy

Imagine your Physical RAM is your Desk and your Secondary Storage is a Filing Cabinet.

  • You can only work on papers that are currently on your desk (RAM).
  • If your desk gets full but you need to open a new folder, you take a folder you aren't using right now and put it in the filing cabinet (Virtual Memory).
  • When you need that folder again, you swap it with something currently on your desk.
  • Thrashing is like spending your entire workday running back and forth between the desk and the cabinet without actually reading any papers!

Advantages of Virtual Memory

  • Multitasking: Allows you to run more applications than the physical RAM capacity would normally permit.
  • No "Out of Memory" Errors: Prevents programs from crashing when RAM is full.
  • Cost-Effective: Using a portion of a hard drive as "extra memory" is much cheaper than buying and installing more physical RAM sticks.
  • Efficient Resource Use: Only the parts of a program currently being used need to be in the expensive, fast RAM.