What Is Virtual Memory, And How Does It Operate In An Operating System


Share This Post

As people, we are always working on different things simultaneously. When we work on a computer, it's the same way. We open several programs or internet tabs at the same time. But RAM, the part of memory that saves currently running apps, has a limited amount of space.

Since RAM runs out, there is a limit to how many apps can be loaded simultaneously. This is where the idea of virtual memory comes in in computer design. It is a function of any operating system in which a small amount of secondary memory is used as extra RAM for a short time.

This is how virtual memory lets you compensate for the lack of real RAM.

Given how big and complicated apps are these days, virtual memory is very important. Let's talk about virtual memory and better understand what this means.

What is Virtual Memory in Operating Systems (OS)?

Virtual Memory, also called "virtual RAM," is a way for an operating system (OS) to handle memory by briefly using a part of secondary or variable memory as main memory. It does this by moving data from RAM to a hard or solid-state drive that hasn't been used lately. When the information is needed, a copy is returned to the original RAM.

This happens when there isn't enough RAM and multiple processes run simultaneously. Virtual storage lets users add more computing tasks than the main memory. This is helpful for big programs. For multitasking to work, the operating system must also be able to put different parts of different tasks into the main memory.

But your computer system may slow down if you have to share info a lot. Demand segmentation and demand paging are usually used to set up virtual memory. You need to know about demand paging to understand how virtual memory works.

Basic Terminologies

A program is a set of rules that tells a machine how to do something.

Process: In an OS, a process is any action that runs program code in a certain order.

Thread: The path that a program takes as it runs. Multithreading is a way for an operating system to handle multiple requests from the same person in the best way.

Memory in an operating system is broken up into "pages". These pages are where programs are kept.

What is Demand Paging?

Demand Paging is a way to handle virtual memory that stores a task's pages in a second memory. Before the need comes up, it can be hard to know which pages should be in the main memory and what ones should be in the virtual memory.

So, no page is put ahead of time into the main memory. When a page is first called up in the main memory, it will already be in the secondary memory. Various methods for replacing pages are used to determine which pages need to be changed.

So, the page might not be in the main memory when you need it later. Currently, only the pages needed by a computing process are loaded. Other pages are changed on demand or when a page fault happens, which is not what you want. Virtual memory is often used with this method.

How Virtual Memory Works in Operating System

Now that you understand what virtual memory is and how it works in operating systems let's look at how it works. When there isn't enough room in the main memory for the programs that need to be loaded during a process, the operating system (OS) generates space in the form of pages to store these programs.

It does this by moving the parts of RAM that are used or referred to the least into a part of secondary memory. So, this info is what makes up your virtual memory. When a piece or page is needed, it is put into the main memory.

The operating system divides the memory into swap files and page files based on the many addresses in the memory. Its memory management unit changes the virtual address into the real address as the data is copied. The memory manager maintains track of all the changes between real and virtual memory.

This lets tasks run even if they can't all fit in the memory. For example, say X MB of real memory is available on RAM, but the OS needs Y MB more memory to store working programs. The operating system will then set up Y MB of virtual storage and tell it where to go.

On a hard disc or SSD, a file of size Y MB will store extra memory. The virtual memory's size depends on how much space is on the hard drive. If the computer architecture's virtual memory starts to run low, you may have to make the page file bigger or buy more RAM.

How Does an Operating System Handle Virtual Memory?

As part of virtual memory, disc storage is used as extra RAM. The usual choices determine how much room on the hard drive can be used by the OS for tasks and programs as virtual memory.

But let's say you have a few hard drives or programs that need fast response times.

In that case, you can directly control virtual memory in OS by changing how much room is allocated to the disc. Those who want to know how to increase virtual memory in manual restart must set the highest and minimum amounts of drive space. It must be in an ideal range to ensure your machine has enough virtual memory.

Check the RAM size on your machine to find out the best range for virtual RAM. How much virtual memory you have depends on how much RAM your operating system needs. In Windows OS, for example, it is between 1.5 and 3 times the size of the RAM.

But if the OS's virtual memory management doesn't meet your needs, you should add RAM. Let's use the Windows operating system as an example to understand better how to add more virtual memory. Here's what you need to do to create virtual memory in OS:

Go to Start, then Settings.

Type performance in the search box.

Choose Change how Windows looks and how it works. There will be a chance.

Click on the Advanced tab.

Click on Change in the part called "Virtual memory".

Uncheck the "Automatically handle paging file size for all drives" box in the window.

Click on Size Custom.

Fill in the numbers in the boxes for "Initial Size" and "Maximum Size".

Click OK to save the new range of virtual memory.

Benefits of Virtual Memory in OS

Virtual memory in a computer is useful in several ways. Virtual memory management methods can also be used to make a virtual machine run better when it needs more resources than it has. Here, we talk about some of the best things about virtual RAM:

Low-cost extra space for memory

High security because data is kept separate and encrypted.

Better use of the CPU by running more things at once.

It gets easier to run multiple programs.

Can run big programs and open more apps at once.

The Drawbacks of OS Virtual Memory

There are also some bad things about using virtual RAM. To understand how well virtual RAM works, you need to know them.

For address translation, it needs more hardware.

Make the system less stable.

Reduces the amount of storage space on the hard drive. Size is restricted by the amount of extra memory that is available.

Performance is getting worse because moving between apps takes longer.



Now that you understand OS virtual memory, you can figure out the best way to do more than one thing simultaneously. After weighing the benefits and drawbacks of your machine, you can decide if you want to buy more RAM or directly set the virtual memory range.