Chapter 10: Virtual Memory

Chapter 10: Virtual Memory

Chapter 10: Virtual Memory Operating System Concepts – 10th Edition Silberschatz, Galvin and Gagne ©2018, revised by S. Weiss 2020 Chapter 10: Virtual Memory Background Demand Paging Copy-on-Write Page Replacement Allocation of Frames Thrashing Memory-Mapped Files Allocating Kernel Memory Other Considerations Operating-System E$amples Operating System Concepts – 10th Edition 10.2 Silberschatz, Galvin and Gagne ©2018, revised by S. Weiss 2020 Objectives Define &irtual memory and describe its benefits. Illustrate how pages are loaded into memory using demand paging( Apply the FIFO, optimal, and LRU page-replacement algorithms. Describe the working set of a process, and explain how it is related to program locality. Describe how Linux manages &irtual memory. Operating System Concepts – 10th Edition 10.3 Silberschatz, Galvin and Gagne ©2018, revised by S. Weiss 2020 Background Although code needs to be in memory to be executed+ the entire program does not need to 'e. !nly small sections execute in any small window of time+ and Error code+ unusual routines, large data structures do not need to be in memory for the entire execution of the program What if we do not load the entire program into memory? Program no longer constrained 'y limits of physical memory Each program takes less memory while running implies more programs run at the same time )ncreased 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 Operating System Concepts – 10th Edition 10.4 Silberschatz, Galvin and Gagne ©2018, revised by S. Weiss 2020 Virtual memory Virtual memory – separation of user logical memory from physical memory Only part of the program and its data needs to be in memory for execution ,ogical address space can therefore be much larger than physical address space Also allows address spaces to be shared by several processes Allows for more efficient process creation More programs running concurrently ,ess I/O needed to load or swap processes Operating System Concepts – 10th Edition 10.5 Silberschatz, Galvin and Gagne ©2018, revised by S. Weiss 2020 Virtual memory (Cont.) Virtual address space 2 logical view of how process is stored in memory -sually starts at address 0, contiguous addresses until end of space 58-bit virtual addresses implies 7848 bytes of virtual memory Physical memory is still organized into page frames MMU must map &irtual to physical 9irtual memory can be implemented via: Demand paging Demand segmentation Operating System Concepts – 10th Edition 10. Silberschatz, Galvin and Gagne ©2018, revised by S. Weiss 2020 Virtual Address Translation Translation of a ;7-'it virtual address to a 30-bit physical address: Virtual address 31 30 29 28 27 15 14 13 12 11 10 9 8 3 2 1 0 Virtual page number Page offset Translation 29 28 27 15 14 13 12 11 10 9 8 3 2 1 0 Physical page number Page offset Physical address Operating System Concepts – 10th Edition 10.! Silberschatz, Galvin and Gagne ©2018, revised by S. Weiss 2020 Virtual Memory That is Larger Than Physical Memory Operating System Concepts – 10th Edition 10." Silberschatz, Galvin and Gagne ©2018, revised by S. Weiss 2020 Translation Using Just a Page Table Operating System Concepts – 10th Edition 10.# Silberschatz, Galvin and Gagne ©2018, revised by S. Weiss 2020 Virtual-address Space "tandard format <#LF= has logical address space for stack to start at Ma$ logical address and grow >down” *hile heap grows >up? Maximizes address space use -nused address space bet*een the t*o is hole @o physical memory needed until heap or stack gro*s to a given new page #nables sparse address spaces *ith holes left for growth+ dynamically linked libraries, etc "ystem libraries shared via mapping into &irtual address space "hared memory by mapping pages read- *rite into &irtual address space Pages can 'e shared during fork()+ speeding process creation Operating System Concepts – 10th Edition 10.10 Silberschatz, Galvin and Gagne ©2018, revised by S. Weiss 2020 Shared Library Using Virtual Memory Operating System Concepts – 10th Edition 10.11 Silberschatz, Galvin and Gagne ©2018, revised by S. Weiss 2020 Demand Paging )n demand paging: pages are brought into memory only *hen needed: Less )0! needed+ no unnecessary )0! Less memory needed Faster response More users )f a page is needed+ it implies a reference made to it invalid reference abort not-in-memory 'ring into memory $azy s&apper 2 ne&er brings a page into memory unless page *ill be needed "*apper that deals *ith pages is called a pager Operating System Concepts – 10th Edition 10.12 Silberschatz, Galvin and Gagne ©2018, revised by S. Weiss 2020 Basic Concepts With swapping+ pager guesses which pages will be used 'efore s*apping out again )nstead, pager brings in only those pages into memory How to determine that set of pages? Need new MMU functionality to implement demand paging )f pages needed are already memory resident No diBerent from non demand-paging )f 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 Operating System Concepts – 10th Edition 10.13 Silberschatz, Galvin and Gagne ©2018, revised by S. Weiss 2020 Valid-Invalid Bit With each page table entry a valid–invalid bit is associated <' in-memory 2 memory resident+ i not-in-memory= )nitially valid–invalid bit is set to i on all entries #$ample of a page table snapshot: During MMU address translation, if valid–invalid bit in page table entry is i page fault Operating System Concepts – 10th Edition 10.14 Silberschatz, Galvin and Gagne ©2018, revised by S. Weiss 2020 Page Table When Some Pages Are Not in Main Memory Operating System Concepts – 10th Edition 10.15 Silberschatz, Galvin and Gagne ©2018, revised by S. Weiss 2020 Steps in Handling Page Fault C( If there is a reference to a page, the first reference to that page will trap to operating system, i(+e. it is a Page fault 7( Operating system looks at another table to decide: Invalid reference abort Just not in memory ;( Find free frame 5( "*ap page into frame via scheduled disk operation E( Reset tables to indicate page now in memory Set validation 'it F ' G( Restart the instruction that caused the page fault Operating System Concepts – 10th Edition 10.1 Silberschatz, Galvin and Gagne ©2018, revised by S. Weiss 2020 Steps in Handling a Page Fault (Cont.) Operating System Concepts – 10th Edition 10.1! Silberschatz, Galvin and Gagne ©2018, revised by S. Weiss 2020 Aspects of Demand Paging #xtreme case 2 start process *ith no pages in memory !" sets instruction pointer to first instruction of process, non-memory-resident -> page fault And for every other process pages on first access )ure demand paging Actually, a given instruction could access multiple pages -1 multiple page faults Consider fetch and decode of instruction *hich adds 7 numbers from memory and stores result back to memory Pain decreased because of locality o( reference Aard*are support needed for demand paging Page table *ith valid 0 invalid 'it "econdary memory <swap device *ith s&ap space= )nstruction restart Operating System Concepts – 10th Edition 10.1" Silberschatz, Galvin and Gagne ©2018, revised by S. Weiss 2020 Instruction Restart Consider an instruction that could access several different locations Block move Auto increment/decrement location Restart the *hole operation? What if source and destination overlap. Operating System Concepts – 10th Edition 10.1# Silberschatz, Galvin and Gagne ©2018, revised by S. Weiss 2020 Free-Frame List When a page fault occurs, the operating system must 'ring the desired page from secondary storage into main memory. Most operating systems maintain a free-frame list -- a pool of free frames for satisfying such requests. !perating system typically allocate free frames using a technique known as zero-fill-on-demand -- the content of the frames zeroed-out before being allocated( When a system starts up+ all available memory is placed on the free-frame list. Operating System Concepts – 10th Edition 10.20 Silberschatz, Galvin and Gagne ©2018, revised by S. Weiss 2020 Stages in Demand Paging – Worse Case C( Trap to the operating system 7( Save the user registers and process state ;( Determine that the interrupt *as a page fault 5( Check that the page reference was legal and determine the location of the page on the disk E( Issue a read from the disk to a free frame: C( Wait in a Hueue for this device until the read request is serviced 7( Wait for the device seek and/or latency time ;( Begin the transfer of the page to a free frame Operating System Concepts – 10th Edition 10.21 Silberschatz, Galvin and Gagne ©2018, revised by S. Weiss 2020 Stages in Demand Paging (Cont.) G( While waiting, allocate the CPU to some other user I( Receive an interrupt from the disk )0O subsystem (I/O completed= 6( Save the registers and process state for the other user J( Determine that the interrupt was from the disk C4( Correct the page table and other tables to show page is now in memory CC( Wait for the CPU to be allocated to this process again C7( Restore the user registers, process state, and new page table, and then resume the interrupted instruction Operating System Concepts – 10th Edition 10.22 Silberschatz, Galvin and Gagne ©2018, revised by S. Weiss 2020 Performance of Demand Paging 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 C if p F 0 no page faults if p F 1, every reference is a fault #Bective Access Time (EAT= EAT F (1 – p) x memory access L p (page fault overhead L s*ap page out L s*ap page in = Operating System Concepts – 10th Edition 10.23 Silberschatz, Galvin and Gagne ©2018, revised by S.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    86 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us