Memory Management Virtual Memory

Similar documents
Chapter 8 Virtual Memory

a process may be swapped in and out of main memory such that it occupies different regions

Chapter 8 Virtual Memory

ECE519 Advanced Operating Systems

Chapter 8 Virtual Memory

MEMORY MANAGEMENT/1 CS 409, FALL 2013

Process size is independent of the main memory present in the system.

Virtual Memory. Chapter 8

Operating Systems CSE 410, Spring Virtual Memory. Stephen Wagner Michigan State University

Role of OS in virtual memory management

Virtual Memory. control structures and hardware support

Chapter 8. Virtual Memory

Virtual Memory. Reading: Silberschatz chapter 10 Reading: Stallings. chapter 8 EEL 358

Virtual Memory. Chapter 8

COMP 346 WINTER 2018 MEMORY MANAGEMENT (VIRTUAL MEMORY)

Addresses in the source program are generally symbolic. A compiler will typically bind these symbolic addresses to re-locatable addresses.

Virtual to physical address translation

Memory Management Virtual Memory

Week 2: Tiina Niklander

Operating Systems, Fall

Operating Systems: Internals and Design Principles. Chapter 7 Memory Management Seventh Edition William Stallings

Virtual Memory Outline

Memory management. Requirements. Relocation: program loading. Terms. Relocation. Protection. Sharing. Logical organization. Physical organization

Virtual Memory. Patterson & Hennessey Chapter 5 ELEC 5200/6200 1

Perform page replacement. (Fig 8.8 [Stal05])

Operating Systems Lecture 6: Memory Management II

The Working Set. CS 355 Operating Systems. The Working Set. Working Set Model 3/27/18. Paging Algorithms and Segmentation

Operating System Concepts

!! What is virtual memory and when is it useful? !! What is demand paging? !! When should pages in memory be replaced?

ECE468 Computer Organization and Architecture. Virtual Memory

ECE4680 Computer Organization and Architecture. Virtual Memory

CSE 120. Translation Lookaside Buffer (TLB) Implemented in Hardware. July 18, Day 5 Memory. Instructor: Neil Rhodes. Software TLB Management

Page Size Page Size Design Issues

CS6401- Operating System UNIT-III STORAGE MANAGEMENT

Operating System Support

Memory Management. Reading: Silberschatz chapter 9 Reading: Stallings. chapter 7 EEL 358

Operating Systems, Fall Lecture 5 1. Overhead due to page table and internal fragmentation. Tbl 8.2 [Stal05] 4.

Memory Management. To improve CPU utilization in a multiprogramming environment we need multiple programs in main memory at the same time.

Last Class: Demand Paged Virtual Memory

Operating Systems, Fall Lecture 5 1

CS450/550 Operating Systems

First-In-First-Out (FIFO) Algorithm

Memory Management. Chapter 4 Memory Management. Multiprogramming with Fixed Partitions. Ideally programmers want memory that is.

Operating Systems Memory Management. Mathieu Delalandre University of Tours, Tours city, France

Basic Memory Management

OPERATING SYSTEM. Chapter 9: Virtual Memory

Objectives and Functions Convenience. William Stallings Computer Organization and Architecture 7 th Edition. Efficiency

Chapter 4 Memory Management. Memory Management

Memory Management Cache Base and Limit Registers base limit Binding of Instructions and Data to Memory Compile time absolute code Load time

Virtual Memory. CSCI 315 Operating Systems Design Department of Computer Science

PROCESS VIRTUAL MEMORY. CS124 Operating Systems Winter , Lecture 18

Virtual Memory. Lecture for CPSC 5155 Edward Bosworth, Ph.D. Computer Science Department Columbus State University

Virtual Memory: Page Replacement. CSSE 332 Operating Systems Rose-Hulman Institute of Technology

Lecture 12: Demand Paging

Readings and References. Virtual Memory. Virtual Memory. Virtual Memory VPN. Reading. CSE Computer Systems December 5, 2001.

CS 31: Intro to Systems Virtual Memory. Kevin Webb Swarthmore College November 15, 2018

Virtual Memory - Overview. Programmers View. Virtual Physical. Virtual Physical. Program has its own virtual memory space.

Virtual Memory COMPSCI 386

Virtual or Logical. Logical Addr. MMU (Memory Mgt. Unit) Physical. Addr. 1. (50 ns access)

10: Virtual Memory Management

Chapter 4 Memory Management

Chapter 8: Virtual Memory. Operating System Concepts

Basic Memory Management. Basic Memory Management. Address Binding. Running a user program. Operating Systems 10/14/2018 CSC 256/456 1

CSCI 4717 Computer Architecture. Memory Management. What is Swapping? Swapping. Partitioning. Fixed-Sized Partitions (continued)

Course Outline. Processes CPU Scheduling Synchronization & Deadlock Memory Management File Systems & I/O Distributed Systems

TLB Recap. Fast associative cache of page table entries

SMD149 - Operating Systems - VM Management

Operating Systems. Operating Systems Sina Meraji U of T

CSE 4/521 Introduction to Operating Systems. Lecture 27 (Final Exam Review) Summer 2018

Paging Policies, Load control, Page Fault Handling, Case studies January WT 2008/09

Recap: Memory Management

Memory Allocation. Copyright : University of Illinois CS 241 Staff 1

Today. Adding Memory Does adding memory always reduce the number of page faults? FIFO: Adding Memory with LRU. Last Class: Demand Paged Virtual Memory

Chapters 7-8. Memory Management. Chapter 7 - Physical Memory. 7.1 Preparing a Program for Execution

VIRTUAL MEMORY READING: CHAPTER 9

Operating Systems (2INC0) 2017/18

How to create a process? What does process look like?

Chapter 8: Virtual Memory. Operating System Concepts Essentials 2 nd Edition

Chapter 4: Memory Management. Part 1: Mechanisms for Managing Memory

CPS104 Computer Organization and Programming Lecture 16: Virtual Memory. Robert Wagner

CPE300: Digital System Architecture and Design

Chapter 9: Virtual Memory

Optimal Algorithm. Replace page that will not be used for longest period of time Used for measuring how well your algorithm performs

Chapter 9 Real Memory Organization and Management

Chapter 9 Real Memory Organization and Management

Operating Systems. Overview Virtual memory part 2. Page replacement algorithms. Lecture 7 Memory management 3: Virtual memory

Memory Management. Goals of Memory Management. Mechanism. Policies

Chapter 7 Memory Management

The memory of a program. Paging and Virtual Memory. Swapping. Paging. Physical to logical address mapping. Memory management: Review

Address spaces and memory management

CS 333 Introduction to Operating Systems. Class 14 Page Replacement. Jonathan Walpole Computer Science Portland State University

Chapter 9 Memory Management Main Memory Operating system concepts. Sixth Edition. Silberschatz, Galvin, and Gagne 8.1

CISC 662 Graduate Computer Architecture Lecture 16 - Cache and virtual memory review

CHAPTER 3 RESOURCE MANAGEMENT

CS510 Operating System Foundations. Jonathan Walpole

CS 143A - Principles of Operating Systems

UNIT III MEMORY MANAGEMENT

Computer Architecture. Lecture 8: Virtual Memory

Memory Management Topics. CS 537 Lecture 11 Memory. Virtualizing Resources

Fall COMP3511 Review

Transcription:

Memory Management Virtual Memory Part of A3 course (by Theo Schouten) Biniam Gebremichael http://www.cs.ru.nl/~biniam/ Office: A6004 April 4 2005

Content Virtual memory Definition Advantage and challenges Virtual memory Paging Page table Transitional Lookaside Buffer (TLB) Virtual memory Segmentation Fetch policy Replacement policy Unix/Linux/Windows memory management 2/49

From Last Week Fixed and dynamic partition Paging and Segmentation Internal and External fragmentation Memory partition Fixed Dynamic Fixed Partition Dynamic Partiton Also Process partition Paging Segmentation 3/49

From last week Logical vs Physical address. Relocation allowed: A process may be swapped in and out of main memory such that it occupies different regions. A process can be broken up into pieces Contiguously not necessary All pieces of a process do not need to be loaded in main memory during execution. All pieces of a process do not have to be in the main memory during execution!! 4/49

Virtual Memory Keep only the active pieces (pages or segments) of the process in main memory. Inactive processes are kept in the secondary memory (hard disk). Advantages More processes can be maintained in the main memory, increases effective use of CPU. The main memory can execute a process bigger than its own capacity. 5/49

Challenges Who is active and who is inactive. Bad swapping results in Trashing. The heuristic principle of locality Expensive interrupt operation to retrieve inactive page/segment. Management complexity Extra hardware support needed The improvement gained by virtual memory is worth the difficulty introduced by it. 6/49

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 P1 Q2 P2 Q1 Q3 P3 P1 P2 P3 P4 P1 P2 P3 P4 P1 P1 P2 P3 P4 P1 P2 P1 P2 P3 P4 P1 P2 P3 P4 P1 P3 P2 7/49

Principle of Locality Program and data references within a process tend to cluster Only a few pieces of a process will be needed over a short period of time Possible to make intelligent guesses about which pieces will be needed in the future In practice virual memory works!! 8/49

Support Needed for Virtual Memory Hardware must support paging and segmentation Operating system must be able to management the movement of pages and/or segments between secondary memory and main memory 9/49

Paging and Page Tables 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 10/49

Modify Bit in Page Table Another modify bit is needed to indicate if the page has been altered since it was last loaded into main memory If no change has been made, the page does not have to be written to the disk when it needs to be swapped out 11/49

Page Table Entries P: page in memory? M: Modify bit Other control bit (OS specific) eg. Ageing... 12/49

Page Translation Virtual address Page number Offset Page table Physical address Frame number Offset Page # Page number P1 P2 P3 P4 Frame # Offset Frame number F4 F5 F10 F11 Offset 13/49

Page Starting bit 14/49

Page Tables The entire page table may take too much main memory space. Specially: With small size pages in 32-bit or higher addressing. 8000 entries in Windows2000 Solution: Store Page tables also in virtual memory When a process is running, part of its page table is in main memory 15/49

Translation Lookaside Buffer Each virtual memory reference can cause two physical memory accesses one to fetch the page table one to fetch the data To overcome this problem a high-speed cache is set up for page table entries called the TLB - Translation Lookaside Buffer Secondary memory TLB Main memory 16/49

Translation Lookaside Buffer Contains page table entries that have been most recently used TLB hit: page number in TLB TLB miss: page number in memory TLB page fault: page number in secondary memory. First load table and do like TLB miss Example: memory cache, proxy 17/49

18/49

19/49

Page Size Internal fragmentation Page table Pages in VM Page importing Small page size Small Large Few Large page size large small more Importing a page costs almost the same regardless of its size 20/49

Page Size Memory size and CPU speed grows, but TLB can not grow at the same rate. Complicate OS operations. Multiple (unequal) page sizes provide the flexibility needed to effectively use a TLB Example: Large pages can be used for program instructions Small pages can be used for threads Most operating system support only one page size. 21/49

Example Page Sizes 22/49

BREAK Segmentation Dynamic size Simplifies handling of growing data structures Process partitioning is easier. Allows programs to be altered and recompiled independently Sharing data among processes is easier Efficient protection 23/49

Segment Table Entries 24/49

Combined Paging and Segmentation Paging is transparent to the programmer Paging eliminates external fragmentation Equal page size, good for replacement policy Segmentation is visible to the programmer Segmentation allows for growing data structures, modularity, and support for sharing and protection Each segment is broken into fixed-size pages (paging after segmentation) 25/49

Combined Segmentation and Paging 26/49

27/49

Operating System Software Fetch Policy Demand and Prepaging Placement Policy Replacement Policy Algorithms Resident Set Management Cleaning Policy Load Control 28/49

Fetch Policy Fetch Policy: Determines when a page should be brought into memory Demand paging only brings pages into main memory when a reference is made to a location on the page Many page faults when process first started Prepaging brings in more pages than needed More efficient to bring in pages that reside contiguously on the disk. Exploit disk rotation latency Swapping follows the same 29/49

Placement Policy Where is a page placed? First-, worst-, best-fit algorithm. Distributed or Parallel computing with several processors accessing the same data. Placement is a serious design issue 30/49

Replacement Policy Issues to consider Avoid trashing How many should be replaced (prepaging?) Should a process replace its own page or not? Which one should be served first Page removed should be the page least likely to be referenced in the near future Most policies predict the future behavior on the basis of past behavior 31/49

Replacement Policy Frame Locking If frame is locked, it may not be replaced Example Kernel of the operating system Control structures I/O buffers Associate a lock bit with each frame 32/49

Basic Replacement Algorithms Optimal policy Selects for replacement that page for which the time to the next reference is the longest Impossible to have perfect knowledge of future events P1 Q2 P2 Q1 Q3 P3 P1 P2 P3 P4 P1 P2 P3 P4 P1 P1 P2 P3 P4 P1 P2 P1 P2 P3 P4 P1 P2 P3 P4 P1 P3 P2 33/49

Basic Replacement Algorithms Least Recently Used (LRU) Replaces the page that has not been referenced for the longest time By the principle of locality, this should be the page least likely to be referenced in the near future Each page could be tagged with the time of last reference (aging). This would require a great deal of overhead. (aging is not a bit) 34/49

Basic Replacement Algorithms First-in, first-out (FIFO) Treats page frames allocated to a process as a circular buffer Pages are removed in round-robin style Simplest replacement policy to implement Page that has been in memory the longest is replaced These pages may be needed again very soon 35/49

Basic Replacement Algorithms Clock Policy Additional bit called a use bit When a page is first loaded in memory, the use bit is set to 0 When the page is referenced, the use bit is set to 1 When it is time to replace a page, the first frame encountered with the use bit set to 0 is replaced. During the search for replacement, each use bit set to 1 is changed to 0 36/49

Replace Page 556 It is the next page with 0 use-bit 37/49

38/49

Resident Set Size Fixed-allocation gives a process a fixed number of pages within which to execute when a page fault occurs, one of the pages of that process must be replaced Variable-allocation number of pages allocated to a process varies over the lifetime of the process Local and Global scope. 39/49

Variable Allocation, Global Scope Easiest to implement Adopted by many operating systems Operating system keeps list of free frames Free frame is added to resident set of process when a page fault occurs If no free frame, replaces one from another process depending on page faults. 40/49

Variable Allocation, Local Scope When new process added, allocate number of page frames based on application type, program request, or other criteria When page fault occurs, select page from among the resident set of the process that suffers the fault Reevaluate allocation from time to time 41/49

Cleaning Policy Demand cleaning a page is written out only when it has been selected for replacement Precleaning pages are written out in batches Compare with fetch policy Demand paging, and Prepaging 42/49

Cleaning Policy Best approach uses page buffering Replaced pages are placed in two lists Modified and unmodified Pages in the modified list are periodically written out in batches later, to save time writing to disk is time consuming. Pages in the unmodified list are either reclaimed if referenced again or lost when its frame is assigned to another page 43/49

UNIX and Solaris Memory Management (Data Structures) Paging System Page table Disk block descriptor Page frame data table Swap-use table 44/49

Data Structures! 45/49

Data Structures 46/49

UNIX and Solaris Memory Management Page Replacement refinement of the clock policy Kernel Memory Allocator Uses different replacement policy for kernel Refinement of buddy system most blocks are smaller than a typical page size 47/49

Windows 2000 Memory Management 4 GB of virtual memory 2 OS 2 user space 1 OS 3 user space for servers W2K Paging Available: page not used. Available for use Reserved: page reserved for future use, but not yet used. Committed: page set aside for OS. 48/49

49/49