We think you have liked this presentation. If you wish to download it, please recommend it to your friends in any social system. Share buttons are a little bit lower. Thank you!
Presentation is loading. Please wait.
Modified over 6 years ago
CSCI2413 Lecture 6 Operating Systems Memory Management 2 phones off (please)
© De Montfort University, 2004 CSCI2413 - L6 2 Lecture Outline Virtual Memory Swapping Paging, thrashing Segmentation Summery Notes on swapping and thrashing
© De Montfort University, 2004CSCI2413 - L63 Swapping Moving processes to and fro between main memory and hard disk is called swapping Roll out, roll in – swapping variant used for priority-based scheduling algorithms; lower-priority process is swapped out so higher- priority process can be loaded and executed. (see notes on page 25)
© De Montfort University, 2004CSCI2413 - L64 Virtual Memory uses locality of reference in which most commonly used instructions and data are referenced: –instruction execution is localised either within loops or heavily used subroutines, –data manipulation is on local variables or upon tables or arrays of information. Virtual memory can also be defined as: A mapping from a virtual address space to a physical address space.
© De Montfort University, 2004CSCI2413 - L65 Why Virtual Memory? Use Physical DRAM as a Cache for the Disk –Address space of a process can exceed physical memory size Simplify Memory Management –Multiple processes resident in main memory. Each process with its own address space Provide Protection –One process can’t interfere with another. because they operate in different address spaces. –User process cannot access privileged information different sections of address spaces have different permissions.
© De Montfort University, 2004CSCI2413 - L66 A System with Physical Memory Only Examples: –most Cray machines, early PCs, nearly all embedded systems, etc. Addresses generated by the CPU correspond directly to bytes in physical memory CPU 0: 1: N-1: Memory Physical Addresses
© De Montfort University, 2004CSCI2413 - L67 0: 1: N-1: A System with Virtual Memory (paging) Address Translation: MMU converts virtual addresses to physical addresses via OS-managed lookup table (page table) CPU Memory 0: 1: P-1: Page Table Disk Virtual Addresses Physical Addresses
© De Montfort University, 2004CSCI2413 - L68 Paging Partition memory into small equal-size blocks and divide each process into the same size blocks The blocks of a process are called pages and blocks of memory are called frames Operating system maintains a page table for each process –contains the frame location for each page in the process –each memory reference consist of a page number and offset within the page
© De Montfort University, 2004CSCI2413 - L69 virtual page numberpage offset virtual address physical page numberpage offset physical address 0p–1 address translation pm–1 n–10p–1p Page offset bits don’t change as a result of translation VM Address Translation Parameters –P = 2 p = page size (bytes). –N = 2 n = Virtual address limit –M = 2 m = Physical address limit
© De Montfort University, 2004CSCI2413 - L610 Paging … Each process has its own page table Each page table entry contains the frame number of the corresponding page in main memory A bit is needed to indicate whether the page is in main memory or not
© De Montfort University, 2004CSCI2413 - L611 Page Tables Memory resident page table (physical page address) Physical Memory Disk Storage (swap blocks) Valid 1 1 1 1 1 1 1 0 0 0 Virtual Page Number
© De Montfort University, 2004CSCI2413 - L612 Execution of a Program Operating system brings into main memory a few blocks of the program An interrupt is generated when a block is needed that is not in main memory - page fault Operating system places the process in a blocking state and a DMA is started to get the page from disk An interrupt is issued when disk I/O is complete which causes the OS to place the affected process in the Ready Queue
© De Montfort University, 2004CSCI2413 - L613 Page Faults (like “Cache Misses”) What if a block is on disk rather than in memory? –Page table entry indicates virtual address not in memory –OS exception handler invoked to move data from disk into memory OS has full control over placement, etc. CPU Memory Page Table Disk Virtual Addresses Physical Addresses CPU Memory Page Table Disk Virtual Addresses Physical Addresses Before fault After fault
© De Montfort University, 2004CSCI2413 - L614 Thrashing Swapping out a piece of a process just before that piece is needed The processor spends most of its time swapping pieces rather than executing user instructions (see notes on page 26)
© De Montfort University, 2004CSCI2413 - L615 Replacement Policy Which page should be replaced? –Page that is least likely to be referenced in the near future Each page in memory usually has two bits associated with it: R referenced bit: set when page is accessed (read/written) M modified bit: set when page is written to These bits would be set by MMU when a page is read/written and cleared by the OS - in particular the OS clears the R bits on every clock interrupt.
© De Montfort University, 2004CSCI2413 - L616 Replacement … When a page fault occurs there are four possible scenarios: R = 0, M = 0: not referenced, not modified R = 0, M = 1: not referenced, but modified R = 1, M = 0: referenced, but not modified R = 1, M = 1: referenced and modified
© De Montfort University, 2004CSCI2413 - L617 Replacement algorithm NRU, Simple to operated and adequate performance. If R = 0 and M = 0 (not referenced, not modified) –swap one of these pages else if R = 0, M = 1 (not referenced, but modified) – swap one of these pages else if R = 1, M = 0 (referenced, but not modified) – swap one of these pages else swap one of the R = 1, M = 1 pages Note that any page with M = 0 can be overwritten since that have not been written to since being read from disk.
© De Montfort University, 2004CSCI2413 - L618 Replacement algorithm … FIFO: Not very good - pages are kept in a list and the one at the end of the list is swapped out even if still in use. LRU: swap out or discard the page which has been least used (used by Atlas). Each page has a counter which is incremented by the MMU when the page is accessed. On a page fault swap page with lowest count.
© De Montfort University, 2004CSCI2413 - L619 Replacement algorithms … NFU: Similar to LRU but implemented in software; the OS adds the R bit to the page counter on each clock interrupt (then clears the R bit). On a page fault swap page with lowest count. (Read about problems of LRU and NFU in page 27)
© De Montfort University, 2004CSCI2413 - L620 Segmentation OS creates multiple virtual address spaces, each starting at an arbitrary location and with arbitrary length. The start of a segment is virtual address 0. Each process can be assigned a different segment, independent of others. Relocation done at run time by the virtual memory mapping mechanism. Segmentation is implemented in a manner much like paging, through a lookup table. The difference is that each segment descriptor in the table contains the base address of the segment and a length.
© De Montfort University, 2004CSCI2413 - L621 Segmentation with Paging Some operating systems allow for the combination of segmentation with paging. If the size of a segment exceeds the size of main memory, the segment may be divided into equal size pages.
© De Montfort University, 2004CSCI2413 - L622 Segmentation with paging … The address consists of: segment number, page within the segment and offset within the page. The segment number is used to find the segment descriptor and the address within the segment is used to find the page frame and the offset within that page.
© De Montfort University, 2004CSCI2413 - L623 Summary When swapping is used, the system can handle more processes than it has room for in memory … virtual memory concept.. and hence paging and segmentation When memory is full, a decision must be made as to which page or pages are to be replaced (replacement policy) http://www.cs.umass.edu/~weems/CmpSci535/53 5lecture9.htmlhttp://www.cs.umass.edu/~weems/CmpSci535/53 5lecture9.html
© De Montfort University, 2004CSCI2413 - L624 Example Page Sizes
© De Montfort University, 2004CSCI2413 - L625 Swap file A swap file (or swap space or, in Windows NT, a page) is a space on a hard disk used as the virtual memory extension of a computer's real memory (RAM). Having a swap file allows your computer's operating system to pretend that you have more RAM than you actually do. The least recently used files in RAM can be "swapped out" to your hard disk until they are needed later so that new files can be "swapped in" to RAM. In larger operating systems (such as IBM's OS/390), the units that are moved are called pages and the swapping is called paging. One advantage of a swap file is that it can be organized as a single contiguous space so that fewer I/O operations are required to read or write a complete file. In general, Windows and Unix-based operating systems provide a default swap file of a certain size that the user or a system administrator can usually change.
© De Montfort University, 2004CSCI2413 - L626 thrashing Thrashing is computer activity that makes little or no progress, usually because memory or other resources have become exhausted or too limited to perform needed operations. When this happens, a pattern typically develops in which a request is made of the operating system by a process or program, the operating system tries to find resources by taking them from some other process, which in turn makes new requests that can't be satisfied. In a virtual storage system (an operating system that manages its logical storage or memory in units called pages), thrashing is a condition in which excessive paging operations are taking place. A system that is thrashing can be perceived as either a very slow system or one that has come to a halt.
© De Montfort University, 2004CSCI2413 - L627 LRU and NFU problem: Problem if page is referenced very heavily its counter is large even if it is no longer being accessed, i.e. the counter does not decrease. A modified LRU/NFU introduces aging by on every clock interrupt shifting the counter right one bit (dividing it by two) then adding the R bit. The penalty is that this takes processor power, i.e. if we had 1000 pages and a shift and add R takes 2usec the total time would be 2msec
4.4 Page replacement algorithms
Background Virtual memory – separation of user logical memory from physical memory. Only part of the program needs to be in memory for execution. Logical.
Part IV: Memory Management
Silberschatz, Galvin and Gagne 2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 36 Virtual Memory Read.
Module 9: Virtual Memory
Module 10: Virtual Memory Background Demand Paging Performance of Demand Paging Page Replacement Page-Replacement Algorithms Allocation of Frames Thrashing.
Segmentation and Paging Considerations
Chapter 101 Virtual Memory Chapter 10 Sections and plus (Skip:10.3.2, 10.7, rest of 10.8)
Virtual Memory Chapter 8.
Memory Management (II)
Operating System Support Focus on Architecture
CSCI2413 Lecture 5 Operating Systems Memory Management 1 phones off (please)
Virtual Memory Chapter 8. Hardware and Control Structures Memory references are dynamically translated into physical addresses at run time –A process.
Multiprocessing Memory Management
COMP5102/5122 Lecture 4 Operating Systems (OS) Memory Management phones off (please)
Memory Management 2010.
1 Virtual Memory Chapter 8. 2 Hardware and Control Structures Memory references are dynamically translated into physical addresses at run time –A process.
1 Lecture 9: Virtual Memory Operating System I Spring 2007.
© 2021 SlidePlayer.com Inc. All rights reserved.