0% found this document useful (0 votes)
9 views7 pages

Virtual Memory

Uploaded by

aviral.sgsits
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views7 pages

Virtual Memory

Uploaded by

aviral.sgsits
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

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 larger applications to run on systems with less RAM.

Objectives of Virtual Memory

• To support multi programming , it allows more than one program to run at the same time.

• A program doesn’t need to be fully loaded in memory to run. Only the needed parts are
loaded.

• Programs can be bigger than the physical memory available in the system.

• Virtual memory creates the illusion of a large memory, even if the actual memory (RAM) is
small.

• It uses both RAM and disk storage to manage memory, loading only parts of programs into
RAM as needed.

• This allows the system to run more programs at once and manage memory more efficiently.
What is Virtual Memory?

Virtual memory is a way for a computer to pretend it has more RAM than it really does. When the
RAM is full, the computer moves some data to the hard drive (or SSD). This space on the hard drive is
used like extra memory. This helps the computer run bigger programs or multiple programs at the
same time, even if there isn’t enough RAM. The part of the hard drive used for this is called a page
file or swap space. The computer automatically moves data in and out of RAM and the hard drive as
needed.

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:

• Paging

• Segmentation

Paging

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:

• 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.
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.

Let Main memory access time is: m


Page fault service time is: s
Page fault rate is : p
Then, Effective memory access time = (p*s) + (1-p)*m

Page and Frame

A page is a fixed size block of data in virtual memory and a frame is a fixed size block of physical
memory in RAM where these pages are loaded. Think of a page as a piece of a puzzle (virtual
memory) While, a frame as the spot where it fits on the board (physical memory). When a program
runs its pages are mapped to available frames so the program can run even if the program size is
larger than physical memory.

Segmentation

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.

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.

Thrashing

• Only a few pages of each process are kept in main memory at a time, allowing more
processes to run simultaneously and saving time by not loading unused pages. The operating
system must carefully manage this to keep memory full of useful pages.

• When the OS loads a new page, it must remove another. If it removes a page that will be
needed soon, the system wastes time swapping pages in and out a problem called thrashing.

• To avoid this, an efficient page replacement algorithm is needed.


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 occurs in a computer system when the CPU spends more time swapping pages in and out
of memory than executing actual processes. This happens when there is insufficient physical
memory, causing frequent page faults and excessive paging activity. Thrashing reduces system
performance and makes processes run very slowly. There are many cause of thrashing as discussed
below.

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.
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.

Effective access time (EAT) = (1-p)* Memory Access Time + p * Page fault time.
Page fault time = page fault overhead + swap out + swap in +restart overhead

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.

• 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.

You might also like