SlideShare a Scribd company logo
1 of 18
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

What's hot

Operating system paging and segmentation
Operating system paging and segmentationOperating system paging and segmentation
Operating system paging and segmentationhamza haseeb
 
Segmentation in Operating Systems.
Segmentation in Operating Systems.Segmentation in Operating Systems.
Segmentation in Operating Systems.Muhammad SiRaj Munir
 
Page replacement algorithms
Page replacement algorithmsPage replacement algorithms
Page replacement algorithmsPiyush Rochwani
 
Structure of the page table
Structure of the page tableStructure of the page table
Structure of the page tableduvvuru madhuri
 
Memory management ppt
Memory management pptMemory management ppt
Memory management pptManishaJha43
 
Presentation on Segmentation
Presentation on SegmentationPresentation on Segmentation
Presentation on SegmentationPriyanka bisht
 
Virtual Memory
Virtual MemoryVirtual Memory
Virtual MemoryArchith777
 
Disk scheduling algorithms
Disk scheduling algorithms Disk scheduling algorithms
Disk scheduling algorithms Paresh Parmar
 
Thrashing allocation frames.43
Thrashing allocation frames.43Thrashing allocation frames.43
Thrashing allocation frames.43myrajendra
 
Memory management
Memory managementMemory management
Memory managementImran Khan
 
Os Swapping, Paging, Segmentation and Virtual Memory
Os Swapping, Paging, Segmentation and Virtual MemoryOs Swapping, Paging, Segmentation and Virtual Memory
Os Swapping, Paging, Segmentation and Virtual Memorysgpraju
 

What's hot (20)

Memory management
Memory managementMemory management
Memory management
 
Virtual Memory
Virtual MemoryVirtual Memory
Virtual Memory
 
Page Replacement
Page ReplacementPage Replacement
Page Replacement
 
Paging.ppt
Paging.pptPaging.ppt
Paging.ppt
 
Operating system paging and segmentation
Operating system paging and segmentationOperating system paging and segmentation
Operating system paging and segmentation
 
Demand paging
Demand pagingDemand paging
Demand paging
 
Segmentation in Operating Systems.
Segmentation in Operating Systems.Segmentation in Operating Systems.
Segmentation in Operating Systems.
 
Virtual memory
Virtual memoryVirtual memory
Virtual memory
 
Page replacement algorithms
Page replacement algorithmsPage replacement algorithms
Page replacement algorithms
 
Structure of the page table
Structure of the page tableStructure of the page table
Structure of the page table
 
Memory management ppt
Memory management pptMemory management ppt
Memory management ppt
 
Presentation on Segmentation
Presentation on SegmentationPresentation on Segmentation
Presentation on Segmentation
 
Virtual Memory
Virtual MemoryVirtual Memory
Virtual Memory
 
Disk scheduling algorithms
Disk scheduling algorithms Disk scheduling algorithms
Disk scheduling algorithms
 
Thrashing allocation frames.43
Thrashing allocation frames.43Thrashing allocation frames.43
Thrashing allocation frames.43
 
Memory management
Memory managementMemory management
Memory management
 
Virtual memory
Virtual memoryVirtual memory
Virtual memory
 
Memory management
Memory managementMemory management
Memory management
 
Os Swapping, Paging, Segmentation and Virtual Memory
Os Swapping, Paging, Segmentation and Virtual MemoryOs Swapping, Paging, Segmentation and Virtual Memory
Os Swapping, Paging, Segmentation and Virtual Memory
 
Virtual memory
Virtual memoryVirtual memory
Virtual memory
 

Similar to Operating system 37 demand paging

Virtual Memory Management Part - I.pdf
Virtual Memory Management Part - I.pdfVirtual Memory Management Part - I.pdf
Virtual Memory Management Part - I.pdfHarika Pudugosula
 
16. PagingImplementIssused.pptx
16. PagingImplementIssused.pptx16. PagingImplementIssused.pptx
16. PagingImplementIssused.pptxMyName1sJeff
 
Virtual Memory Management Part - II.pdf
Virtual Memory Management Part - II.pdfVirtual Memory Management Part - II.pdf
Virtual Memory Management Part - II.pdfHarika Pudugosula
 
Virtual Memory Management
Virtual Memory ManagementVirtual Memory Management
Virtual Memory ManagementRahul Jamwal
 
08 virtual memory
08 virtual memory08 virtual memory
08 virtual memoryKamal Singh
 
Lecture 8- Virtual Memory Final.pptx
Lecture 8- Virtual Memory Final.pptxLecture 8- Virtual Memory Final.pptx
Lecture 8- Virtual Memory Final.pptxAmanuelmergia
 
Mca ii os u-4 memory management
Mca  ii  os u-4 memory managementMca  ii  os u-4 memory management
Mca ii os u-4 memory managementRai University
 
Computer architecture virtual memory
Computer architecture virtual memoryComputer architecture virtual memory
Computer architecture virtual memoryMazin Alwaaly
 
Operating system 38 page replacement
Operating system 38 page replacementOperating system 38 page replacement
Operating system 38 page replacementVaibhav Khanna
 
Lect 27 28_29_30_virtual_memory
Lect 27 28_29_30_virtual_memoryLect 27 28_29_30_virtual_memory
Lect 27 28_29_30_virtual_memorySoumendu Sarkar
 
Memory management
Memory managementMemory management
Memory managementRasi123
 
Virtual memory - Demand Paging
Virtual memory - Demand PagingVirtual memory - Demand Paging
Virtual memory - Demand Pagingjeyaperumal
 
Virtual memory managment
Virtual memory managmentVirtual memory managment
Virtual memory managmentSantu Kumar
 
Unit 2chapter 2 memory mgmt complete
Unit 2chapter 2  memory mgmt completeUnit 2chapter 2  memory mgmt complete
Unit 2chapter 2 memory mgmt completeKalai Selvi
 

Similar to Operating system 37 demand paging (20)

Virtual Memory Management Part - I.pdf
Virtual Memory Management Part - I.pdfVirtual Memory Management Part - I.pdf
Virtual Memory Management Part - I.pdf
 
Virtual Memory.pdf
Virtual Memory.pdfVirtual Memory.pdf
Virtual Memory.pdf
 
16. PagingImplementIssused.pptx
16. PagingImplementIssused.pptx16. PagingImplementIssused.pptx
16. PagingImplementIssused.pptx
 
Virtual Memory Management Part - II.pdf
Virtual Memory Management Part - II.pdfVirtual Memory Management Part - II.pdf
Virtual Memory Management Part - II.pdf
 
Virtual Memory Management
Virtual Memory ManagementVirtual Memory Management
Virtual Memory Management
 
08 virtual memory
08 virtual memory08 virtual memory
08 virtual memory
 
Lecture 8- Virtual Memory Final.pptx
Lecture 8- Virtual Memory Final.pptxLecture 8- Virtual Memory Final.pptx
Lecture 8- Virtual Memory Final.pptx
 
Mca ii os u-4 memory management
Mca  ii  os u-4 memory managementMca  ii  os u-4 memory management
Mca ii os u-4 memory management
 
virtual memory
virtual memoryvirtual memory
virtual memory
 
O ssvv82014
O ssvv82014O ssvv82014
O ssvv82014
 
Computer architecture virtual memory
Computer architecture virtual memoryComputer architecture virtual memory
Computer architecture virtual memory
 
Virtual memory
Virtual memoryVirtual memory
Virtual memory
 
CH09.pdf
CH09.pdfCH09.pdf
CH09.pdf
 
Operating system 38 page replacement
Operating system 38 page replacementOperating system 38 page replacement
Operating system 38 page replacement
 
Lect 27 28_29_30_virtual_memory
Lect 27 28_29_30_virtual_memoryLect 27 28_29_30_virtual_memory
Lect 27 28_29_30_virtual_memory
 
Memory management
Memory managementMemory management
Memory management
 
Virtual memory - Demand Paging
Virtual memory - Demand PagingVirtual memory - Demand Paging
Virtual memory - Demand Paging
 
Virtual memory managment
Virtual memory managmentVirtual memory managment
Virtual memory managment
 
Operating System
Operating SystemOperating System
Operating System
 
Unit 2chapter 2 memory mgmt complete
Unit 2chapter 2  memory mgmt completeUnit 2chapter 2  memory mgmt complete
Unit 2chapter 2 memory mgmt complete
 

More from Vaibhav Khanna

Information and network security 47 authentication applications
Information and network security 47 authentication applicationsInformation and network security 47 authentication applications
Information and network security 47 authentication applicationsVaibhav Khanna
 
Information and network security 46 digital signature algorithm
Information and network security 46 digital signature algorithmInformation and network security 46 digital signature algorithm
Information and network security 46 digital signature algorithmVaibhav Khanna
 
Information and network security 45 digital signature standard
Information and network security 45 digital signature standardInformation and network security 45 digital signature standard
Information and network security 45 digital signature standardVaibhav Khanna
 
Information and network security 44 direct digital signatures
Information and network security 44 direct digital signaturesInformation and network security 44 direct digital signatures
Information and network security 44 direct digital signaturesVaibhav Khanna
 
Information and network security 43 digital signatures
Information and network security 43 digital signaturesInformation and network security 43 digital signatures
Information and network security 43 digital signaturesVaibhav Khanna
 
Information and network security 42 security of message authentication code
Information and network security 42 security of message authentication codeInformation and network security 42 security of message authentication code
Information and network security 42 security of message authentication codeVaibhav Khanna
 
Information and network security 41 message authentication code
Information and network security 41 message authentication codeInformation and network security 41 message authentication code
Information and network security 41 message authentication codeVaibhav Khanna
 
Information and network security 40 sha3 secure hash algorithm
Information and network security 40 sha3 secure hash algorithmInformation and network security 40 sha3 secure hash algorithm
Information and network security 40 sha3 secure hash algorithmVaibhav Khanna
 
Information and network security 39 secure hash algorithm
Information and network security 39 secure hash algorithmInformation and network security 39 secure hash algorithm
Information and network security 39 secure hash algorithmVaibhav Khanna
 
Information and network security 38 birthday attacks and security of hash fun...
Information and network security 38 birthday attacks and security of hash fun...Information and network security 38 birthday attacks and security of hash fun...
Information and network security 38 birthday attacks and security of hash fun...Vaibhav Khanna
 
Information and network security 37 hash functions and message authentication
Information and network security 37 hash functions and message authenticationInformation and network security 37 hash functions and message authentication
Information and network security 37 hash functions and message authenticationVaibhav Khanna
 
Information and network security 35 the chinese remainder theorem
Information and network security 35 the chinese remainder theoremInformation and network security 35 the chinese remainder theorem
Information and network security 35 the chinese remainder theoremVaibhav Khanna
 
Information and network security 34 primality
Information and network security 34 primalityInformation and network security 34 primality
Information and network security 34 primalityVaibhav Khanna
 
Information and network security 33 rsa algorithm
Information and network security 33 rsa algorithmInformation and network security 33 rsa algorithm
Information and network security 33 rsa algorithmVaibhav Khanna
 
Information and network security 32 principles of public key cryptosystems
Information and network security 32 principles of public key cryptosystemsInformation and network security 32 principles of public key cryptosystems
Information and network security 32 principles of public key cryptosystemsVaibhav Khanna
 
Information and network security 31 public key cryptography
Information and network security 31 public key cryptographyInformation and network security 31 public key cryptography
Information and network security 31 public key cryptographyVaibhav Khanna
 
Information and network security 30 random numbers
Information and network security 30 random numbersInformation and network security 30 random numbers
Information and network security 30 random numbersVaibhav Khanna
 
Information and network security 29 international data encryption algorithm
Information and network security 29 international data encryption algorithmInformation and network security 29 international data encryption algorithm
Information and network security 29 international data encryption algorithmVaibhav Khanna
 
Information and network security 28 blowfish
Information and network security 28 blowfishInformation and network security 28 blowfish
Information and network security 28 blowfishVaibhav Khanna
 
Information and network security 27 triple des
Information and network security 27 triple desInformation and network security 27 triple des
Information and network security 27 triple desVaibhav Khanna
 

More from Vaibhav Khanna (20)

Information and network security 47 authentication applications
Information and network security 47 authentication applicationsInformation and network security 47 authentication applications
Information and network security 47 authentication applications
 
Information and network security 46 digital signature algorithm
Information and network security 46 digital signature algorithmInformation and network security 46 digital signature algorithm
Information and network security 46 digital signature algorithm
 
Information and network security 45 digital signature standard
Information and network security 45 digital signature standardInformation and network security 45 digital signature standard
Information and network security 45 digital signature standard
 
Information and network security 44 direct digital signatures
Information and network security 44 direct digital signaturesInformation and network security 44 direct digital signatures
Information and network security 44 direct digital signatures
 
Information and network security 43 digital signatures
Information and network security 43 digital signaturesInformation and network security 43 digital signatures
Information and network security 43 digital signatures
 
Information and network security 42 security of message authentication code
Information and network security 42 security of message authentication codeInformation and network security 42 security of message authentication code
Information and network security 42 security of message authentication code
 
Information and network security 41 message authentication code
Information and network security 41 message authentication codeInformation and network security 41 message authentication code
Information and network security 41 message authentication code
 
Information and network security 40 sha3 secure hash algorithm
Information and network security 40 sha3 secure hash algorithmInformation and network security 40 sha3 secure hash algorithm
Information and network security 40 sha3 secure hash algorithm
 
Information and network security 39 secure hash algorithm
Information and network security 39 secure hash algorithmInformation and network security 39 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 38 birthday attacks and security of hash fun...Information and network security 38 birthday attacks and security of hash fun...
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 37 hash functions and message authenticationInformation and network security 37 hash functions and message authentication
Information and network security 37 hash functions and message authentication
 
Information and network security 35 the chinese remainder theorem
Information and network security 35 the chinese remainder theoremInformation and network security 35 the chinese remainder theorem
Information and network security 35 the chinese remainder theorem
 
Information and network security 34 primality
Information and network security 34 primalityInformation and network security 34 primality
Information and network security 34 primality
 
Information and network security 33 rsa algorithm
Information and network security 33 rsa algorithmInformation and network security 33 rsa algorithm
Information and network security 33 rsa algorithm
 
Information and network security 32 principles of public key cryptosystems
Information and network security 32 principles of public key cryptosystemsInformation and network security 32 principles of public key cryptosystems
Information and network security 32 principles of public key cryptosystems
 
Information and network security 31 public key cryptography
Information and network security 31 public key cryptographyInformation and network security 31 public key cryptography
Information and network security 31 public key cryptography
 
Information and network security 30 random numbers
Information and network security 30 random numbersInformation and network security 30 random numbers
Information and network security 30 random numbers
 
Information and network security 29 international data encryption algorithm
Information and network security 29 international data encryption algorithmInformation and network security 29 international data encryption algorithm
Information and network security 29 international data encryption algorithm
 
Information and network security 28 blowfish
Information and network security 28 blowfishInformation and network security 28 blowfish
Information and network security 28 blowfish
 
Information and network security 27 triple des
Information and network security 27 triple desInformation and network security 27 triple des
Information and network security 27 triple des
 

Recently uploaded

Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataBradBedford3
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptkotipi9215
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfkalichargn70th171
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...Christina Lin
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfjoe51371421
 
Introduction to Decentralized Applications (dApps)
Introduction to Decentralized Applications (dApps)Introduction to Decentralized Applications (dApps)
Introduction to Decentralized Applications (dApps)Intelisync
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)OPEN KNOWLEDGE GmbH
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 

Recently uploaded (20)

Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.ppt
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdf
 
Introduction to Decentralized Applications (dApps)
Introduction to Decentralized Applications (dApps)Introduction to Decentralized Applications (dApps)
Introduction to Decentralized Applications (dApps)
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
Exploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the ProcessExploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the Process
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 

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