CS 149: Operating Systems March 3 Class Meeting Department of Computer Science San Jose State University Spring 2015 Instructor: Ron Mak www.cs.sjsu.edu/~mak.

Slides:



Advertisements
Similar presentations
Memory.
Advertisements

Part IV: Memory Management
MODERN OPERATING SYSTEMS Third Edition ANDREW S. TANENBAUM Chapter 3 Memory Management Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall,
Operating Systems Lecture Notes Memory Management Matthew Dailey Some material © Silberschatz, Galvin, and Gagne, 2002.
CS 311 – Lecture 21 Outline Memory management in UNIX
Modified from Silberschatz, Galvin and Gagne Lecture 16 Chapter 8: Main Memory.
Chapter 9: Main Memory. 8.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Feb 22, 2005 Chapter 9: Memory Management Background.
Memory Management.
Chapter 3 Memory Management
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 8: Main Memory.
Chapter 7: Main Memory CS 170, Fall Memory Management Background Swapping Contiguous Memory Allocation Paging Structure of the Page Table Segmentation.
03/22/2004CSCI 315 Operating Systems Design1 Virtual Memory Notice: The slides for this lecture have been largely based on those accompanying the textbook.
A. Frank - P. Weisberg Operating Systems Simple/Basic Paging.
Silberschatz, Galvin and Gagne  Operating System Concepts Segmentation Memory-management scheme that supports user view of memory. A program.
Main Memory. Background Program must be brought (from disk) into memory and placed within a process for it to be run Main memory and registers are only.
03/17/2008CSCI 315 Operating Systems Design1 Virtual Memory Notice: The slides for this lecture have been largely based on those accompanying the textbook.
03/05/2008CSCI 315 Operating Systems Design1 Memory Management Notice: The slides for this lecture have been largely based on those accompanying the textbook.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 8: Main Memory.
Chapter 8: Main Memory.
Chapter 8 Main Memory Bernard Chen Spring Objectives To provide a detailed description of various ways of organizing memory hardware To discuss.
Chap 8 Memory Management. Background Program must be brought into memory and placed within a process for it to be run Input queue – collection of processes.
Chapter 8: Main Memory. 8.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 8: Memory Management Background Swapping Contiguous.
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 346, Royden, Operating System Concepts Operating Systems Lecture 24 Paging.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 9: Memory Management Background Swapping Contiguous Allocation Paging Segmentation.
8.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts with Java – 8 th Edition Chapter 8: Memory Management.
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 32 Paging Read Ch. 9.4.
SOCSAMS e-learning Dept. of Computer Applications, MES College Marampally MEMORYMANAGEMNT.
Operating Systems Chapter 8
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 8: Main Memory.
CS 149: Operating Systems February 26 Class Meeting Department of Computer Science San Jose State University Spring 2015 Instructor: Ron Mak
8.4 paging Paging is a memory-management scheme that permits the physical address space of a process to be non-contiguous. The basic method for implementation.
1 Chapter 3.2 : Virtual Memory What is virtual memory? What is virtual memory? Virtual memory management schemes Virtual memory management schemes Paging.
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 34 Paging Implementation.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 9: Memory Management Background Swapping Contiguous Allocation Paging Segmentation.
Memory Management – Page 1 of 49CSCI 4717 – Computer Architecture Memory Management Uni-program – memory split into two parts –One for Operating System.
Background Program must be brought into memory and placed within a process for it to be run. Input queue – collection of processes on the disk that are.
CS 149: Operating Systems April 9 Class Meeting Department of Computer Science San Jose State University Spring 2015 Instructor: Ron Mak
Computer Architecture and Operating Systems CS 3230: Operating System Section Lecture OS-8 Memory Management (2) Department of Computer Science and Software.
8.1 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Paging Physical address space of a process can be noncontiguous Avoids.
1 Memory Management (b). 2 Paging  Logical address space of a process can be noncontiguous; process is allocated physical memory whenever the latter.
CS 149: Operating Systems March 5 Class Meeting Department of Computer Science San Jose State University Spring 2015 Instructor: Ron Mak
Memory Management Continued Questions answered in this lecture: What is paging? How can segmentation and paging be combined? How can one speed up address.
Memory Management. Background Memory consists of a large array of words or bytes, each with its own address. The CPU fetches instructions from memory.
Chapter 8: Main Memory. 8.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Feb 22, 2005 Memory and Addressing It all starts.
8.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Fragmentation External Fragmentation – total memory space exists to satisfy.
Silberschatz, Galvin and Gagne  Operating System Concepts Paging Logical address space of a process can be noncontiguous; process is allocated.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 8: Main Memory.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 8: Main Memory.
Chapter 8: Memory Management. 8.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 8: Memory Management Background Swapping Contiguous.
Chapter 7: Main Memory CS 170, Fall Program Execution & Memory Management Program execution Swapping Contiguous Memory Allocation Paging Structure.
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 33 Paging Read Ch. 9.4.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition, Chapter 8: Memory- Management Strategies.
Module 9: Memory Management
Chapter 9: Memory Management
Chapter 8: Main Memory.
Operating System Concepts
Module 9: Memory Management
Memory Management Lectures notes from the text supplement by Siberschatz and Galvin Modified by B.Ramamurthy Chapter 8 11/24/2018.
Background Program must be brought into memory and placed within a process for it to be run. Input queue – collection of processes on the disk that are.
CSS 430: Operating Systems - Main Memory
Memory Management Lectures notes from the text supplement by Siberschatz and Galvin Modified by B.Ramamurthy Chapter 9 12/1/2018.
Memory Management-I 1.
Main Memory Background Swapping Contiguous Allocation Paging
Lecture 3: Main Memory.
So far in memory management…
Memory Management Lectures notes from the text supplement by Siberschatz and Galvin Modified by B.Ramamurthy Chapter 9 4/5/2019.
4.3 Virtual Memory.
Page Main Memory.
Presentation transcript:

CS 149: Operating Systems March 3 Class Meeting Department of Computer Science San Jose State University Spring 2015 Instructor: Ron Mak

Computer Science Dept. Spring 2015: March 3 CS 149: Operating Systems © R. Mak 2 Keeping Track of Memory  The memory manager can maintain either a bitmap or a linked list of allocated and free memory segments. A segment is either a process or a hole between processes. Modern Operating Systems, 3 rd ed. Andrew Tanenbaum (c) 2008 Prentice-Hall, Inc All rights reserved

Computer Science Dept. Spring 2015: March 3 CS 149: Operating Systems © R. Mak 3 Keeping Track of Memory, cont’d  A linked list entry changes from “process” to “hole” when the process terminates.  Two adjacent hole entries can coalesce into a single entry for a (larger) hole. Modern Operating Systems, 3 rd ed. Andrew Tanenbaum (c) 2008 Prentice-Hall, Inc All rights reserved

Computer Science Dept. Spring 2015: March 3 CS 149: Operating Systems © R. Mak 4 Memory Allocation Algorithms  When a process is loaded into memory, a large enough hole must be found for it.  First fit: The memory manager searches its linked list of memory segments from the beginning until it finds the first hole big enough. It breaks the hole into two parts, one to allocate to the process and the other part to be a (smaller) hole. Fast algorithm: shortest possible search.

Computer Science Dept. Spring 2015: March 3 CS 149: Operating Systems © R. Mak 5 Memory Allocation Algorithms, cont’d  Next fit: Each search for a hole in the linked list of memory segments starts from where the previous search ended. Simulations show slightly worse performance than first fit.  Best fit: Search the linked list of memory segments for the smallest hole where the process will fit. Slower: longer search Results in more wasted memory. Fills memory with tiny, useless holes. Why?

Computer Science Dept. Spring 2015: March 3 CS 149: Operating Systems © R. Mak 6 Memory Allocation Algorithms, cont’d  Some optimizations are possible. Maintain separate linked lists for processes and holes. Sort the holes by size.  Quick fit: Maintain separate linked lists for the most commonly requested allocation sizes. Hard to find neighboring holes to coalesce when processes terminate. Fills memory with tiny, useless holes.

Computer Science Dept. Spring 2015: March 3 CS 149: Operating Systems © R. Mak 7 External Memory Fragmentation  Free memory space is broken into small pieces.  Free spaces are not contiguous.  Fragmentation depends on the memory allocation algorithm. With first fit, up to one-third of memory may be unusable.

Computer Science Dept. Spring 2015: March 3 CS 149: Operating Systems © R. Mak 8 Internal Memory Fragmentation  Unused memory that is internal to a block.  When allocating memory in fixed-size blocks, the amount allocated to a process may be more than what the process requested.

Computer Science Dept. Spring 2015: March 3 CS 149: Operating Systems © R. Mak 9 Paging  Paging is a memory management scheme that allows the physical address space of a process to be noncontiguous.  No external fragmentation. Can have internal fragmentation.  No need for memory compaction.  Helps solve the problem of allocating various sizes of memory blocks to a process. Fragmentation can occur on the swapping backing store.

Computer Science Dept. Spring 2015: March 3 CS 149: Operating Systems © R. Mak 10 Paging, cont’d  Used by most operating systems.  Superior to previous memory management schemes.  Paging support traditionally was handled by hardware. On 64-bit microprocessors, paging is often implemented by a combination of hardware and operating system.

Computer Science Dept. Spring 2015: March 3 CS 149: Operating Systems © R. Mak 11 Paging, cont’d  Divide physical memory into fixed-sized frames. AKA page frames Size is a power of 2, between 512 bytes and 8192 bytes.  Divide logical memory into pages of same size.

Computer Science Dept. Spring 2015: March 3 CS 149: Operating Systems © R. Mak 12 Paging, cont’d  The memory manager keeps track of all free frames.  To run a program of size n pages, the memory manager needs to find n free frames into which to load the program.  A page table translates logical addresses to physical addresses.

Computer Science Dept. Spring 2015: March 3 CS 149: Operating Systems © R. Mak 13 Paging, cont’d  Page table mapping of logical (virtual) addresses to physical addresses. Modern Operating Systems, 3 rd ed. Andrew Tanenbaum (c) 2008 Prentice-Hall, Inc All rights reserved

Computer Science Dept. Spring 2015: March 3 CS 149: Operating Systems © R. Mak 14 Paging, cont’d  Every logical address generated by the CPU has two parts: page number p page offset d  The page number is the page table index. The page table entry contains the base address of each page in physical memory.  The base address + the page offset together map to the physical address. This mapping must be fast.

Computer Science Dept. Spring 2015: March 3 CS 149: Operating Systems © R. Mak 15 Paging, cont’d  Why a power of 2 for the page and frame size?  If the size of the logical address space is 2 m and the page size is 2 n, then the high-order m-n bits of a logical address are the page number and the low-order n bits are the page offset. page number page offset p d m - n n

Computer Science Dept. Spring 2015: March 3 CS 149: Operating Systems © R. Mak 16 Paging, cont’d Modern Operating Systems, 3 rd ed. Andrew Tanenbaum (c) 2008 Prentice-Hall, Inc All rights reserved

Computer Science Dept. Spring 2015: March 3 CS 149: Operating Systems © R. Mak 17 Paging, cont’d Operating Systems Concepts with Java, 8 th edition Silberschatz, Galvin, and Gagne (c) 2010 John Wiley & Sons. All rights reserved

Computer Science Dept. Spring 2015: March 3 CS 149: Operating Systems © R. Mak 18 Paging, cont’d Operating Systems Concepts with Java, 8 th edition Silberschatz, Galvin, and Gagne (c) 2010 John Wiley & Sons. All rights reserved

Computer Science Dept. Spring 2015: March 3 CS 149: Operating Systems © R. Mak 19 Shared Pages  Paging enables shared code. One copy of a reentrant code module in memory. Shared code must appear in same location in the logical address space of all processes.  Private code and data. Each process keeps a separate copy of its private code and data pages. The pages for the private code and data can appear anywhere in the logical address space.

Computer Science Dept. Spring 2015: March 3 CS 149: Operating Systems © R. Mak 20 Shared Pages, cont’d Operating Systems Concepts with Java, 8 th edition Silberschatz, Galvin, and Gagne (c) 2010 John Wiley & Sons. All rights reserved

Computer Science Dept. Spring 2015: March 3 CS 149: Operating Systems © R. Mak 21 Multilevel Page Tables  Multilevel page tables avoid keeping all the page tables in memory all the time.  A virtual address has two page table fields along with the offset. Operating Systems Concepts with Java, 8 th edition Silberschatz, Galvin, and Gagne (c) 2010 John Wiley & Sons. All rights reserved

Computer Science Dept. Spring 2015: March 3 CS 149: Operating Systems © R. Mak 22 Common Fields of a Page Table Entry  Page frame number  Present/absent bit 0 = virtual page not currently in memory Page fault if attempt to access this page.  Protection bits Read, write, execute privileges  Modified (“dirty”) bit Is the disk copy still valid?  Referenced OK to evict this page from memory?  Caching On or off Modern Operating Systems, 3 rd ed. Andrew Tanenbaum (c) 2008 Prentice-Hall, Inc All rights reserved

Computer Science Dept. Spring 2015: March 3 CS 149: Operating Systems © R. Mak 23 Translation Lookaside Buffer (TLB)  Hardware device that rapidly maps virtual addresses to physical addresses.  Bypass the page table.  Usually inside the memory management unit (MMU).  AKA associative memory.

Computer Science Dept. Spring 2015: March 3 CS 149: Operating Systems © R. Mak 24 Translation Lookaside Buffer (TLB), cont’d  Takes advantage of locality of reference.  A program generally only uses a small percentage of its page table entries. Spatial locality: Address references tend to cluster. Temporal locality: An address that was referenced will tend to be referenced again soon.  The TLB usually contains only 8 to 64 entries.

Computer Science Dept. Spring 2015: March 3 CS 149: Operating Systems © R. Mak 25 Translation Lookaside Buffer (TLB), cont’d Operating Systems Concepts with Java, 8 th edition Silberschatz, Galvin, and Gagne (c) 2010 John Wiley & Sons. All rights reserved

Computer Science Dept. Spring 2015: March 3 CS 149: Operating Systems © R. Mak 26 Search TLB Entries in Parallel  If the desired page is not in the TLB (a TLB miss), then go to the page table.  After a miss, enter the page into the TLB so that it can be a TLB hit the next time.

Computer Science Dept. Spring 2015: March 3 CS 149: Operating Systems © R. Mak 27 TLB Hit Ratio  Hit ratio: The percentage of times that a desired page number is found in the TLB.

Computer Science Dept. Spring 2015: March 3 CS 149: Operating Systems © R. Mak 28 TLB Hit Ratio Example  Suppose it takes 20 nsec to search the TLB and 100 nsec to access main memory. Therefore, if the desired page is in the TLB, it will take 120 nsec to access memory.  If the page is not in the TLB, it will take  20 nsec to search the TLB, 100 nsec to access the page table 100 nsec to access main memory TotaL: 220 nsec.

Computer Science Dept. Spring 2015: March 3 CS 149: Operating Systems © R. Mak 29 TLB Hit Ratio Example  Effective access time (EAT) for an 80% hit ratio: (0.80 X 120 nsec) + (0.20 X 220 nsec) = 140 nsec  Effective access time for a 98% hit ratio: (0.98 X 120 nsec) + (0.02 X 220 nsec) = 122 nsec  Increasing the hit ratio by 23% decreased EAT by 13%

Computer Science Dept. Spring 2015: March 3 CS 149: Operating Systems © R. Mak 30 Inverted Page Tables  Traditional page table: One entry per virtual page.  On 64-bit computers, the virtual address space is 2 64 bytes.  With size 4KB (2 12 ) pages, a page table would need 2 52 entries.

Computer Science Dept. Spring 2015: March 3 CS 149: Operating Systems © R. Mak 31 Inverted Page Tables, cont’d  An inverted page table has one entry per page frame in physical memory.  Each entry consists of: The virtual address of the page stored in that page frame. Information about the process that owns that page.

Computer Science Dept. Spring 2015: March 3 CS 149: Operating Systems © R. Mak 32 Inverted Page Tables, cont’d  Decreases the memory needed to store each page table.  But increases time needed to search the table for each page reference. Use a hash table to search the table faster. Or use the TLB.

Computer Science Dept. Spring 2015: March 3 CS 149: Operating Systems © R. Mak 33 Inverted Page Tables, cont’d  Comparison of a traditional page table with an inverted page table. Modern Operating Systems, 3 rd ed. Andrew Tanenbaum (c) 2008 Prentice-Hall, Inc All rights reserved

Computer Science Dept. Spring 2015: March 3 CS 149: Operating Systems © R. Mak 34 Segmentation  Programmers think of their programs as consisting of segments, not one linear address space. Examples: Java packages, objects, etc.  Segmentation memory management scheme The logical address space is a collection of segments. Each segment has a name (or number) and a length. A logical address specifies the segment name or number and an offset within the segment.

Computer Science Dept. Spring 2015: March 3 CS 149: Operating Systems © R. Mak 35 The Segment Table  Each table entry has a segment base and a segment limit.  The segment base is the starting physical address.  The segment limit specifies the length of the segment.

Computer Science Dept. Spring 2015: March 3 CS 149: Operating Systems © R. Mak 36 The Segment Table, cont’d Operating Systems Concepts with Java, 8 th edition Silberschatz, Galvin, and Gagne (c) 2010 John Wiley & Sons. All rights reserved

Computer Science Dept. Spring 2015: March 3 CS 149: Operating Systems © R. Mak 37 Segmentation, cont’d  Segmented memory allows each segment to grow and shrink independently of the others. Example: Segments of a compiler: Modern Operating Systems, 3 rd ed. Andrew Tanenbaum (c) 2008 Prentice-Hall, Inc All rights reserved

Computer Science Dept. Spring 2015: March 3 CS 149: Operating Systems © R. Mak 38 Segmentation, cont’d  Segmentation can cause external fragmentation. AKA checkerboarding Remove with memory compaction. Modern Operating Systems, 3 rd ed. Andrew Tanenbaum (c) 2008 Prentice-Hall, Inc All rights reserved

Computer Science Dept. Spring 2015: March 3 CS 149: Operating Systems © R. Mak 39 Paging vs. Segmentation Modern Operating Systems, 3 rd ed. Andrew Tanenbaum (c) 2008 Prentice-Hall, Inc All rights reserved