0% found this document useful (0 votes)
17 views

Paging Concept of Virtual Memory 2

Coa pahing

Uploaded by

kavinjothi18
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

Paging Concept of Virtual Memory 2

Coa pahing

Uploaded by

kavinjothi18
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 34

PAGING CONCEPT OF

VIRTUAL MEMORY
BATCH 3
DHANUSH S – 23I213
DHEVASRIE P P – 23I214
DHIVYESS YADAV N– 23I215
DHYANESH P – 23I216
DUSHAL VIGNESH – 23I217
GIRETHAREN M– 23I218
INTRODUCTION
What is Virtual Memory?
• Memory management technique extending physical
RAM using disk storage.
• Enables large programs to run on limited physical
memory.
• Provides each program with its own large, continuous
address space.
• Uses disk storage (swap space) for data not currently
in RAM.
How Virtual Memory Works
• Programs access data using virtual addresses.
• Data not in RAM is swapped from disk to RAM when
needed.
• Managed by the Operating System.

3
BALANCE 1 GB
What is Paging?
• Virtual memory is divided into fixed-size blocks called pages.
• Physical memory (RAM) is divided into page frames of the
same size.
• Pages are mapped to frames using a Page Table.
• Optimizes memory use.
• Entries get reduced by 1000 times.

1 WORD = 4 BYTES

1 PAGE = 4 KB (4096 BYTES)


PAGE TABLES
WHAT IS PAGE
TABLE
• A page table is a data structure used by a virtual memory system in a
computer to store mappings between virtual addresses and physical
addresses.
• Each mapping between the virtual address and the physical address is
called “page table entry”.
TYPES OF PAGE
TABLES
• SINGLE-LEVEL:In a single-level page table, each entry maps a virtual
page number to a physical frame number.
• MULTI-LEVEL:They break down the virtual address space into multiple
levels of page tables. This hierarchical structure reduces the size of
the page table and improves memory efficiency.
• INVERTED: In this approach, the page table maps physical frames to
virtual pages. This can be efficient for systems with many processes,
but it requires a complex lookup mechanism.
HOW DOES THE TABLE
FUNCTIONS
• Virtual Address Generation
• Page Table Lookup
• Physical Address Calculation
• Memory access
• Virtual Address Generation:
- When a process executes, it generates virtual addresses,
which are logical addresses that the process uses to access memory.
• Page Table Lookup:
-The virtual address is divided into two parts: the page
number and the offset within the page.
-The page number is used as an index to access the page table.

-The corresponding entry in the page table contains


information about the physical frame where the page is located, as well
as other attributes like access permissions and whether the page is
present in physical memory.
• Physical Address Calculation:
-The physical address is formed by concatenating the physical
frame number with the page offset.
-Physical Address = (Physical Frame Number << Page Offset Bits) +
Page Offset.
Eg:
Consider a system with a 32-bit virtual address space and 16-bit physical addresses.
If the page size is 4 KB (2^12 bytes), then the virtual address can be divided into a
20-bit page number and a 12-bit page offset.
Virtual Address: 0x12345
Page Number: 0x123
Page Offset: 0x45

Physical Address = (0x10 << 12) + 0x45 = 0x10045


• Memory access:
-The CPU uses the physical address to access the desired data
from main memory.
->Direct Memory access
->Programmed I/O
Factors affecting access speed:
->Page Table Size.
->Page Table Location
->Page Replacement Algorithm
->Memory Hierarchy
FRAME ALLOCATION
 Frame Allocation is a technique used in paging systems to manage physical memory.
 Each process needs minimum number of frames.

 Example: IBM 370-6 pages to handle SS MOVE instruction:


- instruction is 6 bytes, might span 2 pages
- 2 pages to handle from
- 2 pages to handle to

 Maximum of course is total frames in the system

 Two major allocation schemes


- fixed allocation
- priority allocation
FIXED ALLOCATION
Equal allocation-For example, if there are 100 frames (after allocating frames for the OS) and 5
processes, give each process 20 frames

- Keep some as free frame buffer pool

Proportional allocation - Allocate according to the size of process

-Dynamic as degree of multiprogramming, process sizes


M=62
PRIORITY ALLOCATION
Use a proportional allocation scheme using priorities rather than size

If process P, generates a page fault,


-select for replacement one of its frames

-select for replacement a frame from a process with lower priority number
LOBAL VS LOCAL ALLOCATION
 Global replacement - process selects a replacement frame from the set of all frames; one
process can take a frame from another
- But then process execution time can vary greatly
-But greater throughput so more common

 Local replacement - each process selects from only its own set of allocated frames
-More consistent per-process performance
- But possibly underutilized memory
DVANTAGES & DISADVANTAGES
 Advantages:
-Reduces external fragmentation.

-Efficient memory usage with paging.

 Disadvantages:
-Internal fragmentation within frames.

-Requires maintenance of page tables.


PAGE FAULTS AND
THEIR MANAGEMENT
WHAT IS PAGE FAULT?
● A page fault occurs in a virtual memory system when a
program accesses a page that is not currently in physical
memory (RAM).

● This triggers a sequence of events where the operating


system must manage the fault by loading the required data
from secondary storage into RAM.

● This is a normal and necessary process in modern operating


systems that use demand paging.
CAUSES OF PAGE FAULTS
● Accessing the page that is not currently loaded in the
memory (RAM).

● It occurs when a program tries to access that memory


which is it’s beyond access boundaries or not allocated

● when a process tries to write to a read-only page or


otherwise violates memory protection rules.
TYPES OF PAGE FAULT

● Minor Page Fault:


Occurs when the required page is in memory but not in
current process’s page table.
● Major Page Fault:
Occurs when the page is not in memory and must be fetched
from disk.
● Invalid Page Fault:
It happens when the process tries to access an invalid memory
address.
1.
The process attempts to access a
memory location (load M) which
refers to a virtual address.
2.
A page fault occurs because the
corresponding page is not present in
physical memory. This generates a
trap to the operating system.
3.
The operating system checks the page
table and identifies that the page is
on the secondary storage.
4.

The operating system retrieves the


required page from the secondary storage
and copies it into a free frame in physical
memory.

5.

The page table is updated to reflect the


mapping between the virtual address and
the newly allocated frame in physical
memory.

6.

The CPU restarts the instruction (load M)


that caused the page fault. Now, since the
required page is available in memory, the
instruction executes successfully.
PAGE
REPLACEMENT
ALGORITHM
(FIFO AND OPTIMAL
REPLACEMENT
ALGORITHM)
PAGE REPLACEMENT
ALGORITHM
Page replacement algorithms are techniques used in operating systems to
manage memory efficiently when the virtual memory is full. When a new page
needs to be loaded into physical memory , and there is no free space, these
algorithms determine which existing page to replace.

If no page frame is free, the virtual memory manager performs a page replacement
operation to replace one of the pages existing in memory with the page whose
reference caused the page fault.

There are three types of Page Replacement Algorithms.


They are:
• Optimal Page Replacement Algorithm
• First In First Out Page Replacement Algorithm
• Least Recently Used (LRU) Page Replacement Algorithm
FIRST IN FIRST OUT REPLACEMENT ALGORITHM

• This is the simplest page replacement algorithm


• In this algorithm,operating system keeps track of all pages in the memory in a queue,oldest page
is in the front of the queue.
• When a page needs to be replaced, page in the front of the queue is selected for removal.
Example:
Consider the page references 7, 0, 1, 2, 0, 3, 0, 4, 2, 3, 0, 3, 2, 3 with 4 page
frame. and calculate number of page faults by using FIFO (First In First Out) Page replacement
algorithms.
Points to Remember
Page Not Found - - - > Page Fault
Page Found - - - > Page Hit
7 0 1 2 0 3 0 4 2 3 0 3 2 3

2 2 2 2 2 2 2 2 2 2 2
1 1 1 1 1 1 1 1 0 0 0 0
0 0 0 0 0 0 4 4 4 4 4 4 4
7 7 7 7 7 3 3 3 3 3 3 3 3 3

M M M M H M H M H H M H H H

Total page faults: 8

Percentage of total page fault: (8/14)*100=57%


OPTIMAL PAGE REPLACEMENT ALGORITHM

• In this algorithm,pages are replaced which are not used for the longest duration of time in the
future.
• This algorithms replaces the page which will not be referred for so long in future.
• This algorithm cannot be implemented in a general purpose operating system because it is
impossible to compute reliably how long it will be before a page is going to be used.
Example: Consider the page references 7, 0, 1, 2, 0, 3, 0, 4, 2, 3, 0, 3, 2, 3 with 4 page frame.
Find number of page fault using Optimal Page Replacement Algorithm

Points to Remember
Page Not Found - - - > Page Fault
Page Found - - - > Page Hit

Percentage of total page fault: (6/14)*100= 43%


PAGE REPLACEMENT
ALGORITHMS & LRU

CHOOSING THE RIGHT


ALGORITHM
INTRODUCTION

1. What is LRU?
• Replaces the Least Recently Used page when a new page is
needed.
• Tracks page usage: the page that hasn't been used for the longest
time is replaced

2. How LRU Works?


• Keeps track of recent accesses and updates the order of pages.
• When a page fault occurs and memory is full, the Least Recently
Used page is identified and replaced with the new page.
ADVANTANGES AND DISADVANTAGES OF LRU

1. Advantages:
• It performs well when recently used pages are likely to be
used again.
• LRU works well in most cases, close to the optimal page
replacement strategy.

2. Disadvantages:
• Requires extra space to track access history.
• Can be more complex to implement compared to simpler
algorithms like FIFO (First In First Out).
THANK YOU

You might also like