Browse Course Material

Course info.

  • Chris Terman

Departments

  • Electrical Engineering and Computer Science

As Taught In

  • Computer Design and Engineering
  • Digital Systems

Learning Resource Types

Computation structures, 16 virtual memory.

BackWorksheet

ContinueAnnotated Slides

16.1 Annotated Slides

  • 16.1.1 Annotated slides

16.2 Topic Videos

  • 16.2.1 Even More Memory Hierarchy (7:09)
  • 16.2.2 Basics of Virtual Memory (12:19)
  • 16.2.3 Page Faults (6:47)
  • 16.2.4 Building the MMU (10:16)
  • 16.2.5 Contexts (4:57)
  • 16.2.6 MMU Improvements (7:33)
  • 16.2.7 Worked Examples

16.3 Worksheet

16.3.1 Virtual Memory Worksheet

facebook

You are leaving MIT OpenCourseWare

DEV Community

DEV Community

Syed Muhammad Ali Raza

Posted on Nov 26, 2023

Understanding Virtual Memory and Paging

Introduction:.

Virtual memory and paging are important concepts in modern computer systems and play an important role in managing memory resources efficiently. This concept is important for the design and operation of the operating system, which allows it to run several programs at the same time and process more data than the physical RAM can accommodate. In this article, we will explore the concept of virtual memory and paging, their importance, and how they contribute to the smoothness of a computer system.

  • Virtual Memory: An Overview

Virtual memory is a memory management technique that provides an ideal abstraction of the storage resources available on a specific device, according to Applications. It allows you to perform operations that may be larger than the available physical RAM. Instead of relying solely on physical memory, use a virtual memory combination of RAM and secondary storage (usually hard disk or SSD) to create the illusion of a larger memory space for each process.

  • Paging: Cracking It Down

Paging is a special implementation of virtual memory that involves dividing a process's virtual address space into blocks of size called "pages". Similarly, physical memory is divided into blocks of the size called "frames". The operating system maintains a table called the page table that keeps track of the mapping between virtual pages and physical frames.

  • Page Table: Mapping Mechanism

The page table becomes an important element in the virtual memory system. This table stores the mapping information between the virtual addresses used by the program and the physical addresses located in RAM. When the process accesses data, the virtual address is translated into a physical address using a page table, allowing the system to locate the actual data in physical memory.

  • Page Faults: Handling Memory Access

In a virtual memory system, not all process pages are loaded into physical memory at the same time. Instead, pages are stored on demand. A page fault occurs when a process accesses a page that is not currently in physical memory. The operating system then fetches the required page from the secondary storage into the frame available in the RAM and updates the page table accordingly.

  • Benefits of Paging and Virtual Memory
  • Increased multitasking: Virtual memory allows multiple processes to run simultaneously, although the total memory requirement is higher than physical RAM.
  • Isolation: Each process has its own virtual address that provides isolation and security.
  • Efficient use of memory: Paging allows efficient use of physical memory by loading only the required pages into RAM.
  • Challenges and Considerations
  • Productivity Success: Due to the need for regular page searches and occasional page crashes, site pages offer multiple headers.
  • Storage Device Speed: Accessing data from secondary storage is slower than retrieving data from RAM, affecting performance during page faults.

Virtual memory and paging are an integral part of modern computer systems, facilitating the use of resources and the execution of complex programs. Understanding these concepts is important for system designers, developers, and administrators to improve system performance and ensure the smooth operation of various computing environments. As technology continues to evolve, so do the techniques and methods used to manage and use virtual memory.

Top comments (0)

pic

Templates let you quickly answer FAQs or store snippets for re-use.

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink .

Hide child comments as well

For further actions, you may consider blocking this person and/or reporting abuse

waelmuawad profile image

Don't Let PERFECT be the enemy of GOOD

Wael-Muawad - Sep 6

presh1 profile image

WEB APP DEPLOYMENT WITH A CI/CD PIPELINE ON AZURE APP SERVICE USING GITHUB AND VS CODE

Omoniyi - Sep 6

nullvoidkage profile image

🚀 Flutter vs React Native: Which One Should You Choose?

Nikko Ferwelo - Sep 6

yusbuntu profile image

Chapter 5 - Building Docker Images

Yusuf Isah - Sep 6

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Page Statistics

Page Metric#
Views0
Avg. time spent0 s

Table Of Contents

  • Introduction to Functional Computer
  • Fundamentals of Architectural Design
  • Data Representation
  • Instruction Set Architecture : Instructions and Formats
  • Instruction Set Architecture : Design Models
  • Instruction Set Architecture : Addressing Modes
  • Performance Measurements and Issues
  • Computer Architecture Assessment 1
  • Fixed Point Arithmetic : Addition and Subtraction
  • Fixed Point Arithmetic : Multiplication
  • Fixed Point Arithmetic : Division
  • Floating Point Arithmetic
  • Arithmetic Logic Unit Design
  • CPU's Data Path
  • CPU's Control Unit
  • Control Unit Design
  • Concepts of Pipelining
  • Computer Architecture Assessment 2
  • Pipeline Hazards
  • Memory Characteristics and Organization
  • Cache Memory

Virtual Memory

  • I/O Communication and I/O Controller
  • Input/Output Data Transfer
  • Direct Memory Access controller and I/O Processor
  • CPU Interrupts and Interrupt Handling
  • Computer Architecture Assessment 3

Course Computer Architecture

Virtual Memory (VM) Concept is similar to the Concept of Cache Memory. While Cache solves the speed up requirements in memory access by CPU, Virtual Memory solves the Main Memory (MM) Capacity requirements with a mapping association to Secondary Memory i.e Hard Disk. Both Cache and Virtual Memory are based on the Principle of Locality of Reference. Virtual Memory provides an illusion of unlimited memory being available to the Processes/ Programmers.

In a VM implementation, a process looks at the resources with a logical view and the CPU looks at it from a Physical or real view of resources. Every program or process begins with its starting address as ‘0’ ( Logical view). However, there is only one real '0' address in Main Memory. Further, at any instant, many processes reside in Main Memory (Physical view). A Memory Management Hardware provides the mapping between logical and physical view.

VM is hardware implementation and assisted by OS’s Memory Management Task. The basic facts of VM are:

  • All memory references by a process are all logical and dynamically translated by hardware into physical.
  • There is no need for the whole program code or data to be present in Physical memory and neither the data or program need to be present in contiguous locations of Physical Main Memory. Similarly, every process may also be broken up into pieces and loaded as necessitated.
  • The storage in secondary memory need not be contiguous. (Remember your single file may be stored in different sectors of the disk, which you may observe while doing defrag).
  • However, the Logical view is contiguous. Rest of the views are transparent to the user.
  • Virtual Memory Design factors

Any VM design has to address the following factors choosing the options available.

  • Type of implementation – Segmentation, Paging, Segmentation with Paging
  • Address Translation – Logical to Physical
  • Static Translation – Few simpler programs are loaded once and may be executed many times. During the lifetime of these programs, nothing much changes and hence the Address Space can be fixed.
  • Dynamic Translation – Complex user programs and System programs use a stack, queue, pointers, etc., which require growing spaces at run time. Space is allotted as the requirement comes up. In such cases, Dynamic Address Translation is used. In this chapter, we discuss only Dynamic Address Translation Methods.
  • A Page/Segment table to be maintained as to what is available in MM
  • Identification of the Information in MM as a Hit or Page / Segment Fault
  • Page/Segment Fault handling Mechanism
  • Protection of pages/ Segments in Memory and violation identification
  • Allocation / Replacement Strategy for Page/Segment in MM –Same as Cache Memory. FIFO, LIFO, LRU and Random are few examples.
  • Segmentation

A Segment is a logically related contiguous allocation of words in MM. Segments vary in length. A segment corresponds to logical entities like a Program, stack, data, etc. A word in a segment is addressed by specifying the base address of the segment and the offset within the segment as in figure 19.2.

A segment table is required to be maintained with the details of those segments in MM and their status. Figure 19.3 shows typical entries in a segment table. A segment table resides in the OS area in MM. The sharable part of a segment, i.e. with other programs/processes are created as a separate segment and the access rights for the segment is set accordingly. Presence bit indicates that the segment is available in MM. The Change bit indicates that the content of the segment has been changed after it was loaded in MM and is not a copy of the Disk version. Please recall in Multilevel hierarchical memory, the lower level has to be in coherence with the immediately higher level. The address translation in segmentation implementation is as shown in figure 19.4. The virtual address generated by the program is required to be converted into a physical address in MM. The segment table help achieve this translation.

Generally, a Segment size coincides with the natural size of the program/data. Although this is an advantage on many occasions, there are two problems to be addressed in this regard.

  • Identifying a contiguous area in MM for the required segment size is a complex process.
  • As we see chunks are identified and allotted as per requirement. There is a possibility that there may be some gaps of memory in small chunks which are too small to be allotted for a new segment. At the same time, the sum of such gaps may become huge enough to be considered as undesirable. These gaps are called external fragmentation . External fragments are cleared by a special process like Compaction by OS.

Paging is another implementation of Virtual Memory. The logical storage is marked as Pages of some size, say 4KB. The MM is viewed and numbered as page frames. Each page frame equals the size of Pages. The Pages from the logical view are fitted into the empty Page Frames in MM. This is synonymous to placing a book in a bookshelf. Also, the concept is similar to cache blocks and their placement. Figure 19.5 explains how two program’s pages are fitted in Page Frames in MM. As you see, any page can get placed into any available Page Frame. Unallotted Page Frames are shown in white.

This mapping is necessary to be maintained in a Page Table. The mapping is used during address translation. Typically a page table contains virtual page address, corresponding physical frame number where the page is stored, Presence bit, Change bit and Access rights ( Refer figure19.6). This Page table is referred to check whether the desired Page is available in the MM. The Page Table resides in a part of MM. Thus every Memory access requested by CPU will refer memory twice – once to the page table and second time to get the data from accessed location. This is called the Address Translation Process and is detailed in figure19.7.

Figure 19.6 Typical Page Table Entry
Virtual Page AddressPage Frame NumberPresence bit PChange bit CAccess Rights
A000400010R, X
B064572801R, W, X
D001023411R, W, X
F006021600R

Page size determination is an important factor to obtain Maximum Page Hits and Minimum Thrashing. Thrashing is very costly in VM as it means getting data from Disk, which is 1000 times likely to be slower than MM.

In the Paging Mechanism, Page Frames of fixed size are allotted. There is a possibility that some of the pages may have contents less than the page size, as we have in our printed books. This causes unutilized space (fragment) in a page frame. By no means, this unutilized space is usable for any other purpose. Since these fragments are inside the allotted Page Frame, it is called Internal Fragmentation .

  • Additional Activities in Address Translation

During address translation, few more activities happen as listed below but are not shown in figures ( 19.4 and 19.7), for simplicity of understanding.

  • In segmentation, the length of the segment mentioned in the segment table is compared with the offset. If the Offset exceeds it is a Segment Violation and an error is generated to this effect.
  • The presence bit is verified to know that the requested segment/page is available in the MM.
  • The Change bit indicates that the segment/page in main memory is not a true copy of that in Disk; if this segment/page is a candidate for replacement, it is to be written onto the disk before replacement. This logic is part of the Address Translation mechanism.
  • Segment/Page access rights are checked to verify any access violation. Ex: one with Read-only attribute cannot be allowed access for WRITE, or so.
  • The OS takes over to READ the segment/page from DISK.
  • A Segment needs to be allotted from the available free space in MM. If Paging, an empty Page frame need to be identified.
  • In case, the free space/Page frame is unavailable, Page Replacement algorithm plays the role to identify the candidate Segment/Page Frame.
  • The Data from Disk is written on to the MM
  • The Segment /Page Table is updated with the necessary information that a new block is available in MM
  • Translation Look-aside Buffer (TLB)

Every Virtual address Translation requires two memory references,

  • once to read the segment/page table and
  • once more to read the requested memory word.

TLB is a hardware functionality designed to speedup Page Table lookup by reducing one extra access to MM. A TLB is a fully associative cache of the Page Table. The entries in TLB correspond to the recently used translations. TLB is sometimes referred to as address cache . TLB is part of the Memory Management Unit (MMU) and MMU is present in the CPU block.

TLB entries are similar to that of Page Table. With the inclusion of TLB, every virtual address is initially checked in TLB for address translation. If it is a TLB Miss, then the page table in MM is looked into. Thus, a TLB Miss does not cause Page fault. Page fault will be generated only if it is a miss in the Page Table too but not otherwise. Since TLB is an associative address cache in CPU, TLB hit provides the fastest possible address translation; Next best is the page hit in Page Table; worst is the page fault.

Having discussed the various individual Address translation options, it is to be understood that in a Multilevel Hierarchical Memory all the functional structures coexist. i.e. TLB, Page Tables, Segment Tables, Cache (Multiple Levels), Main Memory and Disk. Page Tables can be many and many levels too, in which case, few Page tables may reside in Disk. In this scenario, what is the hierarchy of verification of tables for address translation and data service to the CPU? Refer figure19.8.

Address Translation verification sequence starts from the lowest level i.e.

TLB -> Segment / Page Table Level 1 -> Segment / Page Table Level n

Once the address is translated into a physical address, then the data is serviced to CPU. Three possibilities exist depending on where the data is.

Case 1 - TLB or PT hit and also Cache Hit - Data returned from CPU to Cache

Case 2 - TLB or PT hit and Cache Miss - Data returned from MM to CPU and Cache

Case 3 - Page Fault - Data from disk loaded into a segment / page frame in MM; MM returns data to CPU and Cache

It is simple, in case of Page hit either Cache or MM provides the Data to CPU readily. The protocol between Cache and MM exists intact. If it is a Segment/Page fault, then the routine is handled by OS to load the required data into Main Memory. In this case, data is not in the cache too. Therefore, while returning data to CPU, the cache is updated treating it as a case of Cache Miss.

  • Advantages of Virtual Memory
  • Generality - ability to run programs that are larger than the size of physical memory.
  • Storage management - allocation/deallocation either by Segmentation or Paging mechanisms.
  • Protection - regions of the address space in MM can selectively be marked as Read Only, Execute,..
  • Flexibility - portions of a program can be placed anywhere in Main Memory without relocation
  • Storage efficiency -retain only the most important portions of the program in memory
  • Concurrent I/O -execute other processes while loading/dumping page. This increases the overall performance
  • Expandability - Programs/processes can grow in virtual address space.
  • Seamless and better Performance for users.

1. Track your progress [Earn 200 points]

Mark as complete

2. Provide your ratings to this chapter [Earn 100 points]

Virtual Memory ( CIE IGCSE Computer Science )

Revision note.

Amy Fellows

Computer Science

Virtual Memory

  • The purpose of RAM is to store current data and program instructions in use
  • The amount of physical RAM available is limited. The average modern desktop computer has between 4 GB   and 16GB of RAM. Some programs are larger t han this
  • Virtual memory is part of secondary storage which acts as RAM when RAM is full
  • It prevents the computer system crashing when RAM is full
  • Data that needs to be accessed by the CPU directly is switched by the operating system from virtual memory into RAM and an inactive page from RAM replaces it in virtual memory. This is called page switching

ram-and-virutal-memory

A diagram showing page switching between RAM and virtual memory

  • The table describes the steps that are taken when a program is opened on a computer

Worked example

Sandy is playing an open world role playing computer game set in a large 3D environment. This requires the use of virtual memory. Explain why

  • To extend the RAM capacity [1]
  • To stop the computer game from crashing when the physical RAM is full  [1]
  • To allow the computer to process the large amount of data required  [1]

You've read 0 of your 10 free revision notes

Unlock more, it's free, join the 100,000 + students that ❤️ save my exams.

the (exam) results speak for themselves:

Did this page help you?

  • Data Storage
  • Network Hardware
  • Types of Software and Interrupts
  • The internet and the World Wide Web
  • Digital Currency
  • Cyber Security
  • Automated Systems
  • Artificial Intelligence
  • Development Life Cycle

Author: Amy Fellows

Amy has been a passionate Computing teacher for over 9 years, teaching Computer Science across the East Midlands, at all levels. Amy has also been a GCSE examiner for seven years.

  • Engineering Mathematics
  • Discrete Mathematics
  • Operating System
  • Computer Networks
  • Digital Logic and Design
  • C Programming
  • Data Structures
  • Theory of Computation
  • Compiler Design
  • Computer Org and Architecture

Virtual Memory in Operating System

Virtual Memory is a storage allocation scheme in which secondary memory can be addressed as though it were part of the main memory. The addresses a program may use to reference memory are distinguished from the addresses the memory system uses to identify physical storage sites and program-generated addresses are translated automatically to the corresponding machine addresses.

What is Virtual Memory?

Virtual memory is a memory management technique used by operating systems to give the appearance of a large, continuous block of memory to applications, even if the physical memory (RAM) is limited. It allows the system to compensate for physical memory shortages, enabling larger applications to run on systems with less RAM.

A memory hierarchy, consisting of a computer system’s memory and a disk, enables a process to operate with only some portions of its address space in memory. A virtual memory is what its name indicates- it is an illusion of a memory that is larger than the real memory. We refer to the software component of virtual memory as a virtual memory manager. The basis of virtual memory is the noncontiguous memory allocation model. The virtual memory manager removes some components from memory to make room for other components.

The size of virtual storage is limited by the addressing scheme of the computer system and the amount of secondary memory available not by the actual number of main storage locations. 

Working of Virtual Memory

It is a technique that is implemented using both hardware and software. It maps memory addresses used by a program, called virtual addresses, into physical addresses in computer memory. 

  • All memory references within a process are logical addresses that are dynamically translated into physical addresses at run time. This means that a process can be swapped in and out of the main memory such that it occupies different places in the main memory at different times during the course of execution.
  • A process may be broken into a number of pieces and these pieces need not be continuously located in the main memory during execution. The combination of dynamic run-time address translation and the use of a page or segment table permits this.

If these characteristics are present then, it is not necessary that all the pages or segments are present in the main memory during execution. This means that the required pages need to be loaded into memory whenever required. Virtual memory is implemented using Demand Paging or Demand Segmentation.

Types of Virtual Memory

In a computer, virtual memory is managed by the Memory Management Unit (MMU), which is often built into the CPU. The CPU generates virtual addresses that the MMU translates into physical addresses.

There are two main types of virtual memory:

Segmentation

Paging divides memory into small fixed-size blocks called pages. When the computer runs out of RAM, pages that aren’t currently in use are moved to the hard drive, into an area called a swap file. The swap file acts as an extension of RAM. When a page is needed again, it is swapped back into RAM, a process known as page swapping. This ensures that the operating system (OS) and applications have enough memory to run.

Demand Paging: The process of loading the page into memory on demand (whenever a page fault occurs) is known as demand paging. The process includes the following steps are as follows: 

Demand Paging

Demand Paging

  • If the CPU tries to refer to a page that is currently not available in the main memory, it generates an interrupt indicating a memory access fault.
  • The OS puts the interrupted process in a blocking state. For the execution to proceed the OS must bring the required page into the memory.
  • The OS will search for the required page in the logical address space.
  • The required page will be brought from logical address space to physical address space. The page replacement algorithms are used for the decision-making of replacing the page in physical address space.
  • The page table will be updated accordingly.
  • The signal will be sent to the CPU to continue the program execution and it will place the process back into the ready state.

Hence whenever a page fault occurs these steps are followed by the operating system and the required page is brought into memory. 

What is Page Fault Service Time?

The time taken to service the page fault is called page fault service time. The page fault service time includes the time taken to perform all the above six steps. 

Segmentation divides virtual memory into segments of different sizes. Segments that aren’t currently needed can be moved to the hard drive. The system uses a segment table to keep track of each segment’s status, including whether it’s in memory, if it’s been modified, and its physical address. Segments are mapped into a process’s address space only when needed.

Combining Paging and Segmentation

Sometimes, both paging and segmentation are used together. In this case, memory is divided into pages, and segments are made up of multiple pages. The virtual address includes both a segment number and a page number.

Virtual Memory vs Physical Memory

When talking about the differences between virtual memory and physical memory, the biggest distinction is speed. RAM is much faster than virtual memory, but it is also more expensive.

When a computer needs storage for running programs, it uses RAM first. Virtual memory, which is slower, is used only when the RAM is full.

Feature Virtual Memory Physical Memory (RAM)
An abstraction that extends the available memory by using disk storage The actual hardware (RAM) that stores data and instructions currently being used by the CPU
On the hard drive or SSD On the computer’s motherboard
Slower (due to disk I/O operations) Faster (accessed directly by the CPU)
Larger, limited by disk space Smaller, limited by the amount of RAM installed
Lower (cost of additional disk storage) Higher (cost of RAM modules)
Indirect (via paging and swapping) Direct (CPU can access data directly)
Non-volatile (data persists on disk) Volatile (data is lost when power is off)

What is Swapping?

Swapping is a process out means removing all of its pages from memory, or marking them so that they will be removed by the normal page replacement process. Suspending a process ensures that it is not runnable while it is swapped out. At some later time, the system swaps back the process from the secondary storage to the main memory. When a process is busy swapping pages in and out then this situation is called thrashing. 

Swapping

Swappinghierar

What is Thrashing?

At any given time, only a few pages of any process are in the main memory, and therefore more processes can be maintained in memory. Furthermore, time is saved because unused pages are not swapped in and out of memory. However, the OS must be clever about how it manages this scheme. In the steady state practically, all of the main memory will be occupied with process pages, so that the processor and OS have direct access to as many processes as possible. Thus when the OS brings one page in, it must throw another out. If it throws out a page just before it is used, then it will just have to get that page again almost immediately. Too much of this leads to a condition called Thrashing . The system spends most of its time swapping pages rather than executing instructions. So a good page replacement algorithm is required. 

In the given diagram, the initial degree of multiprogramming up to some extent of point(lambda), the CPU utilization is very high and the system resources are utilized 100%. But if we further increase the degree of multiprogramming the CPU utilization will drastically fall down and the system will spend more time only on the page replacement and the time taken to complete the execution of the process will increase. This situation in the system is called thrashing. 

Causes of Thrashing

Thrashing

1. High Degree of Multiprogramming: If the number of processes keeps on increasing in the memory then the number of frames allocated to each process will be decreased. So, fewer frames will be available for each process. Due to this, a page fault will occur more frequently and more CPU time will be wasted in just swapping in and out of pages and the utilization will keep on decreasing. 

For example:  Let free frames = 400  Case 1 : Number of processes = 100  Then, each process will get 4 frames. 

Case 2 : Number of processes = 400  Each process will get 1 frame.  Case 2 is a condition of thrashing, as the number of processes is increased, frames per process are decreased. Hence CPU time will be consumed just by swapping pages. 

2. Lacks of Frames: If a process has fewer frames then fewer pages of that process will be able to reside in memory and hence more frequent swapping in and out will be required. This may lead to thrashing. Hence a sufficient amount of frames must be allocated to each process in order to prevent thrashing.

Recovery of Thrashing  

  • Do not allow the system to go into thrashing by instructing the long-term scheduler not to bring the processes into memory after the threshold.
  • If the system is already thrashing then instruct the mid-term scheduler to suspend some of the processes so that we can recover the system from thrashing.

Performance in Virtual Memory

  •   Let p be the page fault rate( 0 <= p <= 1).
  • if p = 0 no page faults
  • if p =1, every reference is a fault.

The performance of a virtual memory management system depends on the total number of page faults, which depend on “ paging policies ” and “ frame allocation “

Frame Allocation

    A number of frames allocated to each process in either static or dynamic.

  • Static Allocation: The number of frame allocations to a process is fixed.
  • Dynamic Allocation:   The number of frames allocated to a process changes.

Paging Policies

  • Fetch Policy: It decides when a page should be loaded into memory.
  • Replacement Policy: It decides which page in memory should be replaced.
  • Placement Policy: It decides where in memory should a page be loaded.

Applications of Virtual memory

Virtual memory has the following important characteristics that increase the capabilities of the computer system. The following are five significant characteristics of Lean.

  • Increased Effective Memory: One major practical application of virtual memory is, virtual memory enables a computer to have more memory than the physical memory using the disk space. This allows for the running of larger applications and numerous programs at one time while not necessarily needing an equivalent amount of DRAM.
  • Memory Isolation: Virtual memory allocates a unique address space to each process and that also plays a role in process segmentation. Such separation increases safety and reliability based on the fact that one process cannot interact with and or modify another’s memory space through a mistake, or even a deliberate act of vandalism.
  • Efficient Memory Management: Virtual memory also helps in better utilization of the physical memories through methods that include paging and segmentation. It can transfer some of the memory pages that are not frequently used to disk allowing RAM to be used by active processes when required in a way that assists in efficient use of memory as well as system performance.
  • Simplified Program Development: For case of programmers, they don’t have to consider physical memory available in a system in case of having virtual memory. They can program ‘as if’ there is one big block of memory and this makes the programming easier and more efficient in delivering more complex applications.

How to Manage Virtual Memory?

Here are 5 key points on how to manage virtual memory:

1. Adjust the Page File Size

  • Automatic Management : All contemporary operating systems including Windows contain the auto-configuration option for the size of the empirical page file. But depending on the size of the RAM, they are set automatically, although the user can manually adjust the page file size if required.
  • Manual Configuration: For tuned up users, the setting of the custom size can sometimes boost up the performance of the system. The initial size is usually advised to be set to the minimum value of 1. To set the size of the swap space equal to 5 times the amount of physical RAM and the maximum size 3 times the physical RAM.

2. Place the Page File on a Fast Drive

  • SSD Placement: If this is feasible, the page file should be stored in the SSD instead of the HDD as a storage device. It has better read and write times, and the virtual memory may prove benefecial in an SSD.
  • Separate Drive: Regarding systems having multiple drives involved, the page file needs to be placed on a different drive than the os and that shall in turn improve its performance.

3. Monitor and Optimize Usage

  • Performance Monitoring: Employ the software tools used in monitoring the performance of the system in tracking the amounts of virtual memory. High page file usage may signify that there is a lack of physical RAM or that virtual memory needs a change of settings or addition in physical RAM.
  • Regular Maintenance: Make sure there is no toolbar or other application running in the background, take time and uninstall all the tool bars to free virtual memory.

4. Disable Virtual Memory for SSDs (with Sufficient RAM)

  • Sufficient RAM: If for instance your system has a big physical memory, for example 16GB and above then it would be advised to freeze the page file in order to minimize SSD usage. But it should be done, in my opinion, carefully and only if the additional signals that one decides to feed into his applications should not likely use all the available RAM.

5. Optimize System Settings

  • System Configuration: Change some general properties of the system concerning virtual memory efficiency. This also involves enabling additional control options in Windows such as adjusting additional system setting option on the operating system, or using other options in different operating systems such as Linux that provides different tools and commands to help in adjusting how virtual memory is utilized.
  • Regular Updates: Ensure that your drivers are run in their newest version because new releases contain some enhancements and issues regarding memory management.

Advantages  of Virtual Memory

  • More processes may be maintained in the main memory: Because we are going to load only some of the pages of any particular process, there is room for more processes. This leads to more efficient utilization of the processor because it is more likely that at least one of the more numerous processes will be in the ready state at any particular time.
  • A process may be larger than all of the main memory: One of the most fundamental restrictions in programming is lifted. A process larger than the main memory can be executed because of demand paging . The OS itself loads pages of a process in the main memory as required.
  • It allows greater multiprogramming levels by using less of the available (primary) memory for each process.
  • It has twice the capacity for addresses as main memory.
  • It makes it possible to run more applications at once.
  • Users are spared from having to add memory modules when RAM space runs out, and applications are liberated from shared memory management.
  • When only a portion of a program is required for execution, speed has increased.
  • Memory isolation has increased security.
  • It makes it possible for several larger applications to run at once.
  • Memory allocation is comparatively cheap.
  • It doesn’t require outside fragmentation.
  • It is efficient to manage logical partition workloads using the CPU .
  • Automatic data movement is possible.

Disadvantages of Virtual Memory

  • It can slow down the system performance, as data needs to be constantly transferred between the physical memory and the hard disk.
  • It can increase the risk of data loss or corruption, as data can be lost if the hard disk fails or if there is a power outage while data is being transferred to or from the hard disk.
  • It can increase the complexity of the memory management system, as the operating system needs to manage both physical and virtual memory.

In conclusion, virtual memory is a crucial feature in operating systems that allows computers to run larger applications and handle more processes than the physical RAM alone can support. By using techniques like paging and segmentation, the system extends the available memory onto the hard drive , ensuring that the operating system and applications can operate smoothly. Although virtual memory can introduce some performance overhead due to the slower speed of hard drives compared to RAM, it provides significant benefits in terms of memory management, efficiency, and multitasking capabilities.

Frequently Asked Questions on Virtual Memory – FAQs

Why is virtual memory important.

Virtual memory is important because it allows the system to handle larger applications and multiple applications simultaneously without running out of physical memory. It helps in optimizing the use of available RAM and provides a buffer against memory shortages.

What is a page file or swap space in virtual memory?

Page file is also known as Virtual memory file in windows while Swap space is known as page file in Unix/Linux It is a disk area assigned by the operating system to act as extension of physical memory. If RAM is saturated, then finally inactive page of memory is swapped to this area, to provide the occupied RAM for more active processes. This process is known as paging or swapping.

Can virtual memory affect system performance?

Virtual memory may affect the efficiency of the operation of the computer. Too much usage of the virtual memory will result in what is referred to as a thrashing where the system spends most of its time swapping data between the RAM and the disk with little time executing applications thus, slows down the system. This can be solved by having enough physical RAM and to correctly setup the page file or swap space.

What is a page fault?

A page fault occurs when a program tries to access data that is not currently in RAM. The operating system then retrieves the required page from the hard drive and loads it into RAM.

Please Login to comment...

Similar reads.

  • Operating Systems
  • memory-management
  • Best Twitch Extensions for 2024: Top Tools for Viewers and Streamers
  • Discord Emojis List 2024: Copy and Paste
  • Best Adblockers for Twitch TV: Enjoy Ad-Free Streaming in 2024
  • PS4 vs. PS5: Which PlayStation Should You Buy in 2024?
  • 15 Most Important Aptitude Topics For Placements [2024]

Improve your Coding Skills with Practice

 alt=

What kind of Experience do you want to share?

What-Is-Virtual-Memory

What Is Virtual Memory?

CC-logo-short.png?w=1000

  • Share article on Twitter
  • Share article on Facebook
  • Share article on LinkedIn

Have you ever wondered how your computer can handle running a browser full of open tabs, email applications, the IDE with your latest development project, a virtual machine , and your music player — all at the same time? Sure, you have 8GB of RAM (random access memory) installed, but what happens when that runs out?

The truth is that we all use far more than our installed physical RAM and it’s all thanks to virtual memory. But what is virtual memory, and how does it work?

In this article, we’ll walk you through the basics of virtual memory, including what it is, how it works, and why it’s so important.

Learn something new for free

Intro to chatgpt, what is virtual memory.

Virtual memory is a memory management technique used by operating systems (OS) . It allows a computer to temporarily increase the capacity of its main memory — RAM — by using secondary memory such as a hard drive or solid-state drive (SSD). Virtual memory utilizes hardware and software to manage how information is stored and retrieved from the hard drive.

Virtual memory helps people do more on their computers without paying for more RAM capacity. While memory is much cheaper today than it used to be, RAM is still one of the most expensive types of memory — only cache memory is more expensive.

How does virtual memory work?

Whenever your computer stores something in RAM, that information is assigned a memory address — a reference to where the information is stored on the RAM chip. When your computer starts running low on RAM, the OS will start transferring data from the RAM to your hard drive. The OS sets up a paging file: A dedicated space on your hard drive for virtual memory.

Data stored on a hard drive is always assigned a physical address — a reference to where the information is stored in the drive. The OS also maps physical addresses to virtual addresses as part of the virtual memory process. Virtual addresses look like RAM addresses. That way, when a program is running on your computer, it can seamlessly use RAM or virtual memory. When a program uses data stored in virtual memory, the OS knows how to find the data using the physical address.

To better understand how virtual memory works, let’s imagine a situation: calculating the sum of some numbers.

How virtual memory works

Suppose that you need to sum up a list of numbers without using a calculator. If someone just gave you three or four small numbers, chances are that you could calculate the sum fairly quickly.

Now imagine that, instead of three small numbers, you needed to calculate a long list of big numbers, small numbers, negative numbers, and decimals. To help make sure you don’t forget anything, you might write down the list of numbers on a sheet of paper. Then, you could sum up the first two numbers, remember the sum, add the third number to the sum, and so on. In this example, the numbers you can remember correspond to the RAM, while writing down numbers is similar to using disk storage.

We all have different capacities to quickly recall complex information that we just learned — in other words, we all have different RAM capacities. By putting some information into a form of long-term storage — on a sheet of paper — we can focus our mental efforts on solving the problem one step at a time.

Of course, writing down everything takes time. It’s not as fast as memorizing each step and keeping everything in your head. That’s the trade-off of virtual memory. While it does help improve computer performance and multitasking, virtual memory is slower than RAM.

The OS constantly decides which data should be quickly accessible and keeps that data in the RAM to optimize performance. If the data isn’t needed right away, then the OS moves it to virtual memory.

How does your computer decide what goes into virtual memory?

Once your computer’s RAM is full, the OS will need to start moving data to virtual memory. The next question is much trickier: how should a computer decide what stays in the faster RAM and what goes to slower virtual memory?

Three common algorithms are used for managing virtual memory: FIFO, LRU, and OPT.

First-in, first-out (FIFO) is the most straightforward virtual memory management algorithm . The idea is to take the data that’s been in RAM the longest and move it to virtual memory. When that space is used up, the data that’s been in RAM the second-longest is moved to virtual memory, and so on.

It’s easy for an OS to use FIFO since it doesn’t rely on complex labeling and prediction algorithms. On the other hand, it’s rarely the most practical algorithm to use — just because your computer loaded some data into RAM a while ago, doesn’t mean it’s not in use.

A more sophisticated virtual memory algorithm is called the least recently used (LRU) algorithm. Here, your computer keeps track of when data is used in RAM. When it’s time to make more room in RAM, the computer replaces the data that hasn’t been used for the longest time.

The most advanced virtual memory algorithm is known as the optimal algorithm, or OPT. In addition to considering past data usage like LRU, OPT also predicts which data will be needed soon. That way, the most relevant data is always kept in RAM.

While the OPT algorithm offers the best virtual memory performance, it’s also the hardest to implement.

Why not use virtual memory all the time?

Virtual memory is an amazing tool that helps people get more out of limited memory resources on their computers, so why not use it all the time — or even dedicate an entire hard drive for virtual memory? There are two big reasons that virtual memory shouldn’t be the default substitute for RAM.

First, it takes more time to read and write data on a hard drive than it does on RAM. The more your computer relies on virtual memory, the slower your programs will run and the less you’ll be able to effectively run multiple programs at once.

Second, swapping data between virtual memory and RAM takes time. If the OS spends too much time swapping data between RAM and virtual memory, it can lead to thrashing — a severe drop in performance because too many computer resources are being dedicated to managing virtual memory and updating the paging file.

Virtual memory is important for every developer

Without virtual memory, your computer would stop loading more applications once the RAM was full. It would be up to you to close your browser tabs, shut down applications, and manage RAM usage on your own. You might not even be able to run some applications at all without upgrading your RAM.

Software Developers can focus on stunning front-end designs and optimized back-end solutions to create amazing web pages and applications thanks to virtual memory. Some programming languages like C++ even allow you to manage memory resources directly.Interested in learning more? Our online programming courses will teach you more about C++ and other in-demand programming languages.

Related courses

Learn to code with blockly, choosing a programming language, choosing a career in tech, subscribe for news, tips, and more, related articles.

Post-Quiz-Illustration.png?w=1024

Behind the Build: Designing Post-Quiz Review

Feedback is back in town with post-quiz review.

Group-2863.png?w=1024

How to Estimate the Amount of Time You Need for a Project 

How long is a piece of string? Estimating software engineering work is part science, part finger in the air — here’s some practical advice to get started.

How-to-Use-AI-to-Get-Ahead-in-School.webp?w=1024

How to Use AI to Get Ahead in School

Get AI-ready for the school year by learning these concepts.

CC-BTS-Blog-illustration-College-Students.webp?w=1024

8 Ways Students Use Codecademy to Excel in Class (& Life)

Learn the skills you’ll actually use in the real world with Codecademy Student Pro.

Introduction To OS

  • Introduction to Operating System
  • Evolution of Operating System
  • Types of Operating System

Process & MultiThreading

  • Operating System Processes
  • Process Scheduling

CPU Scheduling

  • First Come First Serve
  • Shortest Job First
  • Priority Scheduling
  • Round Robin Scheduling
  • Multilevel Queue Scheduling
  • Multilevel Feedback Queue Scheduling
  • Comparision of Scheduling Algorithms
  • Introduction to Threads
  • Process Synchronization
  • Classical Synchronization Problems
  • Bounded Buffer Problem
  • Dining Philosophers Problem
  • Readers Writer Problem
  • Semaphores in OS
  • Classical Problems of Synchronization
  • Deadlock Prevention in OS
  • Deadlock Avoidance in OS
  • Deadlock Detection and Recovery
  • HRRN Scheduling
  • Shortest Remaining Time First
  • Longest Job First Scheduling
  • Longest Remaining Time First Scheduling
  • Memory Management
  • Partition Allocation Methods
  • Virtual Memory
  • File System
  • Banker's Algorithm
  • Secondary Storage
  • Resource Allocation Graph
  • System Calls
  • Logical and Physical Address
  • Swapping in OS
  • Contiguous Memory Allocation
  • Paging in OS
  • Page Table in OS
  • Segmentation in OS
  • Paging Vs Segmentation
  • Contiguous Vs Non-Contiguous
  • Paging Vs Swapping
  • Internal Vs External Fragmentation
  • Virtual Memory in OS
  • Demand Paging in OS
  • Copy on Write in OS
  • Page Fault in OS
  • Page Replacement Algorithm
  • Thrashing in OS

What is Virtual Memory?

In this tutorial, we will be covering the concept of Virtual Memory in an Operating System.

Virtual Memory is a space where large programs can store themselves in form of pages while their execution and only the required pages or portions of processes are loaded into the main memory. This technique is useful as a large virtual memory is provided for user programs when a very small physical memory is there. Thus Virtual memory is a technique that allows the execution of processes that are not in the physical memory completely.

Virtual Memory mainly gives the illusion of more physical memory than there really is with the help of Demand Paging.

In real scenarios, most processes never need all their pages at once, for the following reasons :

Error handling code is not needed unless that specific error occurs, some of which are quite rare.

Arrays are often over-sized for worst-case scenarios, and only a small fraction of the arrays are actually used in practice.

Certain features of certain programs are rarely used.

In an Operating system, the memory is usually stored in the form of units that are known as pages . Basically, these are atomic units used to store large programs.

Virtual memory can be implemented with the help of:-

Demand Paging

Demand Segmentation

Need of Virtual Memory

Following are the reasons due to which there is a need for Virtual Memory:

In case, if a computer running the Windows operating system needs more memory or RAM than the memory installed in the system then it uses a small portion of the hard drive for this purpose.

Suppose there is a situation when your computer does not have space in the physical memory, then it writes things that it needs to remember into the hard disk in a swap file and that as virtual memory.

Benefits of having Virtual Memory

Large programs can be written, as the virtual space available is huge compared to physical memory.

Less I/O required leads to faster and easy swapping of processes.

More physical memory available, as programs are stored on virtual memory, so they occupy very less space on actual physical memory.

Therefore, the Logical address space can be much more larger than that of physical address space.

Virtual memory allows address spaces to be shared by several processes.

During the process creation, virtual memory allows: copy-on-write and Memory-mapped files

Execution of the Program in the Virtual memory

With the help of the Operating system few pieces of the program are brought into the main memory:

  • A portion of the process that is brought in the main memory is known as Resident Set.

Whenever an address is needed that is not in the main memory, then it generates an interrupt. The process is placed in the blocked state by the Operating system. Those pieces of the process that contains the logical address are brought into the main memory.

The basic idea behind demand paging is that when a process is swapped in, its pages are not swapped in all at once. Rather they are swapped in only when the process needs them(On-demand). Initially, only those pages are loaded which will be required by the process immediately.

The pages that are not moved into the memory, are marked as invalid in the page table. For an invalid entry, the rest of the table is empty. In the case of pages that are loaded in the memory, they are marked as valid along with the information about where to find the swapped out page.

Page Replacement

As studied in Demand Paging, only certain pages of a process are loaded initially into the memory. This allows us to get more number of processes into memory at the same time. but what happens when a process requests for more pages and no free memory is available to bring them in. Following steps can be taken to deal with this problem :

Put the process in the wait queue, until any other process finishes its execution thereby freeing frames.

Or, remove some other process completely from the memory to free frames.

Or, find some pages that are not being used right now, move them to the disk to get free frames. This technique is called Page replacement and is most commonly used. We have some great algorithms to carry on page replacement efficiently.

A process that is spending more time paging than executing is said to be thrashing. In other words, it means, that the process doesn't have enough frames to hold all the pages for its execution, so it is swapping pages in and out very frequently to keep executing. Sometimes, the pages which will be required in the near future have to be swapped out.

Initially, when the CPU utilization is low, the process scheduling mechanism, to increase the level of multiprogramming loads multiple processes into the memory at the same time, allocating a limited amount of frames to each process. As the memory fills up, the process starts to spend a lot of time for the required pages to be swapped in, again leading to low CPU utilization because most of the processes are waiting for pages. Hence the scheduler loads more processes to increase CPU utilization, as this continues at a point of time the complete system comes to a stop.

Advantages of Virtual Memory

Given below are the advantages of using Virtual Memory:

Virtual Memory allows you to run more applications at a time.

With the help of virtual memory, you can easily fit many large programs into smaller programs.

With the help of Virtual memory, a multiprogramming environment can be easily implemented.

As more processes should be maintained in the main memory which leads to the effective utilization of the CPU.

Data should be read from disk at the time when required.

Common data can be shared easily between memory.

With the help of virtual memory, speed is gained when only a particular segment of the program is required for the execution of the program.

The process may even become larger than all of the physical memory.

Disadvantages of Virtual Memory

Given below are the drawbacks of using Virtual Memory:

Virtual memory reduces the stability of the system.

The performance of Virtual memory is not as good as that of RAM.

If a system is using virtual memory then applications may run slower.

Virtual memory negatively affects the overall performance of a system.

Virtual memory occupies the storage space, which might be otherwise used for long term data storage.

This memory takes more time in order to switch between applications.

  • ← Prev
  • Next →

  OS MCQ Tests

  gate mcq tests.

COMMENTS

  1. PDF A Study of Virtual Memory Usage and Implications for Large Memory

    The maximum number of virtual memory mappings ac-tually used is in the thousands, a relatively small number given that the maximum supported is effectively unlim-ited. Applications perform most of their virtual memory allo-cations at startup or at well-defined boundaries between workload phases. Linking memory protection to virtual address ...

  2. PDF Chapter 10

    10.3 Block Mapping. Figure 10.6 Virtual address format in a block mapping system. Given a virtual address v = (b, d) Block map origin register stored in a. Block number, b, is added to a to locate the appropriate entry in the block map table. Block map table entry yields the address, b ́, of the start of block. b in main memory.

  3. A survey of memory management techniques in virtualized systems

    2.2. Virtualizing the memory management unit. The virtual memory subsystem in an operating system provides the illusion of unlimited memory (as large as the address space) to processes. The virtual to physical address mapping is performed at run time using specialized hardware, the Memory Management Unit (MMU).

  4. PDF Virtual Memory: Concepts

    Programmer's view of virtual memory. Each process has its own private linear address space. Cannot be corrupted by other processes. System view of virtual memory. Uses memory efficiently by caching virtual memory pages. Efficient only because of locality. Simplifies memory management and programming.

  5. Term Paper ON Virtual Memory

    Term Paper ON Virtual Memory - Free download as Word Doc (.doc / .docx), PDF File (.pdf), Text File (.txt) or read online for free. The document is a term paper on virtual memory. It discusses virtual memory techniques like demand paging and demand segmentation. Demand paging divides processes into pages that are loaded into memory on demand ...

  6. Virtual Memory Term Paper

    Virtual Memory Term Paper - Free download as PDF File (.pdf), Text File (.txt) or read online for free. The document discusses writing a term paper on virtual memory. It explains that virtual memory is a fundamental computer science concept that allows computers to run programs and handle data larger than the available physical memory. Writing a term paper on this complex technical topic ...

  7. Term Paper On Virtual Memory

    Term Paper on Virtual Memory - Free download as PDF File (.pdf), Text File (.txt) or read online for free. The document discusses the challenges of writing a thesis on the complex topic of virtual memory. It explains that virtual memory allows a computer to use hard disk space as additional "memory" by transferring data between RAM and hard disk.

  8. PDF Virtual Memory

    Virtual memory is central. Virtual memory pervades all levels of computer systems, playing key roles in the design of hardware exceptions, assemblers, linkers, loaders, shared objects, files, and processes. Understanding virtual memory will help you better understand how systems work in general. Virtual memory is powerful.

  9. 16 Virtual Memory

    16 Virtual Memory 16.1 Annotated Slides 16.2 Topic Videos 16.3 Worksheet 17 Virtualizing the Processor 17.1 Annotated Slides 17.2 Topic Videos 17.3 Worksheet 18 Devices and Interrupts 18.1 Annotated Slides 18.2 Topic Videos 18.3 Worksheet 19 Concurrency and Synchronization ...

  10. 13.2: Virtual Memory in the Operating System

    The computer's operating system, using a combination of hardware and software, maps memory addresses used by a program, called virtual addresses, into physical addresses in computer memory. Main storage, as seen by a process or task, appears as a contiguous address space or collection of contiguous segments. The operating system manages virtual ...

  11. 2542 PDFs

    Explore the latest full-text research PDFs, articles, conference papers, preprints and more on VIRTUAL MEMORY. Find methods information, sources, references or conduct a literature review on ...

  12. Term Paper: Virtual Memory Management

    Virtual memory helps free applications from having to deal with the problems of shared memory space. Essentially, systems use "virtual memory to address more memory than is physically available in the system" (IBM, 2009). Overall, increases the efficiency of the software and hardware of a particular system.

  13. Memory Management in Operating System

    This paper also describes about the basic concept of virtual memory management and dynamic memory management. Discover the world's research. 25+ million members; 160+ million publication pages;

  14. Understanding Virtual Memory and Paging

    Paging: Cracking It Down. Paging is a special implementation of virtual memory that involves dividing a process's virtual address space into blocks of size called "pages". Similarly, physical memory is divided into blocks of the size called "frames". The operating system maintains a table called the page table that keeps track of the mapping ...

  15. Virtual Memory

    Virtual Memory. Virtual Memory (VM) Concept is similar to the Concept of Cache Memory. While Cache solves the speed up requirements in memory access by CPU, Virtual Memory solves the Main Memory (MM) Capacity requirements with a mapping association to Secondary Memory i.e Hard Disk. Both Cache and Virtual Memory are based on the Principle of ...

  16. Virtual Memory

    The amount of physical RAM available is limited. The average modern desktop computer has between 4GB and 16GB of RAM. Some programs are larger than this. Virtual memory is part of secondary storage which acts as RAM when RAM is full. It prevents the computer system crashing when RAM is full. Data that needs to be accessed by the CPU directly is ...

  17. Virtual Memory in Operating System

    Virtual Memory in Operating System

  18. Virtual Memory: How Your Computer Manages Memory Beyond ...

    Virtual memory uses both hardware and software to aid your computer to satisfy an absence of physical memory by temporarily displacing data from random access memory ( RAM) to disk storage. By ...

  19. Virtual Memory

    Virtual memory is a memory management technique developed for multitasking kernels. 3. In virtual memory Operating systems have memory areas that are pinned (never swapped to secondary storage). For example, interrupt mechanisms rely on an array of pointers to their handlers, such as I/O completion and page fault.

  20. What Is Virtual Memory?

    Virtual memory is a memory management technique used by operating systems (OS). It allows a computer to temporarily increase the capacity of its main memory — RAM — by using secondary memory such as a hard drive or solid-state drive (SSD). Virtual memory utilizes hardware and software to manage how information is stored and retrieved from ...

  21. Virtual Memory in Operating System

    Virtual memory reduces the stability of the system. The performance of Virtual memory is not as good as that of RAM. If a system is using virtual memory then applications may run slower. Virtual memory negatively affects the overall performance of a system. Virtual memory occupies the storage space, which might be otherwise used for long term ...

  22. Virtual Memory

    Virtual memory is a memory management technique developed for multitasking kernels. 3. In virtual memory Operating systems have memory areas that are pinned (never swapped to secondary storage). For example, interrupt mechanisms rely on an array of pointers to their handlers, such as I/O completion and page fault.