Virtual Memory - aryanjoshi0823/5143-Operating-System GitHub Wiki
What Is Virtual Memory?
Virtual memory is a method computers use to manage storage space and ensure smooth system operations. It involves transferring data between random access memory (RAM) and other storage mediums, such as a hard drive or solid-state drive (SSD). Virtual memory ensures that the system operates efficiently by managing active and dormant processes.
How Does Virtual Memory Work?
Virtual memory operates through the collaboration of the computer's hardware and software components. Here's how it functions:
-
Swapping Data:
- Virtual memory transfers inactive processes from RAM to the hard disk, freeing up RAM for active tasks.
- When a process becomes active, it can be swapped back into RAM.
-
RAM Optimization:
- RAM is a finite resource stored on chips within the CPU.
- Virtual memory maximizes available RAM by temporarily relocating less urgent processes to disk storage.
-
Cost Efficiency:
- Adding more physical RAM can be expensive, but virtual memory offers a cost-effective alternative for managing memory-intensive tasks.
Types of virtual memory?
- Paging
- Segmentation
Example of Virtual Memory in Action
Consider a scenario where you're working on a laptop with limited RAM while running multiple applications:
- You open a web browser, a word processor, and an image editing application.
- The OS identifies which processes are actively in use and allocates RAM to them.
- If you minimize the image editing application, the system moves its data to virtual memory on the hard drive.
- This frees up RAM for more pressing tasks, such as opening a new program.
- When you return to the image editor, the system swaps the data back into RAM, ensuring a seamless user experience.