SlideShare a Scribd company logo
2
Most read
12
Most read
17
Most read
Operating System 37
Demand Paging
Prof Neeraj Bhargava
Vaibhav Khanna
Department of Computer Science
School of Engineering and Systems Sciences
Maharshi Dayanand Saraswati University Ajmer
Demand Paging
• Could bring entire process into memory at
load time
• Or bring a page into memory only when it is
needed
– Less I/O needed, no unnecessary I/O
– Less memory needed
– Faster response
– More users
• Similar to paging system with swapping
(diagram on right)
• Page is needed  reference to it
– invalid reference  abort
– not-in-memory  bring to memory
• Lazy swapper – never swaps a page into
memory unless page will be needed
– Swapper that deals with pages is a
pager
Demand Paging
• With swapping, pager guesses which pages will be
used before swapping out again
• Instead, pager brings in only those pages into memory
• How to determine that set of pages?
– Need new MMU functionality to implement demand
paging
• If pages needed are already memory resident
– No difference from non demand-paging
• If page needed and not memory resident
– Need to detect and load the page into memory from
storage
• Without changing program behavior
• Without programmer needing to change code
Basic Concepts of Demand Paging
• A demand-paging system is similar to a paging system, discussed
earlier, with a little difference that it uses - swapping.
• Processes reside on secondary memory (which is usually a disk).
• When we want to execute a process, we swap it into memory.
• Rather than swapping the entire process into memory, however, we
use a lazy swapper, which swaps a page into memory only when
that page is needed.
• Since we are now viewing a process as a sequence of pages, rather
than one large contiguous address space, the use of the term swap
will not technically correct.
• A swapper manipulates entire processes, whereas a pager is
concerned with the individual pages of a process.
• We shall thus use the term pager, rather than swapper, in
connection with demand paging.
Basic Concepts of Demand Paging
• When a process is to be swapped in, the pager
guesses which pages will be used before the
process in swapped out again.
• Instead of swapping in a whole process, the pager
brings only those necessary pages into memory.
• Thus, it avoids reading into memory pages that
will not be used anyway, decreasing the swap
time and the amount of physical memory
needed.
Basic Concepts of Demand Paging
• With this scheme, we need some form of hardware
support to distinguish between those pages that are in
memory and those pages that are on the disk.
• The valid-invalid bit scheme described earlier can be
used for this purpose.
• This time, however, when this bit is set to “valid”, this
value indicates that the associated page is both legal
and in memory.
• If the bit is set to “invalid,” this value indicates that the
page either is not valid (that is, not in the logical
address space of the process), or is valid but is
currently on the disk not in the memory.
Basic Concepts of Demand Paging
• The page-table entry for a page that is not currently in
memory is simply marked invalid, or contains the
address of the page on disk.
• Notice that marking a page invalid will have no effect if
the process never attempts to access that page.
• Hence, if we guess right and only those pages that are
actually needed are brought into the memory, the
process will run exactly as though we had brought in all
pages.
• While the process executes and accesses pages that are
memory resident, execution proceeds normally.
Valid-Invalid Bit
• With each page table entry a valid–invalid bit is
associated
(v  in-memory – memory resident, i  not-in-
memory)
• Initially valid–invalid bit is set to i on all entries
• Example of a page table snapshot:
• During MMU address translation, if valid–invalid
bit in page table entry is i  page fault
Page Table When Some Pages Are Not in Main Memory
Page Fault
• If there is a reference to a page, first reference to
that page will trap to operating system:
page fault
1. Operating system looks at another table to decide:
– Invalid reference  abort
– Just not in memory
2. Find free frame
3. Swap page into frame via scheduled disk operation
4. Reset tables to indicate page now in memory
Set validation bit = v
5. Restart the instruction that caused the page fault
Steps in Handling a Page Fault
Steps in Handling a Page Fault
• 1. We check an internal table (usually kept with the process control
block) for the process under consideration, to determine whether the
reference was a valid or invalid memory access.
• 2. If the reference was invalid, we terminate the process. If it was valid,
but we have not yet brought in that page into memory, we now page in
the latter.
• 3. We find a free frame (by taking one from the free-frame list, for
example).
• 4. We schedule a disk operation to read the desired page into the
newly allocated frame.
• 5. When the disk read is complete, we modify the internal table kept
with the process and the page table to indicate that the page is now in
memory.
• 6. We restart the instruction that was interrupted by the illegal address
trap. The process can now access the page as though it had always been in
memory.
Handling Page Fault
• It is important to realize that, because we save the state (registers,
condition code, instruction counter) of the interrupted process
when the page fault occurs, we can restart the process in exactly
the same place and state, except that the desired page is now in
memory and is accessible.
• In this way, we are able to execute a process, even though portions
of it are not (yet) in memory.
• When the process tries to access locations that are not in memory,
the hardware traps to the operating system (page fault).
• The operating system reads the desired page into memory and
restarts the process as though the page had always been in
memory.
Aspects of Demand Paging
• Extreme case – start process with no pages in memory
– OS sets instruction pointer to first instruction of process,
non-memory-resident -> page fault
– And for every other process pages on first access
– Pure demand paging
• Actually, a given instruction could access multiple pages
-> multiple page faults
– Consider fetch and decode of instruction which adds 2
numbers from memory and stores result back to memory
– Pain decreased because of locality of reference
• Hardware support needed for demand paging
– Page table with valid / invalid bit
– Secondary memory (swap device with swap space)
– Instruction restart
Instruction Restart
• Consider an instruction that could access
several different locations
– block move
– auto increment/decrement location
– Restart the whole operation?
• What if source and destination overlap?
Performance of Demand Paging
• Stages in Demand Paging (worse case)
1. Trap to the operating system
2. Save the user registers and process state
3. Determine that the interrupt was a page fault
4. Check that the page reference was legal and determine the location of the page on the disk
5. Issue a read from the disk to a free frame:
1. Wait in a queue for this device until the read request is serviced
2. Wait for the device seek and/or latency time
3. Begin the transfer of the page to a free frame
6. While waiting, allocate the CPU to some other user
7. Receive an interrupt from the disk I/O subsystem (I/O completed)
8. Save the registers and process state for the other user
9. Determine that the interrupt was from the disk
10. Correct the page table and other tables to show page is now in memory
11. Wait for the CPU to be allocated to this process again
12. Restore the user registers, process state, and new page table, and then resume the interrupted
instruction
Performance of Demand Paging
(Cont.)
• Three major activities
– Service the interrupt – careful coding means just several hundred
instructions needed
– Read the page – lots of time
– Restart the process – again just a small amount of time
• Page Fault Rate 0  p  1
– if p = 0 no page faults
– if p = 1, every reference is a fault
• Effective Access Time (EAT)
EAT = (1 – p) x memory access
+ p (page fault overhead
+ swap page out
+ swap page in )
Assignment
• Explain the concept and usage of Demand
Paging
• Explain the Steps in Handling a Page Fault

More Related Content

PPTX
Demand paging
PPTX
Page replacement algorithms
PPT
Thrashing allocation frames.43
PPTX
Context switching
PPT
Disk scheduling
PPTX
Virtual memory management in Operating System
PPTX
SCHEDULING ALGORITHMS
PDF
Process scheduling (CPU Scheduling)
Demand paging
Page replacement algorithms
Thrashing allocation frames.43
Context switching
Disk scheduling
Virtual memory management in Operating System
SCHEDULING ALGORITHMS
Process scheduling (CPU Scheduling)

What's hot (20)

PPT
Paging.ppt
PPTX
contiguous memory allocation.pptx
PPTX
Computer architecture virtual memory
PPT
Memory management
PPS
Virtual memory
PPTX
Operating system memory management
PPTX
Computer architecture page replacement algorithms
PPT
Deadlock
PPTX
Computer architecture memory system
PPTX
Disk structure
PPTX
Virtual Memory
PPTX
Memory Management in OS
PPTX
Auxiliary memory
PPT
Parallel processing
PPT
Parallel processing and pipelining
PPTX
Allocation of Frames & Thrashing
PPTX
Page replacement algorithms
PPTX
Process synchronization
PPTX
General register organization (computer organization)
Paging.ppt
contiguous memory allocation.pptx
Computer architecture virtual memory
Memory management
Virtual memory
Operating system memory management
Computer architecture page replacement algorithms
Deadlock
Computer architecture memory system
Disk structure
Virtual Memory
Memory Management in OS
Auxiliary memory
Parallel processing
Parallel processing and pipelining
Allocation of Frames & Thrashing
Page replacement algorithms
Process synchronization
General register organization (computer organization)
Ad

Similar to Operating system 37 demand paging (20)

PDF
Virtual Memory Management Part - I.pdf
PDF
Virtual Memory.pdf
PPTX
16. PagingImplementIssused.pptx
PDF
Adobe Scan 06-Jan-2023.pdf demand paging document
PPT
Virtual memory Chapter 9 simple and easy
PPTX
operating system virtual memory and logical memory
PPTX
Virtual Memory Managementddddddddffffffffffffff.pptx
PDF
Virtual memory
PDF
Virtual Memory Management Part - II.pdf
PPTX
Virtual Memory Management
PPT
08 virtual memory
PPTX
Lecture 8- Virtual Memory Final.pptx
PPT
Mca ii os u-4 memory management
PPT
virtual memory
PPT
page replacement algorithm powerpoint presentation
DOCX
Virtual memory
PDF
CH09.pdf
PPTX
Operating system 38 page replacement
PPTX
Lect 27 28_29_30_virtual_memory
Virtual Memory Management Part - I.pdf
Virtual Memory.pdf
16. PagingImplementIssused.pptx
Adobe Scan 06-Jan-2023.pdf demand paging document
Virtual memory Chapter 9 simple and easy
operating system virtual memory and logical memory
Virtual Memory Managementddddddddffffffffffffff.pptx
Virtual memory
Virtual Memory Management Part - II.pdf
Virtual Memory Management
08 virtual memory
Lecture 8- Virtual Memory Final.pptx
Mca ii os u-4 memory management
virtual memory
page replacement algorithm powerpoint presentation
Virtual memory
CH09.pdf
Operating system 38 page replacement
Lect 27 28_29_30_virtual_memory
Ad

More from Vaibhav Khanna (20)

PPTX
Information and network security 47 authentication applications
PPTX
Information and network security 46 digital signature algorithm
PPTX
Information and network security 45 digital signature standard
PPTX
Information and network security 44 direct digital signatures
PPTX
Information and network security 43 digital signatures
PPTX
Information and network security 42 security of message authentication code
PPTX
Information and network security 41 message authentication code
PPTX
Information and network security 40 sha3 secure hash algorithm
PPTX
Information and network security 39 secure hash algorithm
PPTX
Information and network security 38 birthday attacks and security of hash fun...
PPTX
Information and network security 37 hash functions and message authentication
PPTX
Information and network security 35 the chinese remainder theorem
PPTX
Information and network security 34 primality
PPTX
Information and network security 33 rsa algorithm
PPTX
Information and network security 32 principles of public key cryptosystems
PPTX
Information and network security 31 public key cryptography
PPTX
Information and network security 30 random numbers
PPTX
Information and network security 29 international data encryption algorithm
PPTX
Information and network security 28 blowfish
PPTX
Information and network security 27 triple des
Information and network security 47 authentication applications
Information and network security 46 digital signature algorithm
Information and network security 45 digital signature standard
Information and network security 44 direct digital signatures
Information and network security 43 digital signatures
Information and network security 42 security of message authentication code
Information and network security 41 message authentication code
Information and network security 40 sha3 secure hash algorithm
Information and network security 39 secure hash algorithm
Information and network security 38 birthday attacks and security of hash fun...
Information and network security 37 hash functions and message authentication
Information and network security 35 the chinese remainder theorem
Information and network security 34 primality
Information and network security 33 rsa algorithm
Information and network security 32 principles of public key cryptosystems
Information and network security 31 public key cryptography
Information and network security 30 random numbers
Information and network security 29 international data encryption algorithm
Information and network security 28 blowfish
Information and network security 27 triple des

Recently uploaded (20)

PPT
Introduction Database Management System for Course Database
PPTX
Operating system designcfffgfgggggggvggggggggg
PPTX
ManageIQ - Sprint 268 Review - Slide Deck
PDF
System and Network Administration Chapter 2
PDF
2025 Textile ERP Trends: SAP, Odoo & Oracle
PDF
medical staffing services at VALiNTRY
PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
PDF
Nekopoi APK 2025 free lastest update
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PDF
Understanding Forklifts - TECH EHS Solution
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PDF
System and Network Administraation Chapter 3
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PPTX
ai tools demonstartion for schools and inter college
PDF
How Creative Agencies Leverage Project Management Software.pdf
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PDF
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
PDF
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
Introduction Database Management System for Course Database
Operating system designcfffgfgggggggvggggggggg
ManageIQ - Sprint 268 Review - Slide Deck
System and Network Administration Chapter 2
2025 Textile ERP Trends: SAP, Odoo & Oracle
medical staffing services at VALiNTRY
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
Nekopoi APK 2025 free lastest update
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
Understanding Forklifts - TECH EHS Solution
Upgrade and Innovation Strategies for SAP ERP Customers
System and Network Administraation Chapter 3
Adobe Illustrator 28.6 Crack My Vision of Vector Design
ai tools demonstartion for schools and inter college
How Creative Agencies Leverage Project Management Software.pdf
How to Choose the Right IT Partner for Your Business in Malaysia
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...

Operating system 37 demand paging

  • 1. Operating System 37 Demand Paging Prof Neeraj Bhargava Vaibhav Khanna Department of Computer Science School of Engineering and Systems Sciences Maharshi Dayanand Saraswati University Ajmer
  • 2. Demand Paging • Could bring entire process into memory at load time • Or bring a page into memory only when it is needed – Less I/O needed, no unnecessary I/O – Less memory needed – Faster response – More users • Similar to paging system with swapping (diagram on right) • Page is needed  reference to it – invalid reference  abort – not-in-memory  bring to memory • Lazy swapper – never swaps a page into memory unless page will be needed – Swapper that deals with pages is a pager
  • 3. Demand Paging • With swapping, pager guesses which pages will be used before swapping out again • Instead, pager brings in only those pages into memory • How to determine that set of pages? – Need new MMU functionality to implement demand paging • If pages needed are already memory resident – No difference from non demand-paging • If page needed and not memory resident – Need to detect and load the page into memory from storage • Without changing program behavior • Without programmer needing to change code
  • 4. Basic Concepts of Demand Paging • A demand-paging system is similar to a paging system, discussed earlier, with a little difference that it uses - swapping. • Processes reside on secondary memory (which is usually a disk). • When we want to execute a process, we swap it into memory. • Rather than swapping the entire process into memory, however, we use a lazy swapper, which swaps a page into memory only when that page is needed. • Since we are now viewing a process as a sequence of pages, rather than one large contiguous address space, the use of the term swap will not technically correct. • A swapper manipulates entire processes, whereas a pager is concerned with the individual pages of a process. • We shall thus use the term pager, rather than swapper, in connection with demand paging.
  • 5. Basic Concepts of Demand Paging • When a process is to be swapped in, the pager guesses which pages will be used before the process in swapped out again. • Instead of swapping in a whole process, the pager brings only those necessary pages into memory. • Thus, it avoids reading into memory pages that will not be used anyway, decreasing the swap time and the amount of physical memory needed.
  • 6. Basic Concepts of Demand Paging • With this scheme, we need some form of hardware support to distinguish between those pages that are in memory and those pages that are on the disk. • The valid-invalid bit scheme described earlier can be used for this purpose. • This time, however, when this bit is set to “valid”, this value indicates that the associated page is both legal and in memory. • If the bit is set to “invalid,” this value indicates that the page either is not valid (that is, not in the logical address space of the process), or is valid but is currently on the disk not in the memory.
  • 7. Basic Concepts of Demand Paging • The page-table entry for a page that is not currently in memory is simply marked invalid, or contains the address of the page on disk. • Notice that marking a page invalid will have no effect if the process never attempts to access that page. • Hence, if we guess right and only those pages that are actually needed are brought into the memory, the process will run exactly as though we had brought in all pages. • While the process executes and accesses pages that are memory resident, execution proceeds normally.
  • 8. Valid-Invalid Bit • With each page table entry a valid–invalid bit is associated (v  in-memory – memory resident, i  not-in- memory) • Initially valid–invalid bit is set to i on all entries • Example of a page table snapshot: • During MMU address translation, if valid–invalid bit in page table entry is i  page fault
  • 9. Page Table When Some Pages Are Not in Main Memory
  • 10. Page Fault • If there is a reference to a page, first reference to that page will trap to operating system: page fault 1. Operating system looks at another table to decide: – Invalid reference  abort – Just not in memory 2. Find free frame 3. Swap page into frame via scheduled disk operation 4. Reset tables to indicate page now in memory Set validation bit = v 5. Restart the instruction that caused the page fault
  • 11. Steps in Handling a Page Fault
  • 12. Steps in Handling a Page Fault • 1. We check an internal table (usually kept with the process control block) for the process under consideration, to determine whether the reference was a valid or invalid memory access. • 2. If the reference was invalid, we terminate the process. If it was valid, but we have not yet brought in that page into memory, we now page in the latter. • 3. We find a free frame (by taking one from the free-frame list, for example). • 4. We schedule a disk operation to read the desired page into the newly allocated frame. • 5. When the disk read is complete, we modify the internal table kept with the process and the page table to indicate that the page is now in memory. • 6. We restart the instruction that was interrupted by the illegal address trap. The process can now access the page as though it had always been in memory.
  • 13. Handling Page Fault • It is important to realize that, because we save the state (registers, condition code, instruction counter) of the interrupted process when the page fault occurs, we can restart the process in exactly the same place and state, except that the desired page is now in memory and is accessible. • In this way, we are able to execute a process, even though portions of it are not (yet) in memory. • When the process tries to access locations that are not in memory, the hardware traps to the operating system (page fault). • The operating system reads the desired page into memory and restarts the process as though the page had always been in memory.
  • 14. Aspects of Demand Paging • Extreme case – start process with no pages in memory – OS sets instruction pointer to first instruction of process, non-memory-resident -> page fault – And for every other process pages on first access – Pure demand paging • Actually, a given instruction could access multiple pages -> multiple page faults – Consider fetch and decode of instruction which adds 2 numbers from memory and stores result back to memory – Pain decreased because of locality of reference • Hardware support needed for demand paging – Page table with valid / invalid bit – Secondary memory (swap device with swap space) – Instruction restart
  • 15. Instruction Restart • Consider an instruction that could access several different locations – block move – auto increment/decrement location – Restart the whole operation? • What if source and destination overlap?
  • 16. Performance of Demand Paging • Stages in Demand Paging (worse case) 1. Trap to the operating system 2. Save the user registers and process state 3. Determine that the interrupt was a page fault 4. Check that the page reference was legal and determine the location of the page on the disk 5. Issue a read from the disk to a free frame: 1. Wait in a queue for this device until the read request is serviced 2. Wait for the device seek and/or latency time 3. Begin the transfer of the page to a free frame 6. While waiting, allocate the CPU to some other user 7. Receive an interrupt from the disk I/O subsystem (I/O completed) 8. Save the registers and process state for the other user 9. Determine that the interrupt was from the disk 10. Correct the page table and other tables to show page is now in memory 11. Wait for the CPU to be allocated to this process again 12. Restore the user registers, process state, and new page table, and then resume the interrupted instruction
  • 17. Performance of Demand Paging (Cont.) • Three major activities – Service the interrupt – careful coding means just several hundred instructions needed – Read the page – lots of time – Restart the process – again just a small amount of time • Page Fault Rate 0  p  1 – if p = 0 no page faults – if p = 1, every reference is a fault • Effective Access Time (EAT) EAT = (1 – p) x memory access + p (page fault overhead + swap page out + swap page in )
  • 18. Assignment • Explain the concept and usage of Demand Paging • Explain the Steps in Handling a Page Fault