Virtual Memory in OS: What is, Demand Paging, Advantages (2024)

By : Lawrence Williams

Updated

What is Virtual Memory?

Virtual Memory is a storage mechanism which offers user an illusion of having a very big main memory. It is done by treating a part of secondary memory as the main memory. In Virtual memory, the user can store processes with a bigger size than the available main memory.

Therefore, instead of loading one long process in the main memory, the OS loads the various parts of more than one process in the main memory. Virtual memory is mostly implemented with demand paging and demand segmentation.

Why Need Virtual Memory?

Here, are reasons for using virtual memory:

  • Whenever your computer doesn’t have space in the physical memory it writes what it needs to remember to the hard disk in a swap file as virtual memory.
  • If a computer running Windows needs more memory/RAM, then installed in the system, it uses a small portion of the hard drive for this purpose.

How Virtual Memory Works?

In the modern world, virtual memory has become quite common these days. It is used whenever some pages require to be loaded in the main memory for the execution, and the memory is not available for those many pages.

So, in that case, instead of preventing pages from entering in the main memory, the OS searches for the RAM space that are minimum used in the recent times or that are not referenced into the secondary memory to make the space for the new pages in the main memory.

Let’s understand virtual memory management with the help of one example.

For example

Let’s assume that an OS requires 300 MB of memory to store all the running programs. However, there’s currently only 50 MB of available physical memory stored on the RAM.

  • The OS will then set up 250 MB of virtual memory and use a program called the Virtual Memory Manager(VMM) to manage that 250 MB.
  • So, in this case, the VMM will create a file on the hard disk that is 250 MB in size to store extra memory that is required.
  • The OS will now proceed to address memory as it considers 300 MB of real memory stored in the RAM, even if only 50 MB space is available.
  • It is the job of the VMM to manage 300 MB memory even if just 50 MB of real memory space is available.

What is Demand Paging?

A demand paging mechanism is very much similar to a paging system with swapping where processes stored in the secondary memory and pages are loaded only on demand, not in advance.

So, when a context switch occurs, the OS never copy any of the old program’s pages from the disk or any of the new program’s pages into the main memory. Instead, it will start executing the new program after loading the first page and fetches the program’s pages, which are referenced.

During the program execution, if the program references a page that may not be available in the main memory because it was swapped, then the processor considers it as an invalid memory reference. That’s because the page fault and transfers send control back from the program to the OS, which demands to store page back into the memory.

Types of Page Replacement Methods

Here, are some important Page replacement methods

  • FIFO
  • Optimal Algorithm
  • LRU Page Replacement

FIFO Page Replacement

FIFO (First-in-first-out) is a simple implementation method. In this method, memory selects the page for a replacement that has been in the virtual address of the memory for the longest time.

Features

  • Whenever a new page loaded, the page recently comes in the memory is removed. So, it is easy to decide which page requires to be removed as its identification number is always at the FIFO stack.
  • The oldest page in the main memory is one that should be selected for replacement first.

Optimal Algorithm

The optimal page replacement method selects that page for a replacement for which the time to the next reference is the longest.

Features

  • Optimal algorithm results in the fewest number of page faults. This algorithm is difficult to implement.
  • An optimal page-replacement algorithm method has the lowest page-fault rate of all algorithms. This algorithm exists and which should be called MIN or OPT.
  • Replace the page which unlike to use for a longer period of time. It only uses the time when a page needs to be used.

LRU Page Replacement

The full form of LRU is the Least Recently Used page. This method helps OS to find page usage over a short period of time. This algorithm should be implemented by associating a counter with an even- page.

How does it work?

  • Page, which has not been used for the longest time in the main memory, is the one that will be selected for replacement.
  • Easy to implement, keep a list, replace pages by looking back into time.

Features

  • The LRU replacement method has the highest count. This counter is also called aging registers, which specify their age and how much their associated pages should also be referenced.
  • The page which hasn’t been used for the longest time in the main memory is the one that should be selected for replacement.
  • It also keeps a list and replaces pages by looking back into time.

Fault rate

Fault rate is a frequency with which a designed system or component fails. It is expressed in failures per unit of time. It is denoted by the Greek letter ? (lambda).

Advantages of Virtual Memory

Here, are pros/benefits of using Virtual Memory:

  • Virtual memory helps to gain speed when only a particular segment of the program is required for the execution of the program.
  • It is very helpful in implementing a multiprogramming environment.
  • It allows you to run more applications at once.
  • It helps you to fit many large programs into smaller programs.
  • Common data or code may be shared between memory.
  • Process may become even larger than all of the physical memory.
  • Data / code should be read from disk whenever required.
  • The code can be placed anywhere in physical memory without requiring relocation.
  • More processes should be maintained in the main memory, which increases the effective use of CPU.
  • Each page is stored on a disk until it is required after that, it will be removed.
  • It allows more applications to be run at the same time.
  • There is no specific limit on the degree of multiprogramming.
  • Large programs should be written, as virtual address space available is more compared to physical memory.

Disadvantages of Virtual Memory

Here, are drawbacks/cons of using virtual memory:

  • Applications may run slower if the system is using virtual memory.
  • Likely takes more time to switch between applications.
  • Offers lesser hard drive space for your use.
  • It reduces system stability.
  • It allows larger applications to run in systems that don’t offer enough physical RAM alone to run them.
  • It doesn’t offer the same performance as RAM.
  • It negatively affects the overall performance of a system.
  • Occupy the storage space, which may be used otherwise for long term data storage.

Summary

  • Virtual Memory is a storage mechanism which offers user an illusion of having a very big main memory.
  • Virtual memory is needed whenever your computer doesn’t have space in the physical memory
  • A demand paging mechanism is very much similar to a paging system with swapping where processes stored in the secondary memory and pages are loaded only on demand, not in advance.
  • Important Page replacement methods are 1) FIFO 2) Optimal Algorithm 3) LRU Page Replacement.
  • In FIFO (First-in-first-out) method, memory selects the page for a replacement that has been in the virtual address of the memory for the longest time.
  • The optimal page replacement method selects that page for a replacement for which the time to the next reference is the longest.
  • LRU method helps OS to find page usage over a short period of time.
  • Virtual memory helps to gain speed when only a particular segment of the program is required for the execution of the program.
  • Applications may run slower if the system is using virtual memory.

You Might Like:

  • Inter Process Communication (IPC) in OS
  • Round Robin Scheduling Algorithm with Example
  • Process Synchronization: Critical Section Problem in OS
  • Process Scheduling in OS: Long, Medium, Short Term Scheduler
  • Priority Scheduling Algorithm: Preemptive, Non-Preemptive EXAMPLE
  • Memory Management in OS: Contiguous, Swapping, Fragmentation
  • Shortest Job First (SJF): Preemptive, Non-Preemptive Example
  • SSD vs HDD: What is the Difference Between SSD and HDD
Virtual Memory in OS: What is, Demand Paging, Advantages (2024)

FAQs

Virtual Memory in OS: What is, Demand Paging, Advantages? ›

Its main advantage is reducing the physical memory required, enabling more applications to run at once and allowing larger programs to run. However, demand paging has some drawbacks. The page fault

page fault
A page fault occurs when a program attempts to access data or code that is in its address space, but is not currently located in the system RAM. So when page fault occurs then following sequence of events happens : The computer hardware traps to the kernel and program counter (PC) is saved on the stack.
https://www.geeksforgeeks.org › page-fault-handling-in-opera...
mechanism can delay program execution because the operating system must retrieve pages from secondary storage.

What is demand paging and its advantages? ›

Advantages. Demand paging, as opposed to loading all pages immediately: Only loads pages that are demanded by the executing process. As there is more space in main memory, more processes can be loaded, reducing the context switching time, which utilizes large amounts of resources.

What is virtual memory and demand paging? ›

Virtual memory is how we stuff large programs into small physical memories. We perform this magic by using demand paging, to bring in pages only when they are needed. But to bring pages into memory means kicking other pages out, so we need to worry about paging algorithms.

What is virtual memory and its advantages? ›

Last Updated: March 31, 2023. Virtual memory is defined as a memory management method where computers use secondary memory to compensate for the scarcity of physical memory. Virtual memory provides benefits in terms of costs, physical space, multitasking capabilities, and data security.

What are the advantages of paging? ›

Advantages of Paging
  • Effective memory management.
  • Simplicity in partitioning (non-contiguous memory allocation).
  • Allocating memory is simple and inexpensive.
  • Pages are simple to share.
  • No compaction is necessary.
  • no external fragmentation.
  • more efficient swapping.

What are the two advantages and disadvantages of paging vs segmentation? ›

Segmentation permits the physical address space of a process to be non- contiguous. Paging is another memory-management scheme that offers this advantage. However, paging avoids external fragmentation and the need for compaction, whereas segmentation does not.

What is the performance of demand paging? ›

The performance of demand paging is often measured in terms of the effective access time. Effective access time is the amount of time it takes to access memory, if the cost of page faults are amortized over all memory accesses. In some sense it is an average or expected access time.

How is paging used in virtual memory? ›

When a process tries to access a page that is not in RAM, the OS brings in the page from the virtual memory. Paging improves the efficiency of memory management. By dividing memory into pages, the operating system moves pages in and out of memory as needed.

What is the difference between virtual memory and Pagefile? ›

Pagefile. RAM is a limited resource, whereas for most practical purposes, virtual memory is unlimited. There can be many processes, and each process has its own 2 GB of private virtual address space.

Does virtual memory use paging or segmentation? ›

Paging is a computer memory management function that presents storage locations to the computer's central processing unit (CPU) as additional memory, called virtual memory. Segmentation is a virtual process that creates variable-sized address spaces in computer storage for related data, called segments.

What is one disadvantage of virtual memory? ›

Using virtual memory makes a computer run slower, as the processor has to wait while data is swapped between hard disk and RAM. As secondary storage devices have slower access times than RAM, the computer's processing performance can be severely impaired.

Why is it called virtual memory? ›

In computing, virtual memory, or virtual storage, is a memory management technique that provides an "idealized abstraction of the storage resources that are actually available on a given machine" which "creates the illusion to users of a very large (main) memory".

Which of the following is a disadvantage of demand paging? ›

Disadvantages of demand paging

It has a higher chance of internal fragmentation. It takes longer to access memory. Virtual memory is limited in the Page Table Length Register (PTLR).

What are demand paging's advantages and disadvantages? ›

Its main advantage is reducing the physical memory required, enabling more applications to run at once and allowing larger programs to run. However, demand paging has some drawbacks. The page fault mechanism can delay program execution because the operating system must retrieve pages from secondary storage.

Why is paging faster? ›

Paging's address translation process is simpler and faster, involving just a few memory accesses, ensuring good system performance. Paging forms the basis for virtual memory systems, allowing the computer to run programs larger than the physical memory by swapping pages in and out of disk storage.

What are the two types of paging? ›

  • Numeric Paging Systems: Numeric paging systems are the simplest form of pagers. ...
  • Alphanumeric Paging Systems: These systems can display both numbers and text, allowing for more detailed messages to be sent.
May 6, 2023

Why demand paging approach is preferred over segmentation? ›

In context of performance, Demand Paging is faster as compared to Segmentation. Segmentation is slower in speed as compared to Pagination. In case of Demand Paging, pages get loaded in the main memory at runtime when the user demands it. In case of Segmentation, all the sections get loaded at the time of compilation.

What is paging short answer? ›

Paging is a function of memory management where a computer will store and retrieve data from a device's secondary storage to the primary storage. Memory management is a crucial aspect of any computing device, and paging specifically is important to the implementation of virtual memory.

Why does Linux use demand paging? ›

Demand paging is sometimes called “Lazy Loading” or it is basically a memory management scheme implemented in OS(Operating System) including Linux, to optimize the use of physical memory. It is a technique that allows the operating system to load pages into memory only when they are demanded by programs.

What hardware support is needed for demand paging? ›

At a minimum, demand paging requires hardware to support the logical to physical address translation. Required hardware includes a translation look-aside buffer to hold page table entries. In addition, each page must have an associated valid bit (to determine if the page is in memory).

Top Articles
'Nah, imagine working for Walmart for 35 years': Walmart worker shames employees who stay with the company for decades
Work ethic: What goes into a great one?
Is Sam's Club Plus worth it? What to know about the premium warehouse membership before you sign up
Cold Air Intake - High-flow, Roto-mold Tube - TOYOTA TACOMA V6-4.0
Craigslist Niles Ohio
Wizard Build Season 28
Readyset Ochsner.org
Apex Rank Leaderboard
Elden Ring Dex/Int Build
Atrium Shift Select
Skip The Games Norfolk Virginia
Oppenheimer & Co. Inc. Buys Shares of 798,472 AST SpaceMobile, Inc. (NASDAQ:ASTS)
Elizabethtown Mesothelioma Legal Question
Missing 2023 Showtimes Near Landmark Cinemas Peoria
Sony E 18-200mm F3.5-6.3 OSS LE Review
Gino Jennings Live Stream Today
Munich residents spend the most online for food
Tamilrockers Movies 2023 Download
Katherine Croan Ewald
Diamond Piers Menards
The Ultimate Style Guide To Casual Dress Code For Women
Site : Storagealamogordo.com Easy Call
Is Windbound Multiplayer
Filthy Rich Boys (Rich Boys Of Burberry Prep #1) - C.M. Stunich [PDF] | Online Book Share
Integer Division Matlab
Sandals Travel Agent Login
Horn Rank
Ltg Speech Copy Paste
Random Bibleizer
Craigslist Fort Smith Ar Personals
The Clapping Song Lyrics by Belle Stars
Poe T4 Aisling
R/Sandiego
Kempsville Recreation Center Pool Schedule
Rogold Extension
Beaver Saddle Ark
Log in or sign up to view
A Man Called Otto Showtimes Near Amc Muncie 12
Powerspec G512
Saybyebugs At Walmart
2007 Jaguar XK Low Miles for sale - Palm Desert, CA - craigslist
Miami Vice turns 40: A look back at the iconic series
Love Words Starting with P (With Definition)
Tlc Africa Deaths 2021
Youravon Com Mi Cuenta
Nope 123Movies Full
Kushfly Promo Code
Diario Las Americas Rentas Hialeah
Game Akin To Bingo Nyt
Marion City Wide Garage Sale 2023
Latest Posts
Article information

Author: Reed Wilderman

Last Updated:

Views: 6540

Rating: 4.1 / 5 (72 voted)

Reviews: 95% of readers found this page helpful

Author information

Name: Reed Wilderman

Birthday: 1992-06-14

Address: 998 Estell Village, Lake Oscarberg, SD 48713-6877

Phone: +21813267449721

Job: Technology Engineer

Hobby: Swimming, Do it yourself, Beekeeping, Lapidary, Cosplaying, Hiking, Graffiti

Introduction: My name is Reed Wilderman, I am a faithful, bright, lucky, adventurous, lively, rich, vast person who loves writing and wants to share my knowledge and understanding with you.