1. Home
Operating System

OS Tutorial: Learn Operating Systems Basics

Learn Operating System fundamentals: concepts, processes, memory management, and more. Start your journey to mastering OS with our comprehensive tutorial.

  • 47
  • 7 Hours
right-top-arrow

Tutorial Playlist

47 Lessons
25

Virtual Memory in Operating System

Updated on 19/07/2024439 Views

Multitasking is the new normal. We, humans, love it. We also want our gadgets to multitask. To keep our laptops running smoothly even when juggling multiple programs, operating systems use a clever technique called virtual memory. Virtual memory in OS is a ‘virtual’ reservoir of memory that enables you to expand your computer’s memory. 

This tutorial is your key to understanding the basics of virtual memory and much more. Shall we?

First, let me explain Virtual memory in OS in detail.

Virtual Memory in OS: How it Started

Virtual memory in OS started developing in the late 50s and by the late 70s it had taken a proper form. The commercial computers of the 70s had virtual memory. Intel introduced virtual memory in personal computers in 1985. With this, even personal computers could now use larger files and never face storage issues. 

What is Virtual Memory in Operating System?

Virtual memory in OS is an efficient way to help your laptop or computer allocate and manage space to run multiple programs quickly and smoothly. It expands the computer's available memory by using space on the hard drive. This allows the system to handle larger programs and data sets that can fit into RAM alone, ensuring smooth operation without running out of memory.

Easy right? 

Now, let’s understand virtual memory in computer architecture with example. 

You must have heard of photo editing software like Adobe Photoshop. When you start the program or the editor, virtual memory only brings the essentials to the RAM so that you can start editing. As you start using different features in the editor virtual memory swaps them with the inactive pages between the RAM and hard drive. 

Where is it Located?

As the name suggests virtual memory is not a physical location within a computer. But the data is stored in the HDD (Hard Drive) or SSD (Solid-State Drive), which have higher capacity than RAM. 

Why is it necessary?

Virtual memory is crucial for multitasking, and that’s a fact. The following reasons are some of the most important ones that you need to know:

  • Enhanced RAM affordability: Many of us can relate to it - RAM is expensive! It has alimited size. Virtual memory overcomes this hurdle and allows your computer to extend the usable memory. Ultimately, you can run massive and complex programs without burning through your pocket. 
  • Increased security of programs: Virtual memory in OS isolates programs. Meaning? Each program has its own virtual address space. This way they do not interfere with each other’s memory and hence no corruption of the data. This increases the overall system security.
  • Efficient multitasking: Virtual memory in OS helps manage multiple programs at the same time. It allows the actively used parts in RAM to stay while swapping less used parts to the hard drive. This creates space for other programs to run. 
  • Current programs are huge: These days the programs are huge compared to their predecessors. Video editing tools, gaming software, and complex OS needs more memory than a typical RAM has. So, virtual memory helps keep the cost down by providing features. 

Role of the Memory Management Unit (MMU) in Virtual Memory

Now that you have understood what virtual memory is in computer architecture, it’s time to understand it further. Virtual memory management is a core concept. Its key components are: 

  • Main Memory or RAM
  • Secondary Storage or (HDD/SSD) 

Then what is a Memory Management Unit or MMU?

It is like a translator between CPU and physical memory. It plays a crucial role in virtual memory management within the Operating System. The following terms that I am explaining will help you understand MMU in detail:

  • Page System: The big programs that virtual memory helps run smoothly are divided into smaller blocks called ‘pages’. While the entire program is located in the secondary storage. 
  • Selective loading: The OS is the smart one here. It doesn’t load all pages into RAM at once rather it prioritizes in-demand pages. This selective loading speeds the program execution as compared to loading the whole program into a limited RAM.
  • Logical to Physical Address Translation: Whenever the CPU requests a piece of data, the MMU fires up. It acts as a translator and translates the virtual address used by the program into a physical address within the RAM.
  • Page Faults and Swapping: When the required page is not present in the RAM, a page fault occurs and the OS being the smart one retrieves this page from the secondary storage and swaps it with a less-used page. Page replacement algorithms like FIFO (First in, First Out) or LRU (Last Recently Used), guide this swapping for maximum memory management.

Types of Virtual Memory in OS

Virtual memory has two types:-

Paging

Paging is the most common type of virtual memory in OS and one of the go-to processes for handle memory. It breaks down both the computer's memory and the programs running on it into smaller chunks called pages. 

This method lets us swap pages in and out independently, which helps us use memory more efficiently and avoid wasting space. It also helps translate virtual addresses to actual memory locations more quickly.

However, there's a downside. If the free space where we store these swapped-out pages isn't located close together on the hard drive, it can slow things down.

Segmentation

Segmentation offers greater flexibility compared to paging by dividing programs based on their functionalities rather than rigid block sizes. Each segment can have different access permissions, thereby enhancing security measures. Moreover, since segments vary in size, it reduces external fragmentation issues.

However, managing segments of variable sizes can be complex, and there's a risk of internal fragmentation within segments.

These days virtual memory in OS often has a mix of paging and segmentation. While paging is for core memory management, segmentation is used within processes. Factors like specific needs of the program and memory management help decide between paging and segmentation.

Advantages of Virtual Memory in OS

Let’s look at the advantages of the virtual memory concept in OS:  

  • Enabling execution of complex software and multitasking: Virtual memory in OS empowers systems to run large programs and handle multiple tasks simultaneously, regardless of the physical RAM size. This capability is crucial for modern computing environments where resource-intensive applications are common.
  • Efficient RAM utilization: By loading only the actively used parts of programs into RAM, virtual memory in OS optimizes memory usage, ensuring that space is available for other processes to run smoothly. This dynamic allocation mechanism helps prevent RAM from being underutilized or overloaded.
  • Isolation of program memory spaces: Each program operates within its own virtual memory space, shielded from interference by other programs. This isolation enhances system stability and security by preventing one program from accessing or corrupting the memory of another, fostering a safer computing environment.
  • Uniform memory model for programmers: Virtual memory in OS provides a consistent memory model across different programs and programming languages, simplifying software development and enhancing compatibility. This uniformity allows programmers to focus on writing code without worrying about the underlying memory management details, promoting efficient and standardized software development practices.

Challenges of Virtual Memory in OS 

Virtual memory in OS has its fair share of challenges. Let’s learn about them here:

  • Virtual memory in OS is slower than physical RAM: It has been observed that RAM is faster than virtual memory on the internal storage of the system irrespective of the configuration. And when the same is tested on external memory the shelf life of the external device gets impacted. 
  • Quantifiable delays due to the nature of the switch: As we have already seen, virtual memory works on a priority basis. So, it switches between active and inactive pages which present delays. On the other hand, RAM is already equipped with both hardware and software to manage multiple processes so the speed is not an issue here. The delay further worsens when the secondary storage chosen is slow. 
  • System instability issues: As virtual memory in OS uses ‘virtual’ space which is more than the hardware it sometimes slows the system or even crashes. 
  • Virtual memory can be a victim of false advertising: In the hopes of getting a good deal, manufacturers sometimes fool the end consumers by cleverly misguiding them. For example, a consumer is happy thinking they are buying a 12 GB RAM device but, the manufacturer provides 8 GB RAM and 4 GB virtual memory.  

To Conclude

I have covered nearly all basic topics related to virtual memory in OS in this tutorial. You have also seen why virtual memory management in OS is a fantastic way to overcome the limitations of physical RAM. Modern programs demand vast memory and how virtual memory helps achieve it. The types of virtual memory will come in handy while running general diagnostics on your system. While virtual memories have limitations like slower speed than RAM it still is the best way to achieve multitasking without breaking the bank. 

Mastering complex concepts like virtual memory in OS opens up exciting career paths. At upGrad you will find a structured way to deep dive into these concepts. 

Frequently Asked Questions

  1. What is virtual memory as used in computers?

It is a method to manage space which helps in running various systems simultaneously. 

  1. What is virtual memory size?

The size of Virtual memory in OS is the total memory capacity accessible by a computer, including both physical RAM and space on the hard drive or SSD, used for swapping data in and out of RAM.

  1. What is virtual RAM?

Virtual RAM is on smartphones, where the device’s internal storage is used as additional RAM.

  1. Where is virtual memory stored?

Virtual memory in OS is in the secondary memory storage like the HDD or SSD.

  1. What is virtual memory with an example?

Think of virtual memory as an expandable backpack for your laptop. It helps you carry more things (programs) than would fit in your pockets (RAM) alone. This way you can work on things wherever you go.

  1. Why is virtual memory used in OS?

Since RAM has physical limitations and OS has more memory, virtual memory is in OS.

  1. How to calculate virtual memory?

The size of virtual memory in OS varies within a specific range. Initially, it starts at 1.5 times the total system memory and can increase to a maximum of 3 times the initial size. For instance, if your computer has 16 GB of RAM, the initial virtual memory size would be 24 GB (16 x 1.5). Similarly, the maximum virtual memory size could reach up to 48 GB (16 x 3).

  1. Is virtual memory large?

Yes, virtual memory in OS is quite large.

  1. How to use virtual RAM?

For Android smartphones, you can find virtual RAM in the RAM management section. For OS like Win 10 or 11, it does not have user-accessible RAM as this is an automatic process within the OS. 

  1. Is virtual memory permanent or temporary?

The feature of virtual memory is permanent and the data it stores can be swapped when not needed. So, the data is temporary.

Rohan Vats

Rohan Vats

Passionate about building large scale web apps with delightful experiences. In pursuit of transforming engineers into leaders.

Get Free Career Counselling
form image
+91
*
By clicking, I accept theT&Cand
Privacy Policy
image
Join 10M+ Learners & Transform Your Career
Learn on a personalised AI-powered platform that offers best-in-class content, live sessions & mentorship from leading industry experts.
right-top-arrowleft-top-arrow

upGrad Learner Support

Talk to our experts. We’re available 24/7.

text

Indian Nationals

1800 210 2020

text

Foreign Nationals

+918045604032

Disclaimer

upGrad does not grant credit; credits are granted, accepted or transferred at the sole discretion of the relevant educational institution offering the diploma or degree. We advise you to enquire further regarding the suitability of this program for your academic, professional requirements and job prospects before enr...