Virtual Memory with Real-life analogy

Virtual Memory with Real-life analogy

5 mins read1.8K Views Comment
Vikram
Vikram Singh
Assistant Manager - Content
Updated on Mar 29, 2024 17:38 IST

This article will explain virtual memory concept in detail and with example.

2022_07_Picture2.jpg

Your computer wouldn’t be able to do much without virtual memory. This little-known feature of your operating system makes it possible for you to open multiple programs simultaneously, surf the web, and write a paper all at the same time. In this post, we’ll take a look at Virtual Memory with a Real-life analogy and also how it works.

Difference Between RAM And ROM
Difference Between RAM And ROM
RAM and ROM are two commonly used terms in computers. The primary distinction between RAM and ROM is that RAM is random access memory, whereas ROM is read-only memory. RAM...read more
CPU vs GPU? What’s the Difference?
CPU vs GPU? What’s the Difference?
Are you wondering about CPU vs GPU? Today, in this article, we will discuss the differences between CPU and GPU. CPU and GPU are two commonly used terms in the...read more
Difference Between Primary Memory and Secondary Memory
Difference Between Primary Memory and Secondary Memory
Computer memory is simply the computer’s brain where data and information are stored for easy retrieval. Memory is the computer’s storage space that temporarily or permanently stores data or programs....read more

Real-life analogy

Suppose you have a furniture shop that is not big enough to accommodate all the furniture, then you will keep it somewhere else, like in a warehouse. And you will keep that furniture in your shop which will be in demand(not all). And if you don’t require some particular furniture, you will keep that in the warehouse. And according to trend or demand, you will keep exchanging the furniture items from the warehouse. The same concept is for virtual memory.

You can also explore these articles:

Memory Hierarchy in Operating System
Memory Hierarchy in Operating System
Memory hierarchy helps in organizing the memory in a way that it can minimize the access time. It is based on a program behavior that is known as locality of...read more
Threads and Multi-Threading: Operating system
Threads and Multi-Threading: Operating system
In any software system, there are always a variety of threads at work. These threads can be classified into two general types: user threads and kernel threads. User threads are...read more
Working of Demand Paging in Operating System
Working of Demand Paging in Operating System
This article explain a very important topic of operating system-Demand paging with real-life analogy

What Is Virtual Memory?

Virtual memory is a way for your computer to use hard drive space to simulate extra RAM.

Virtual memory is a process that uses part of your computer’s hard drive to act as if it were additional memory. When your computer starts to run low on actual memory, the system will move inactive data from physical memory to virtual memory, freeing up space so active programs can run properly.

How Does Virtual Memory Work?

Now that you have a basic understanding of virtual memory let’s look at how it works.

A computer system stores data on its hard drive, including the operating system’s virtual memory. When a program requests information from the operating system, it sends instructions to the computer’s processor telling it where to find that information. The processor then retrieves that data from one of these places and displays it on-screen. This is how programs like Microsoft Word or Excel access their text files or spreadsheet cells—by asking the operating system to “push” those files down into virtual memory so they can be accessed more quickly than if they were stored on disk entirely.

When you use an application, the program’s data is stored in RAM at a physical address. The memory management unit (MMU) maps the address to RAM and translates the address automatically. For example, an MMU can map a logical address space to a corresponding physical address. At some point, if something more urgent requires RAM space, you can swap out the data from RAM to virtual memory. Your computer’s memory manager is responsible for tracking the movement between physical and virtual memory. The computer’s MMU uses a context switch when that data is needed to continue running. 

When copying virtual memory to physical memory, the operating system shares memory with a fixed number of addresses in either the paging file or the paging file. All pages are stored on a disk, and when a page is needed, the operating system copies that page from the disk to the main memory and translates the virtual address to the actual address.

Example of virtual memory

Suppose the CPU wants to access process P1, divided into ten pages. So following the idea of virtual memory, only P1, P3, P5, P6, and P8 Pages are selected to be loaded in the main memory. For that have to consult the page table. First CPU will check whether that page has a valid(v) or invalid bit(I). Valid bit indicates that the page is in main memory and invalid bit indicates that the page is not in main memory and has to load from secondary memory. Like from the page table, we can see that page 1 is at frame 1, page 3 is at frame 2, page 5 is in frame 3, and so on. If the page is not in the main memory, then those pages not in use are swapped out, and a new required page is swapped in. In short virtual memory includes the concept of demand paging and swapping.

Also explore: What is Operating Systems (OS) – Types, Functions, and Examples

Also explore: Operating system interview questions

Memory Management Techniques in Operating System
Memory Management Techniques in Operating System
Memory management is very important aspect of operating system performance.In this article we have covered different memory management techniques like paging,swapping,compaction and segmentation. This article covers different topics related to...read more
Types of Operating Systems
Types of Operating Systems
There are different types of operating system.This article includes imporant types of operating systems with diagrams. This article covered types of operating systems multiprogramming, multiprocessor, distributed, batch, time-sharing, and multitasking...read more
Process Scheduling: Operating System
Process Scheduling: Operating System
Have you ever wondered how your computer juggles multiple tasks simultaneously? To know that, you must read this blog on process scheduling in the operating system! This article includes...read more

Advantages of Virtual memory

  1. It has also enabled a more comprehensive range of applications since the program code, and data structures are not copied onto the diskette or hard drive. This increases the overall speed of the computer system. 
  2. It has also made it possible to increase a computer’s memory without increasing the computer’s size.
  3. Virtual memory also enables your computer to run more programs simultaneously.
  4. Virtual memory can help protect your computer’s physical memory from overloading. 

Disadvantages of Virtual memory

  1. If the virtual memory system fails, the entire computer system may fail.
  2. The virtual memory system is not fault-tolerant.
  3. Virtual memory can slow down your computer.
  4.  Can shorten the lifespan of your hard drive.

So, is virtual memory a good thing or a bad thing? It depends on your specific situation and how you use your computer. If you have a lot of RAM and don’t often run out of physical memory, you don’t need to worry about using virtual memory. But if you’re regularly running low on RAM or experience slowdown issues, then virtual memory might be worth turning off.

How to Configure Virtual Memory in Windows

Now that you understand how virtual memory works, it’s time to learn how to configure it on your computer. Here’s how:

1. Open the Control Panel and select System and Security > System.

2. Click on Advanced system settings on the left-hand side of the window.

3. In the Advanced tab, click on Settings under Performance.

4. Select the Advanced tab and click on Change under Virtual Memory.

5. Uncheck the box next to Automatically manage paging file size for all drives and select your Windows drive (usually C:).

6. Change the Initial size and Maximum size to the recommended values by Windows (1.5 times your total system memory for Initial size and 3 times your total system memory for Maximum size).

7. Click OK to save your changes.

Conclusion

Virtual memory is a crucial component of today’s operating systems. By combining physical and virtual memory, your computer can seem to have much more RAM than it does. This can be a huge help when you’re running multiple applications simultaneously.

In this post, we’ve explained Virtual Memory with Real-life analogy and also how it works. If you liked this blog, hit the like button and share this article with as many people as possible. Stay tuned for more interesting blogs on the operating system

Happy Learning!!!

About the Author
author-image
Vikram Singh
Assistant Manager - Content

Vikram has a Postgraduate degree in Applied Mathematics, with a keen interest in Data Science and Machine Learning. He has experience of 2+ years in content creation in Mathematics, Statistics, Data Science, and Mac... Read Full Bio