Скачать презентацию CE 454 Computer Architecture Lecture 12 Ahmed Ezzat Скачать презентацию CE 454 Computer Architecture Lecture 12 Ahmed Ezzat

7d435ab1cca0fee3013a97eb9754b7a0.ppt

  • Количество слайдов: 28

CE 454 Computer Architecture Lecture 12 Ahmed Ezzat The Operating System Machine Level, Ch-(6. CE 454 Computer Architecture Lecture 12 Ahmed Ezzat The Operating System Machine Level, Ch-(6. 1 – 6. 3) 1

Outline l l Virtual Memory l Virtual I/O Instructions l 2 Introduction Virtual Instructions Outline l l Virtual Memory l Virtual I/O Instructions l 2 Introduction Virtual Instructions for Parallel Processing CE 454 Ahmed Ezzat

Introduction l l OS Machine level includes most ISA instructions + system calls l Introduction l l OS Machine level includes most ISA instructions + system calls l 3 OS is a program that adds variety of new instructions and features (system calls) beyond the ISA level OSM level is always interpretive, i. e. , reading data from a file is executed similar to a microprogram carrying out an ADD instruction – step-by-step CE 454 Ahmed Ezzat

Virtual Memory l Since the IBM compatible PC 286, virtual memory has been used Virtual Memory l Since the IBM compatible PC 286, virtual memory has been used to make believe that memory space is larger than what it is – l Before, programmers tried to shrink programs to fit tiny memories – 4 Using the external memory device (as disk) to extend the addressable space Code and data size is still a constraint in embedded systems though CE 454 Ahmed Ezzat

Virtual Memory: Implementations of VM l Distinction between virtual and physical memory l Paging Virtual Memory: Implementations of VM l Distinction between virtual and physical memory l Paging – – l Segmentation – 5 The memory space is a large one-dimensional array, which extends to the disk Disk broken up into regular sized pages Pages are brought in memory on demand And written back when needed The memory is broken up into variable sized segments l We will not consider segmentation in detail CE 454 Ahmed Ezzat

Virtual Memory: Memory Issues l Idea: Separate concepts of – Addressable space (virtual memory) Virtual Memory: Memory Issues l Idea: Separate concepts of – Addressable space (virtual memory) – And memory locations (physical memory) – Example: l Address Space = 216 = 65536 memory cells l Memory Size = 4096 memory cells How can we fit the Address Space into Main Memory? 6 CE 454 Ahmed Ezzat

Virtual Memory: Paging l Break the addressable space (Virtual space) into Pages – Normally Virtual Memory: Paging l Break the addressable space (Virtual space) into Pages – Normally Main Memory has thousands of pages 1 page = 4096 bytes page New Issue: How to manage addressing? 7 CE 454 Ahmed Ezzat

Virtual Memory: Address Mapping Virtual Memory addresses to Main Memory addresses (physical addresses) Physical Virtual Memory: Address Mapping Virtual Memory addresses to Main Memory addresses (physical addresses) Physical / Virtual 4095 0 1 page = 4096 bytes 8191 4096 page virtual address used by program 8 CE 454 page physical address used by hardware Ahmed Ezzat

Virtual Memory: Paging physical virtual 4095 4096 page 9 • Large 8191 0 • Virtual Memory: Paging physical virtual 4095 4096 page 9 • Large 8191 0 • Illusion that Main Memory is page • Contiguous • Linear • Size(MM) = Size(2 ndry M) • Transparent to Programmer 4095 / 0 0 CE 454 page Ahmed Ezzat

Virtual Memory: Paging Implementation l Virtual Address Space & Physical Address Space – Broken Virtual Memory: Paging Implementation l Virtual Address Space & Physical Address Space – Broken up into equal pages l Page size Always a power of 2 Common Size: l – 10 512 to 64 K bytes CE 454 Ahmed Ezzat

Virtual Memory: Paging Implementation l l Page Tables l 11 Page Frames Programs use Virtual Memory: Paging Implementation l l Page Tables l 11 Page Frames Programs use Virtual Addresses CE 454 Ahmed Ezzat

Virtual Memory: Virtual and physical Memory • Page Frame: • Home of VM pages Virtual Memory: Virtual and physical Memory • Page Frame: • Home of VM pages in MM • Page Table: • Home of mappings for VM pages 12 CE 454 Ahmed Ezzat

Virtual Memory: Memory Mapping • Memory Management Unit (MMU): • Device that performs virtual-to-physical Virtual Memory: Memory Mapping • Memory Management Unit (MMU): • Device that performs virtual-to-physical mapping 32 -bit VM Address MMU 13 CE 454 15 -bit Physical Address Ahmed Ezzat

Virtual Memory: Memory Management Unit 32 -bit Virtual Address • MMU Breaks VA into Virtual Memory: Memory Management Unit 32 -bit Virtual Address • MMU Breaks VA into 2 portions 20 -bit Virtual page # 12 -bit offset in page How to determine if page is in MM? Present/Absent Bit in Page Table Entry 14 CE 454 Ahmed Ezzat

Virtual Memory: Demand Paging and Working Set Model Page Fault: Requested page is not Virtual Memory: Demand Paging and Working Set Model Page Fault: Requested page is not in MM Demand Paging: Page is demanded by program from disk Possible Mapping of pages Page is loaded into MM + initialize a PTE 15 Repeat instruction that caused the page fault CE 454 Ahmed Ezzat

Virtual Memory: Demand Paging and Working Set Model l l Instead they tend to Virtual Memory: Demand Paging and Working Set Model l l Instead they tend to cluster on a small number of pages l Working set is the set of pages that are used actively and heavily l 16 Most programs do not reference their address space uniformly Working set typically varies slowly with time kept in memory to reduce page faults CE 454 Ahmed Ezzat

Virtual Memory: Page Replacement Policy l l 17 Replacement: It is necessary to predict Virtual Memory: Page Replacement Policy l l 17 Replacement: It is necessary to predict which page would have least impact on the running program Common Replacement Schemes: – Least Recently Used (LRU) – First-In-First-Out (FIFO) CE 454 Ahmed Ezzat

Virtual Memory: Page Replacement Policies l Least Recently Used (LRU) – – Generally works Virtual Memory: Page Replacement Policies l Least Recently Used (LRU) – – Generally works well TROUBLE: l When the working set is larger than the Main Memory Working Set = 9 pages Pages are executed in sequence (0 8 (repeat)) 18 THRASHING CE 454 Ahmed Ezzat

Virtual Memory: Page Replacement Policies l First-In-First-Out (FIFO) – – – 19 Removes Least Virtual Memory: Page Replacement Policies l First-In-First-Out (FIFO) – – – 19 Removes Least Recently Loaded page Does not depend on Use Determined by number of page faults seen: increment counter on P/F CE 454 Ahmed Ezzat

Virtual Memory: Page Replacement Policies l Upon Replacement – Need to know whether to Virtual Memory: Page Replacement Policies l Upon Replacement – Need to know whether to write data back – Add a Dirty-Bit Dirty Bit = 0; Page is clean; No writing Dirty Bit = 1; 20 Page is dirty; Write back CE 454 Ahmed Ezzat

Virtual Memory: Page Size Comments l l Smaller page size allows for less wasted Virtual Memory: Page Size Comments l l Smaller page size allows for less wasted space Benefits: – – l Drawbacks: – – – 21 Less internal fragmentation Less thrashing: large # of small pages is better than small # of large pages (from a Working Set point of view) page table storage bandwidth computer cost time to load more time spent at disk miss rate CE 454 Ahmed Ezzat

Virtual Memory: Segmentation l Rather than having one virtual address space, having multiple can Virtual Memory: Segmentation l Rather than having one virtual address space, having multiple can be better. For example, compiler produces multiple tables: – – 22 Some grows continuously (e. g. , symbol table) Some grow/shrink (e. g. , stack) CE 454 Ahmed Ezzat

Virtual I/O Instructions l ISA-level and Microinstruction-level instructions are quite different l OS Machine-level Virtual I/O Instructions l ISA-level and Microinstruction-level instructions are quite different l OS Machine-level instruction set includes most of the ISA-level instructions Plus additional important instructions (system calls) Minus few damaging ISA instructions (removed from the ISAlevel instructions) – 23 As an example, doing I/O at the ISA-level is tedious and complex. No user cares about the low-level details of why an I/O failed for example CE 454 Ahmed Ezzat

Virtual I/O Instructions: Files l File is an abstraction for presenting virtual I/O l Virtual I/O Instructions: Files l File is an abstraction for presenting virtual I/O l Simple form of a file: a sequence of bytes on an I/O device. If the device is disk, data can be read back. If the device is a printer, data can’t be read back – l 24 In the above abstraction, any further structure to the file abstraction is left up to the application Mainframe file abstraction is more sophisticated: sequence of logical records each with a well defined structure CE 454 Ahmed Ezzat

Virtual I/O Instructions: Implementation Issues l l l 25 Storage allocation: can be a Virtual I/O Instructions: Implementation Issues l l l 25 Storage allocation: can be a disk sector, but often a block of consecutive sectors? Is file stored on disk as consecutive blocks or not? Programmer view the file as a linear sequence of bytes. The OS view the file as an ordered, not necessarily consecutive, collection of blocks on disk CE 454 Ahmed Ezzat

Virtual I/O Instructions: Implementation Issues l 26 OS needs to keep track of which Virtual I/O Instructions: Implementation Issues l 26 OS needs to keep track of which blocks are available on disk? CE 454 Ahmed Ezzat

Virtual Instructions for Parallel Processing l Parallel processing can be done by: – – Virtual Instructions for Parallel Processing l Parallel processing can be done by: – – l 27 Write the application as a set of cooperating processes running in parallel on different CPUs Write the application as a set of processes/threads running on the same CPU In both cases, certain virtual instructions are needed to synchronize among these processes/threads. One such mechanism is semaphores CE 454 Ahmed Ezzat

28 CE 454 Ahmed Ezzat 28 CE 454 Ahmed Ezzat