Virtual Memory with Real-life analogy
This article will explain virtual memory concept in detail and with example.
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.
Table of contents
- Real-life analogy
- What Is Virtual Memory?
- How Does Virtual Memory Work?
- Example of virtual memory
- Advantages of Virtual memory
- Disadvantages of Virtual memory
- How to Configure Virtual Memory in Windows
- Conclusion
You can also explore these articles:
Best-suited Operating Systems courses for you
Learn Operating Systems with these high-rated online courses
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:
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
Advantages of Virtual memory
- 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.
- It has also made it possible to increase a computer’s memory without increasing the computer’s size.
- Virtual memory also enables your computer to run more programs simultaneously.
- Virtual memory can help protect your computer’s physical memory from overloading.
Disadvantages of Virtual memory
- If the virtual memory system fails, the entire computer system may fail.
- The virtual memory system is not fault-tolerant.
- Virtual memory can slow down your computer.
- 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!!!
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