You are on page 1of 41

Virtual Memory

Anandha Prakash 1901011

Geetha A P 1901039 Brindha M 1901029


What is Virtual Memory?

❯ The term virtual memory refers to something which appears to be present


but actually it is not.

❯ The virtual memory technique allows users to use more memory for
program than the real memory of computer.

❯ A technique using main memory as a “cache” for secondary storage (disk).


Main memory needs to contain only the active portions of the programs
Why we use it?
❯ Multitasking
When a computer user opens multiple programs at once, the data for these
programs must be stored in memory for quick access.
The more programs are open, the more memory is needed.
When the computer's physical memory is full, the excess data is stored in
virtual memory.
❯ Large Programs
Virtual memory allows programmers to create larger and more complex
applications.
When these programs are running, they occupy physical memory as well as
virtual memory.
Virtual address maps to RAM (Physical) address

RAM

PROCESSOR
PROCESSOR RAM
Memory Management Unit
MMU converts virtual address into physical address
The page table maps each VM page to either a page in main memory or a page stored on disk.

Virtual page
number is used to frame
index the page frame
table. frame
frame

Valid bit 0 : the page


currently resides only
on disk, at a specified
disk address.
The page table

2 20 = 4GB 2 12 = 4096= 4KB

Each process OS algorithm


has such determines
register. the physical
page
number.

2 18 = 2GB
❯ Each process has its own page table (+register), since different processes use the
same virtual addresses.

❯ The OS allocates the physical memory and updates the page tables, to avoid
collision of the virtual address spaces of different processes.

❯ Separate page tables provide protection of one process from another.


PAGE REPLACEMENT ALGORITHMS

FIFO (First In First Out) : Rather than choosing the victim page at random ,the
oldest page is the first to be removed.

OPTIMAL: Eliminate the page that be not excepted to be used.

LRU (Least Recently Used) : Move out the page which is least rarely used .
❯ Virtual memory is implemented using,

Demand paging Demand Segmentation


VIRTUAL MEMORY
❯ The OS creates the space on disk for all the pages of a process when it
creates the process.

❯ This disk space is called the swap space.

❯ When all the pages in main memory are in use, the OS chooses a page to
replace. Replaced pages are written to swap space on the disk.

❯ To minimize the number of page faults LRU is used. But it is too


expensive, requiring updating a data structure on every memory
reference.
Swapping
❯ Swapping is the process that removes all of its pages from memory,
or allowing them to be removed by the normal page replacement
process.
FIFO OPTIMAL LRU

❯ Suspending a process ensures that it is not executable while it is


swapped out. When required, the system swaps back the process
from the secondary storage to main memory.

❯ Swapping pages in and out is referred to as “Thrashing”.


Demand paging
❯ Demand paging is a type of swapping that is done in virtual memory systems.

❯ Demand paging as it says ,only copies data from the disk to the RAM if the data is required
by some program, therefore meaning that the data will not be when the data is already
available on the memory.

❯ Memory is split up into equal sized sections called pages (or page frames)
❯ A single application may occupy multiple pages, which are not necessarily contiguous.
❯ Unused pages may be paged out to a swap file on disc to make room for others , Pages are
paged in when needed again
❯ When memory is low, excessive swapping can lead to disc threshing and degrade
performance
Demand Segmentation
Demand Segmentation
Demand Segmentation
Demand Segmentation
Demand Segmentation
Demand segmentation
❯ Segments are swapped between disc and main memory as needed
❯ This action will decrease the number of page faults.
❯ Data segments correspond to data structures such as stacks, queues or graphs
❯ Segments vary in size
❯ A segment in memory can be replaced by a segment of the same size or
smaller
❯ Segmentation can result in memory fragmentation; a lot of small segments
with gaps in between
❯ Segments can be "pushed together" to limit fragmentation and allow large
segments to be loaded
Usually every process has its own mapping table
Fast Address Translation: The TLB

A special cache, called Translation Look-aside Buffer (TLB), keeps track of


recently used translations
𝟐𝒑𝟏 𝟑𝟐-bit
entries

𝟐𝒅 words
in main
memory

𝟐𝒑𝟐 entries per page

𝟐𝒑𝟏 pages in main memory


Two-level page-table (forward-mapped page table).
Advantages of Virtual Memory

❑ Protection Sharing
❑ VM supports Swapping
❑ Allows more than one program to be executed at the same time.
❑ Common data or code may be shared between memory.
❑ Virtual memory increases the overall memory on a system without
adding RAM, this is advantageous as virtual memory is less
expensive.
❑ Eliminates external fragmentation.
Disadvantages
❯ If the system relies to much on virtual memory, it may cause a decrease in
performance.

❯ The more virtual memory that’s being used, the less disk space a user has
for storage.

❯ Time it takes to read from a magnetic disk is greater than the time to
access RAM, therefore swapping should be avoided wherever
performance is important.
❯ Ultimately meaning that it would take greater time to switch between
applications.

You might also like