SlideShare a Scribd company logo
What is Demand Paging?
Main memory Secondary Memory
Processl
A
B
C
D
E
Process 2
1-___ F _ _
f_ G
~ H
r I
I
Swap IN
Swap Out
A
B
C
D
E
F
G
H
I
J
IGuru99.com I
K
L
M
N
0
p_
Q'
'>,;,
R
s1
Ti
lJ'
V
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
FlFO (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 FlFO 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 itwork?
• 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 ofVirtual
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 memor .
• 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 ofVirtual
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.
How does demand paging work?
When the request comes from the CPU for accessing any
page, the page table Is referred to find where that page
Is in the main memory. Suppose that page Is found In the
main memory, then well and good. If not found then page
fault occurs. So page fault Is a situation In which the
page CPU wants to access ls not In the main memory. What
to do In that case? In that case, that particular page Is
brought(swapped) In. But from where It ls swapped In? The
answer Is secondary memory. Swapped-In means removing a
program from a hard disk and putting It back Into the
main memory or RAM. But If the page Is there Is main
memory, It Is fetched from It. Else pages are loaded from
secondary memory. Swapping Is also done In that case. We
also have valid and Invalid bits. A valid-Invalid bit Is
associated with each page table entry. So when the CPU
tries to find the page in the main memory, it first checks
the valid-Invalid bit corresponding to that page.
1. Valid bits-It Is sometimes denoted by v.lf the bit Is
valid, then the page is both legal and in memory.
2. Invalid bits-'!' denotes an invalid bit. If the bit is
invalid, then that means the page Is either not valid
or the page Is valid but Is currently not on the disk.
Let's understand with an example.
1
2
3
4
5
6
7
8
9
10
11
Frame
~
M
I
p
Physical memory
Valid-Invalid bit
I
5 V
I
I
I
4 V
i
I
7 V
Page table
Steps of demand paging
2
3
4
5
6
7
8
I
J
K
L
M
N
0
p
Logical memory
Whenever a request for any page comes, the page table Is
consulted first. There are some frames which have Invalid
bit means either they are not In the main memory then-
1. In case of a page fault, an interrupt Is generated.
2. After Interrupting the current process, the operating
system blocks the process and moves to the blocked
state.
3. The requested process is searched in the secondary
memory.
4. Check for the free frame, but if do not find any free
frame, then page replacement algorithms are followed.
5. The page is replaced(from secondary memory to main
memory) with the help of the page replacement
algorithms.
6. The CPU is informed about that update. And asked
to go ahead with the execution, and the process
returns to its ready state. The page table is
updated accordingly.
Whenever any page is referred for the first time in
the main memory. then that page will be found in
the secondary memory.
After that. it may or may not be present in the
main memory depending upon the page replacement
algorithm which will be covered later in this tutorial.
What Is a Page Fault?
If the referred page is not present in the main
memory then there will be a miss and the concept
is called Page miss or page fault.
The CPU has to access the missed page from the
secondary memory. If the number of page fault is
very high then the effective access time of the
system wi11 become very high.
What is Thrashing?
If the number of page faults is equal to the
number of referred pages or the number of page
faults are so high so that the CPU remains busy in
just reading the pages from the secondary memory
then the effective access time will be the time
taken by the CPU to read one word from the
secondary memory and it will be so high. The
concept is called thrashing.
If the page fault rate is PF %, the time taken in
getting a page from the secondary memory and
again restarting is S (service time) and the memory
access time is ma then the effective access time
can be given as;
Performance
Demand Paging
of
Demand paging can significantly affect the
performance of a computer system. To see why,
let's compute the effective access time for a
demand-paged memory.
For most computer systems, the memory-access
time, denoted ma, ranges from 10 to 200
nanoseconds.
As long as we have no page faults, the effective
access time is equal to the memory access time. If
however a page fault occurs, we must first read
the relevant page from disk and then access the
desired word.
Let p be the probability of a page fault. We would
expect p to be close to zero-that is, we would
expect to have only a few page faults. The effective
access time is then
Effective Access Time= (1- p) *ma+ p * page
fault time.
•
A
Effective Access Time= (1 - p) * ma + p * page
fault time.
To compute the effective access time, we must
know how much time is needed to service a page
fault.

More Related Content

PDF
Virtual Memory.pdf
PPTX
operating system virtual memory and logical memory
PPT
Operating System
PPTX
Virtual Memory Management
PPTX
CHAPTER 2 - Operating systems Virtual Memory.pptx
PDF
Virtual Memory Management Part - I.pdf
PPTX
Virtual Memory in Operating System
Virtual Memory.pdf
operating system virtual memory and logical memory
Operating System
Virtual Memory Management
CHAPTER 2 - Operating systems Virtual Memory.pptx
Virtual Memory Management Part - I.pdf
Virtual Memory in Operating System

Similar to Adobe Scan 06-Jan-2023.pdf demand paging document (20)

PPT
Ch10 OS
 
PPT
DOCX
virtual memory
PPTX
Demand paging
PPT
Mca ii os u-4 memory management
PPT
Chapter 9 - Virtual Memory
PPTX
Os unit 2
PPT
Virtual memory Chapter 9 simple and easy
PDF
CH09.pdf
PPTX
Virtual Memory
PPTX
Computer architecture virtual memory
PPTX
Abhaycavirtual memory and the pagehit.pptx
PPTX
coafinal1-copy-150430204758-conversion-gate01.pptx
PPT
Chapter 04
PDF
381 ccs chapter7_updated(1)
PDF
Unit 5
PPTX
operating system notes about virtual memory 4.pptx
PPT
NOV11 virtual memory.ppt
PPT
Chapter 09 - Virtual Memory.ppt
Ch10 OS
 
virtual memory
Demand paging
Mca ii os u-4 memory management
Chapter 9 - Virtual Memory
Os unit 2
Virtual memory Chapter 9 simple and easy
CH09.pdf
Virtual Memory
Computer architecture virtual memory
Abhaycavirtual memory and the pagehit.pptx
coafinal1-copy-150430204758-conversion-gate01.pptx
Chapter 04
381 ccs chapter7_updated(1)
Unit 5
operating system notes about virtual memory 4.pptx
NOV11 virtual memory.ppt
Chapter 09 - Virtual Memory.ppt
Ad

Recently uploaded (20)

PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PPTX
Cell Types and Its function , kingdom of life
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PPTX
master seminar digital applications in india
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PDF
Anesthesia in Laparoscopic Surgery in India
PDF
O7-L3 Supply Chain Operations - ICLT Program
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PPTX
Pharma ospi slides which help in ospi learning
PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PDF
Basic Mud Logging Guide for educational purpose
PPTX
The Healthy Child – Unit II | Child Health Nursing I | B.Sc Nursing 5th Semester
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PDF
TR - Agricultural Crops Production NC III.pdf
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
Supply Chain Operations Speaking Notes -ICLT Program
Cell Types and Its function , kingdom of life
Renaissance Architecture: A Journey from Faith to Humanism
master seminar digital applications in india
Microbial diseases, their pathogenesis and prophylaxis
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
Module 4: Burden of Disease Tutorial Slides S2 2025
Anesthesia in Laparoscopic Surgery in India
O7-L3 Supply Chain Operations - ICLT Program
102 student loan defaulters named and shamed – Is someone you know on the list?
Pharma ospi slides which help in ospi learning
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
Basic Mud Logging Guide for educational purpose
The Healthy Child – Unit II | Child Health Nursing I | B.Sc Nursing 5th Semester
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
human mycosis Human fungal infections are called human mycosis..pptx
TR - Agricultural Crops Production NC III.pdf
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
Ad

Adobe Scan 06-Jan-2023.pdf demand paging document

  • 1. What is Demand Paging? Main memory Secondary Memory Processl A B C D E Process 2 1-___ F _ _ f_ G ~ H r I I Swap IN Swap Out A B C D E F G H I J IGuru99.com I K L M N 0 p_ Q' '>,;, R s1 Ti lJ' V 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.
  • 2. 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 FlFO (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
  • 3. 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 FlFO 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.
  • 4. • 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.
  • 5. How does itwork? • 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.
  • 6. 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 ofVirtual 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 memor .
  • 7. • 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 ofVirtual Memory
  • 8. • 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.
  • 9. How does demand paging work? When the request comes from the CPU for accessing any page, the page table Is referred to find where that page Is in the main memory. Suppose that page Is found In the main memory, then well and good. If not found then page fault occurs. So page fault Is a situation In which the page CPU wants to access ls not In the main memory. What to do In that case? In that case, that particular page Is brought(swapped) In. But from where It ls swapped In? The answer Is secondary memory. Swapped-In means removing a program from a hard disk and putting It back Into the main memory or RAM. But If the page Is there Is main memory, It Is fetched from It. Else pages are loaded from secondary memory. Swapping Is also done In that case. We also have valid and Invalid bits. A valid-Invalid bit Is associated with each page table entry. So when the CPU tries to find the page in the main memory, it first checks the valid-Invalid bit corresponding to that page. 1. Valid bits-It Is sometimes denoted by v.lf the bit Is valid, then the page is both legal and in memory. 2. Invalid bits-'!' denotes an invalid bit. If the bit is invalid, then that means the page Is either not valid or the page Is valid but Is currently not on the disk.
  • 10. Let's understand with an example. 1 2 3 4 5 6 7 8 9 10 11 Frame ~ M I p Physical memory Valid-Invalid bit I 5 V I I I 4 V i I 7 V Page table Steps of demand paging 2 3 4 5 6 7 8 I J K L M N 0 p Logical memory Whenever a request for any page comes, the page table Is consulted first. There are some frames which have Invalid bit means either they are not In the main memory then- 1. In case of a page fault, an interrupt Is generated. 2. After Interrupting the current process, the operating system blocks the process and moves to the blocked state. 3. The requested process is searched in the secondary memory. 4. Check for the free frame, but if do not find any free frame, then page replacement algorithms are followed. 5. The page is replaced(from secondary memory to main memory) with the help of the page replacement algorithms. 6. The CPU is informed about that update. And asked to go ahead with the execution, and the process returns to its ready state. The page table is updated accordingly.
  • 11. Whenever any page is referred for the first time in the main memory. then that page will be found in the secondary memory. After that. it may or may not be present in the main memory depending upon the page replacement algorithm which will be covered later in this tutorial. What Is a Page Fault? If the referred page is not present in the main memory then there will be a miss and the concept is called Page miss or page fault. The CPU has to access the missed page from the secondary memory. If the number of page fault is very high then the effective access time of the system wi11 become very high.
  • 12. What is Thrashing? If the number of page faults is equal to the number of referred pages or the number of page faults are so high so that the CPU remains busy in just reading the pages from the secondary memory then the effective access time will be the time taken by the CPU to read one word from the secondary memory and it will be so high. The concept is called thrashing. If the page fault rate is PF %, the time taken in getting a page from the secondary memory and again restarting is S (service time) and the memory access time is ma then the effective access time can be given as;
  • 13. Performance Demand Paging of Demand paging can significantly affect the performance of a computer system. To see why, let's compute the effective access time for a demand-paged memory. For most computer systems, the memory-access time, denoted ma, ranges from 10 to 200 nanoseconds. As long as we have no page faults, the effective access time is equal to the memory access time. If however a page fault occurs, we must first read the relevant page from disk and then access the desired word. Let p be the probability of a page fault. We would expect p to be close to zero-that is, we would expect to have only a few page faults. The effective access time is then Effective Access Time= (1- p) *ma+ p * page fault time. • A
  • 14. Effective Access Time= (1 - p) * ma + p * page fault time. To compute the effective access time, we must know how much time is needed to service a page fault.