SlideShare a Scribd company logo
1 of 22
© Oxford University Press 2014. All rights reserved.
Virtual Memory
© Oxford University Press 2014. All rights reserved.
Objectives
• Need of Virtual Memory
• Virtual addresses and virtual address space
• Implementation of VM system through demand loading
• Demand paging
• Page replacement algorithms
• Thrashing and its solutions
© Oxford University Press 2014. All rights reserved.
Virtual Memory
• Virtual memory may be realized with paging or segmentation as
it requires a non-contiguous memory allocation method.
• All the basics related to these concepts apply here also in VM
system.
• The logical address here is known as virtual address and the
logical address space is called as virtual address space.
© Oxford University Press 2014. All rights reserved.
Why Virtual Memory
•Code needs to be in memory to execute, but entire program rarely used
Error code, unusual routines, large data structures
•Entire program code not needed at same time
•Consider ability to execute partially-loaded program
Program no longer constrained by limits of physical memory
Each program takes less memory while running -> more programs run at the
same time
Increased CPU utilization and throughput with no increase in response
time or turnaround time
Less I/O needed to load or swap programs into memory -> each user program
runs faster
•
© Oxford University Press 2014. All rights reserved.
Virtual Memory
Virtual memory – separation of user logical memory
from physical memory
•Only part of the program needs to be in memory for
execution
•Logical address space can therefore be much larger than
physical address space
•Allows address spaces to be shared by several processes
•Allows for more efficient process creation
•More programs running concurrently
•Less I/O needed to load or swap processes
© Oxford University Press 2014. All rights reserved.
Virtual Memory
• Virtual memory can be implemented via:
Demand paging
Demand segmentation
• The address translation using paging and segmentation are
applied in the same way as discussed in the last chapter.
• The only difference of applying paging and segmentation in
relation to virtual memory is that there is no need to load the
whole process in the form of pages or segments in the main
memory.
• VM system requires only those pages or segments of a process
in the memory which are needed at a certain time of execution.
© Oxford University Press 2014. All rights reserved.
Demand loading
© Oxford University Press 2014. All rights reserved.
Demand paging
Demand paging is to load only those pages in the memory that are
needed at an instant of time of execution.
•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
•Page is needed  reference/logical address 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
© Oxford University Press 2014. All rights reserved.
Demand paging
© Oxford University Press 2014. All rights reserved.
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
© Oxford University Press 2013. All rights reserved.
Page Table When Some Pages Are Not in Main Memory
© Oxford University Press 2014. All rights reserved.
Page and Frame Replacement Algorithms
• Frame-allocation algorithm determines
– How many frames to give each process
– Which frames to replace
• Page-replacement algorithm
– Want lowest page-fault rate on both first access and re-access
• Evaluate algorithm by running it on a particular string of memory references
(reference string) and computing the number of page faults on that string
– String is just page numbers, not full addresses
– Repeated access to the same page does not cause a page fault
– Results depend on number of frames available
• In all our examples, the reference string of referenced page numbers is
7,0,1,2,0,3,0,4,2,3,0,3,0,3,2,1,2,0,1,7,0,1
© Oxford University Press 2014. All rights reserved.
Page replacement algorithms
•A page fault occurs when a page is not found in the memory, and
needs to be loaded from the disk.
•If a page fault occurs and all memory frames have been already
allocated, then replacement of a page in memory is required on
the request of a new page. This is referred to as demand-paging.
•The choice of which page to replace is specified by a page
replacement algorithms. The commonly used page replacement
algorithms are FIFO, LRU, optimal page replacement algorithms
etc.
© Oxford University Press 2014. All rights reserved.
Page replacement algorithms
The strategy to choose a best page to be replaced in the memory is
called a page replacement algorithm.
FIFO page replacement algorithm
A page to be replaced is chosen such that it is the oldest one among
the all pages in the memory.
Optimal page replacement algorithm
A page will be replaced that will not be referenced for the longest
time.
© Oxford University Press 2014. All rights reserved.
First-In-First-Out (FIFO) Algorithm
• Reference string: 7,0,1,2,0,3,0,4,2,3,0,3,0,3,2,1,2,0,1,7,0,1
• 3 frames (3 pages can be in memory at a time per process)
• Can vary by reference string: consider 1,2,3,4,1,2,5,1,2,3,4,5
– Adding more frames can cause more page faults!
• Belady’s Anomaly
15 page faults
© Oxford University Press 2014. All rights reserved.
Belody Anamoly
• Generally, on increasing the number of frames to a process’ virtual
memory, its execution becomes faster as less number of page
faults occur. Sometimes the reverse happens, i.e. more number of
page faults occur when more frames are allocated to a process.
This most unexpected result is termed as Belady’s Anomaly.
• Bélády’s anomaly is the name given to the phenomenon where
increasing the number of page frames results in an increase in the
number of page faults for a given memory access pattern.
© Oxford University Press 2014. All rights reserved.
Optimal Page Replacement Algorithm
• Replace page that will not be used for longest period of time (Page
that is referred in last in reference string is replaced first)
• How do you know this?
– Can’t read the future
• Used for measuring how well your algorithm performs
© Oxford University Press 2014. All rights reserved.
Page replacement algorithms
Least Recently Used (LRU) page replacement algorithm
Replace a page which will not be referenced for a longest time in the
future.
•Use past knowledge rather than future
•Replace page that has not been used in the most amount of time
•Associate time of last use with each page
•
© Oxford University Press 2014. All rights reserved.
Least Recently Used (LRU) Algorithm
•12 faults – better than FIFO but worse than OPT
•Generally good algorithm and frequently used
© Oxford University Press 2014. All rights reserved.
Global 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
© Oxford University Press 2014. All rights reserved.
Thrashing
The high paging activity is known as thrashing. A process is said to be
thrashing if most of the time is being consumed in paging rather than
its actual execution.
If a process does not have “enough” pages, the page-fault rate is very
high
Page fault to get page
Replace existing frame
But quickly need replaced frame back
This leads to:
Low CPU utilization
Operating system thinking that it needs to increase the degree
of multiprogramming
Another process added to the system
© Oxford University Press 2014. All rights reserved.
Thrashing

More Related Content

Similar to Virtual Memory sjkdhikejv vsdkjnksnv vkjhfvk

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
 
Virtual Memory Management Part - I.pdf
Virtual Memory Management Part - I.pdfVirtual Memory Management Part - I.pdf
Virtual Memory Management Part - I.pdfHarika Pudugosula
 
Operating system 37 demand paging
Operating system 37 demand pagingOperating system 37 demand paging
Operating system 37 demand pagingVaibhav Khanna
 
Virtual Memory in Windows
Virtual Memory in Windows Virtual Memory in Windows
Virtual Memory in Windows HanzlaRafique
 
Comparision of page replacement algorithms.pptx
Comparision of page replacement algorithms.pptxComparision of page replacement algorithms.pptx
Comparision of page replacement algorithms.pptxSureshD94
 
Virtual Memory Management Part - II.pdf
Virtual Memory Management Part - II.pdfVirtual Memory Management Part - II.pdf
Virtual Memory Management Part - II.pdfHarika Pudugosula
 
Computer architecture virtual memory
Computer architecture virtual memoryComputer architecture virtual memory
Computer architecture virtual memoryMazin Alwaaly
 
Improving page migration분산처리
Improving page migration분산처리 Improving page migration분산처리
Improving page migration분산처리 Park Chunduck
 
virtual memory Operating system
virtual memory Operating system virtual memory Operating system
virtual memory Operating system Shaheen kousar
 
Lecture-7 Main Memroy.pptx
Lecture-7 Main Memroy.pptxLecture-7 Main Memroy.pptx
Lecture-7 Main Memroy.pptxAmanuelmergia
 
07-MemoryManagement.ppt
07-MemoryManagement.ppt07-MemoryManagement.ppt
07-MemoryManagement.ppthello509579
 
Virtual memory managment
Virtual memory managmentVirtual memory managment
Virtual memory managmentSantu Kumar
 
Virtual memory This is the operating system ppt.ppt
Virtual memory This is the operating system ppt.pptVirtual memory This is the operating system ppt.ppt
Virtual memory This is the operating system ppt.pptry54321288
 
UNIT 3-EXPLAINING THE MEMORY MANAGEMENT LOGICAL AND AND PHYSICAL DATA FLOW DI...
UNIT 3-EXPLAINING THE MEMORY MANAGEMENT LOGICAL AND AND PHYSICAL DATA FLOW DI...UNIT 3-EXPLAINING THE MEMORY MANAGEMENT LOGICAL AND AND PHYSICAL DATA FLOW DI...
UNIT 3-EXPLAINING THE MEMORY MANAGEMENT LOGICAL AND AND PHYSICAL DATA FLOW DI...LeahRachael
 

Similar to Virtual Memory sjkdhikejv vsdkjnksnv vkjhfvk (20)

08 virtual memory
08 virtual memory08 virtual memory
08 virtual memory
 
Virtual memory
Virtual memoryVirtual memory
Virtual memory
 
virtual memory
virtual memoryvirtual memory
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
 
Virtual Memory Management Part - I.pdf
Virtual Memory Management Part - I.pdfVirtual Memory Management Part - I.pdf
Virtual Memory Management Part - I.pdf
 
Operating system 37 demand paging
Operating system 37 demand pagingOperating system 37 demand paging
Operating system 37 demand paging
 
Virtual Memory in Windows
Virtual Memory in Windows Virtual Memory in Windows
Virtual Memory in Windows
 
Comparision of page replacement algorithms.pptx
Comparision of page replacement algorithms.pptxComparision of page replacement algorithms.pptx
Comparision of page replacement algorithms.pptx
 
Mem mgt
Mem mgtMem mgt
Mem mgt
 
Virtual Memory Management Part - II.pdf
Virtual Memory Management Part - II.pdfVirtual Memory Management Part - II.pdf
Virtual Memory Management Part - II.pdf
 
Computer architecture virtual memory
Computer architecture virtual memoryComputer architecture virtual memory
Computer architecture virtual memory
 
Improving page migration분산처리
Improving page migration분산처리 Improving page migration분산처리
Improving page migration분산처리
 
virtual memory Operating system
virtual memory Operating system virtual memory Operating system
virtual memory Operating system
 
Memory Management
Memory ManagementMemory Management
Memory Management
 
Lecture-7 Main Memroy.pptx
Lecture-7 Main Memroy.pptxLecture-7 Main Memroy.pptx
Lecture-7 Main Memroy.pptx
 
07-MemoryManagement.ppt
07-MemoryManagement.ppt07-MemoryManagement.ppt
07-MemoryManagement.ppt
 
Virtual memory managment
Virtual memory managmentVirtual memory managment
Virtual memory managment
 
Virtual memory This is the operating system ppt.ppt
Virtual memory This is the operating system ppt.pptVirtual memory This is the operating system ppt.ppt
Virtual memory This is the operating system ppt.ppt
 
UNIT 3-EXPLAINING THE MEMORY MANAGEMENT LOGICAL AND AND PHYSICAL DATA FLOW DI...
UNIT 3-EXPLAINING THE MEMORY MANAGEMENT LOGICAL AND AND PHYSICAL DATA FLOW DI...UNIT 3-EXPLAINING THE MEMORY MANAGEMENT LOGICAL AND AND PHYSICAL DATA FLOW DI...
UNIT 3-EXPLAINING THE MEMORY MANAGEMENT LOGICAL AND AND PHYSICAL DATA FLOW DI...
 
Os unit 3
Os unit 3Os unit 3
Os unit 3
 

More from HKShab

Unit-1 part 2.pptx
Unit-1 part 2.pptxUnit-1 part 2.pptx
Unit-1 part 2.pptxHKShab
 
Multithreadingppt.pptx
Multithreadingppt.pptxMultithreadingppt.pptx
Multithreadingppt.pptxHKShab
 
Pharmacymanagement- Harish(221348092).pptx
Pharmacymanagement- Harish(221348092).pptxPharmacymanagement- Harish(221348092).pptx
Pharmacymanagement- Harish(221348092).pptxHKShab
 
assamppt-161024172823.pptx
assamppt-161024172823.pptxassamppt-161024172823.pptx
assamppt-161024172823.pptxHKShab
 
1's and 2's complement.pptx
1's and 2's complement.pptx1's and 2's complement.pptx
1's and 2's complement.pptxHKShab
 
1sand2scomplement.pptx
1sand2scomplement.pptx1sand2scomplement.pptx
1sand2scomplement.pptxHKShab
 
hp.pptx
hp.pptxhp.pptx
hp.pptxHKShab
 
Ankit (221348051) BCA-Aiml.pptx
Ankit (221348051) BCA-Aiml.pptxAnkit (221348051) BCA-Aiml.pptx
Ankit (221348051) BCA-Aiml.pptxHKShab
 
Ram Singh (221348062) - Cloud Computing.pptx
Ram Singh (221348062) - Cloud Computing.pptxRam Singh (221348062) - Cloud Computing.pptx
Ram Singh (221348062) - Cloud Computing.pptxHKShab
 
Sahil Presentation1.pptx
Sahil Presentation1.pptxSahil Presentation1.pptx
Sahil Presentation1.pptxHKShab
 

More from HKShab (10)

Unit-1 part 2.pptx
Unit-1 part 2.pptxUnit-1 part 2.pptx
Unit-1 part 2.pptx
 
Multithreadingppt.pptx
Multithreadingppt.pptxMultithreadingppt.pptx
Multithreadingppt.pptx
 
Pharmacymanagement- Harish(221348092).pptx
Pharmacymanagement- Harish(221348092).pptxPharmacymanagement- Harish(221348092).pptx
Pharmacymanagement- Harish(221348092).pptx
 
assamppt-161024172823.pptx
assamppt-161024172823.pptxassamppt-161024172823.pptx
assamppt-161024172823.pptx
 
1's and 2's complement.pptx
1's and 2's complement.pptx1's and 2's complement.pptx
1's and 2's complement.pptx
 
1sand2scomplement.pptx
1sand2scomplement.pptx1sand2scomplement.pptx
1sand2scomplement.pptx
 
hp.pptx
hp.pptxhp.pptx
hp.pptx
 
Ankit (221348051) BCA-Aiml.pptx
Ankit (221348051) BCA-Aiml.pptxAnkit (221348051) BCA-Aiml.pptx
Ankit (221348051) BCA-Aiml.pptx
 
Ram Singh (221348062) - Cloud Computing.pptx
Ram Singh (221348062) - Cloud Computing.pptxRam Singh (221348062) - Cloud Computing.pptx
Ram Singh (221348062) - Cloud Computing.pptx
 
Sahil Presentation1.pptx
Sahil Presentation1.pptxSahil Presentation1.pptx
Sahil Presentation1.pptx
 

Recently uploaded

URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting DataJhengPantaleon
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 

Recently uploaded (20)

URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 

Virtual Memory sjkdhikejv vsdkjnksnv vkjhfvk

  • 1. © Oxford University Press 2014. All rights reserved. Virtual Memory
  • 2. © Oxford University Press 2014. All rights reserved. Objectives • Need of Virtual Memory • Virtual addresses and virtual address space • Implementation of VM system through demand loading • Demand paging • Page replacement algorithms • Thrashing and its solutions
  • 3. © Oxford University Press 2014. All rights reserved. Virtual Memory • Virtual memory may be realized with paging or segmentation as it requires a non-contiguous memory allocation method. • All the basics related to these concepts apply here also in VM system. • The logical address here is known as virtual address and the logical address space is called as virtual address space.
  • 4. © Oxford University Press 2014. All rights reserved. Why Virtual Memory •Code needs to be in memory to execute, but entire program rarely used Error code, unusual routines, large data structures •Entire program code not needed at same time •Consider ability to execute partially-loaded program Program no longer constrained by limits of physical memory Each program takes less memory while running -> more programs run at the same time Increased CPU utilization and throughput with no increase in response time or turnaround time Less I/O needed to load or swap programs into memory -> each user program runs faster •
  • 5. © Oxford University Press 2014. All rights reserved. Virtual Memory Virtual memory – separation of user logical memory from physical memory •Only part of the program needs to be in memory for execution •Logical address space can therefore be much larger than physical address space •Allows address spaces to be shared by several processes •Allows for more efficient process creation •More programs running concurrently •Less I/O needed to load or swap processes
  • 6. © Oxford University Press 2014. All rights reserved. Virtual Memory • Virtual memory can be implemented via: Demand paging Demand segmentation • The address translation using paging and segmentation are applied in the same way as discussed in the last chapter. • The only difference of applying paging and segmentation in relation to virtual memory is that there is no need to load the whole process in the form of pages or segments in the main memory. • VM system requires only those pages or segments of a process in the memory which are needed at a certain time of execution.
  • 7. © Oxford University Press 2014. All rights reserved. Demand loading
  • 8. © Oxford University Press 2014. All rights reserved. Demand paging Demand paging is to load only those pages in the memory that are needed at an instant of time of execution. •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 •Page is needed  reference/logical address 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
  • 9. © Oxford University Press 2014. All rights reserved. Demand paging
  • 10. © Oxford University Press 2014. All rights reserved. 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
  • 11. © Oxford University Press 2013. All rights reserved. Page Table When Some Pages Are Not in Main Memory
  • 12. © Oxford University Press 2014. All rights reserved. Page and Frame Replacement Algorithms • Frame-allocation algorithm determines – How many frames to give each process – Which frames to replace • Page-replacement algorithm – Want lowest page-fault rate on both first access and re-access • Evaluate algorithm by running it on a particular string of memory references (reference string) and computing the number of page faults on that string – String is just page numbers, not full addresses – Repeated access to the same page does not cause a page fault – Results depend on number of frames available • In all our examples, the reference string of referenced page numbers is 7,0,1,2,0,3,0,4,2,3,0,3,0,3,2,1,2,0,1,7,0,1
  • 13. © Oxford University Press 2014. All rights reserved. Page replacement algorithms •A page fault occurs when a page is not found in the memory, and needs to be loaded from the disk. •If a page fault occurs and all memory frames have been already allocated, then replacement of a page in memory is required on the request of a new page. This is referred to as demand-paging. •The choice of which page to replace is specified by a page replacement algorithms. The commonly used page replacement algorithms are FIFO, LRU, optimal page replacement algorithms etc.
  • 14. © Oxford University Press 2014. All rights reserved. Page replacement algorithms The strategy to choose a best page to be replaced in the memory is called a page replacement algorithm. FIFO page replacement algorithm A page to be replaced is chosen such that it is the oldest one among the all pages in the memory. Optimal page replacement algorithm A page will be replaced that will not be referenced for the longest time.
  • 15. © Oxford University Press 2014. All rights reserved. First-In-First-Out (FIFO) Algorithm • Reference string: 7,0,1,2,0,3,0,4,2,3,0,3,0,3,2,1,2,0,1,7,0,1 • 3 frames (3 pages can be in memory at a time per process) • Can vary by reference string: consider 1,2,3,4,1,2,5,1,2,3,4,5 – Adding more frames can cause more page faults! • Belady’s Anomaly 15 page faults
  • 16. © Oxford University Press 2014. All rights reserved. Belody Anamoly • Generally, on increasing the number of frames to a process’ virtual memory, its execution becomes faster as less number of page faults occur. Sometimes the reverse happens, i.e. more number of page faults occur when more frames are allocated to a process. This most unexpected result is termed as Belady’s Anomaly. • Bélády’s anomaly is the name given to the phenomenon where increasing the number of page frames results in an increase in the number of page faults for a given memory access pattern.
  • 17. © Oxford University Press 2014. All rights reserved. Optimal Page Replacement Algorithm • Replace page that will not be used for longest period of time (Page that is referred in last in reference string is replaced first) • How do you know this? – Can’t read the future • Used for measuring how well your algorithm performs
  • 18. © Oxford University Press 2014. All rights reserved. Page replacement algorithms Least Recently Used (LRU) page replacement algorithm Replace a page which will not be referenced for a longest time in the future. •Use past knowledge rather than future •Replace page that has not been used in the most amount of time •Associate time of last use with each page •
  • 19. © Oxford University Press 2014. All rights reserved. Least Recently Used (LRU) Algorithm •12 faults – better than FIFO but worse than OPT •Generally good algorithm and frequently used
  • 20. © Oxford University Press 2014. All rights reserved. Global 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
  • 21. © Oxford University Press 2014. All rights reserved. Thrashing The high paging activity is known as thrashing. A process is said to be thrashing if most of the time is being consumed in paging rather than its actual execution. If a process does not have “enough” pages, the page-fault rate is very high Page fault to get page Replace existing frame But quickly need replaced frame back This leads to: Low CPU utilization Operating system thinking that it needs to increase the degree of multiprogramming Another process added to the system
  • 22. © Oxford University Press 2014. All rights reserved. Thrashing