Memory Management. An expensive way to run multiple processes: Swapping. CPSC 410/611 : Operating Systems. Memory Management: Paging / Segmentation 1

Similar documents
Virtual Memory. Today. Handling bigger address spaces Speeding translation

SMD149 - Operating Systems - Memory

Virtual Memory 2. Today. Handling bigger address spaces Speeding translation

CS162 - Operating Systems and Systems Programming. Address Translation => Paging"

Virtual Memory 2. To do. q Handling bigger address spaces q Speeding translation

Virtual Memory 2. q Handling bigger address spaces q Speeding translation

Chapter 9 Memory Management

Memory management: outline

Memory management: outline

CPS 104 Computer Organization and Programming Lecture 20: Virtual Memory

Operating Systems. Paging... Memory Management 2 Overview. Lecture 6 Memory management 2. Paging (contd.)

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

CSE 451: Operating Systems Winter Page Table Management, TLBs and Other Pragmatics. Gary Kimura

Virtual Memory: From Address Translation to Demand Paging

Virtual Memory: Mechanisms. CS439: Principles of Computer Systems February 28, 2018

Chapter 8 Memory Management

Learning Outcomes. An understanding of page-based virtual memory in depth. Including the R3000 s support for virtual memory.

Memory Management. Dr. Yingwu Zhu

MEMORY MANAGEMENT/1 CS 409, FALL 2013

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

Lecture 13: Virtual Memory Management. CSC 469H1F Fall 2006 Angela Demke Brown

Learning Outcomes. An understanding of page-based virtual memory in depth. Including the R3000 s support for virtual memory.

Goals of Memory Management

File Systems. OS Overview I/O. Swap. Management. Operations CPU. Hard Drive. Management. Memory. Hard Drive. CSI3131 Topics. Structure.

Memory Management. Dr. Yingwu Zhu

CS 3733 Operating Systems:

CS5460: Operating Systems Lecture 14: Memory Management (Chapter 8)

Chapter 9: Memory Management. Background

Chapter 8 Main Memory

Virtual Memory. Daniel Sanchez Computer Science & Artificial Intelligence Lab M.I.T. November 15, MIT Fall 2018 L20-1

Module 8: Memory Management

Module 9: Memory Management. Background. Binding of Instructions and Data to Memory

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

Virtual Memory: From Address Translation to Demand Paging

Part Three - Memory Management. Chapter 8: Memory-Management Strategies

Operating Systems. 09. Memory Management Part 1. Paul Krzyzanowski. Rutgers University. Spring 2015

1. Creates the illusion of an address space much larger than the physical memory

CS 153 Design of Operating Systems Winter 2016

Virtual Memory. Daniel Sanchez Computer Science & Artificial Intelligence Lab M.I.T. April 12, 2018 L16-1

Module 8: Memory Management

Multi-level Translation. CS 537 Lecture 9 Paging. Example two-level page table. Multi-level Translation Analysis

Memory Management. Minsoo Ryu. Real-Time Computing and Communications Lab. Hanyang University.

16 Sharing Main Memory Segmentation and Paging

Topics: Memory Management (SGG, Chapter 08) 8.1, 8.2, 8.3, 8.5, 8.6 CS 3733 Operating Systems

CS307 Operating Systems Main Memory

Lecture 8 Memory Management Strategies (chapter 8)

Memory Management. Memory Management

8.1 Background. Part Four - Memory Management. Chapter 8: Memory-Management Management Strategies. Chapter 8: Memory Management

Chapter 8: Memory Management. Background Swapping Contiguous Allocation Paging Segmentation Segmentation with Paging

Memory Management (Chaper 4, Tanenbaum)

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

Virtual Memory. control structures and hardware support

Address Translation. Tore Larsen Material developed by: Kai Li, Princeton University

CIS Operating Systems Memory Management Address Translation for Paging. Professor Qiang Zeng Spring 2018

CHAPTER 8: MEMORY MANAGEMENT. By I-Chen Lin Textbook: Operating System Concepts 9th Ed.

Chapter 8: Memory-Management Strategies

Computer Architecture. Lecture 8: Virtual Memory

A Typical Memory Hierarchy

Outlook. Background Swapping Contiguous Memory Allocation Paging Structure of the Page Table Segmentation Example: The Intel Pentium

Memory Management. Memory

Chapter 8: Main Memory

CHAPTER 8 - MEMORY MANAGEMENT STRATEGIES

Chapter 8: Memory- Management Strategies. Operating System Concepts 9 th Edition

Memory Management Minsoo Ryu Real-Time Computing and Communications Lab. Hanyang University

Simple idea 1: load-time linking. Our main questions. Some terminology. Simple idea 2: base + bound register. Protection mechanics.

Memory management. Last modified: Adaptation of Silberschatz, Galvin, Gagne slides for the textbook Applied Operating Systems Concepts

CS 152 Computer Architecture and Engineering. Lecture 11 - Virtual Memory and Caches

A Typical Memory Hierarchy

Chapter 8: Main Memory

Chapter 8: Main Memory. Operating System Concepts 9 th Edition

Virtual Memory Virtual memory first used to relive programmers from the burden of managing overlays.

ECE468 Computer Organization and Architecture. Virtual Memory

Operating Systems, Fall

Operating Systems, Fall

Logical versus Physical Address Space

Main Memory. Electrical and Computer Engineering Stephen Kim ECE/IUPUI RTOS & APPS 1

Chapter 8: Main Memory

Reducing Hit Times. Critical Influence on cycle-time or CPI. small is always faster and can be put on chip

CS 162 Operating Systems and Systems Programming Professor: Anthony D. Joseph Spring Lecture 13: Address Translation

ECE4680 Computer Organization and Architecture. Virtual Memory

Chapter 8: Memory Management

Chapter 8: Memory Management Strategies

Virtual to physical address translation

Memory and multiprogramming

Memory Management (Chaper 4, Tanenbaum)

Recap: Memory Management

CS 333 Introduction to Operating Systems. Class 11 Virtual Memory (1) Jonathan Walpole Computer Science Portland State University

Chapter 8: Memory- Manage g me m nt n S tra r t a e t gie i s

File system internals Tanenbaum, Chapter 4. COMP3231 Operating Systems

MEMORY: SWAPPING. Shivaram Venkataraman CS 537, Spring 2019

Memory Management. Goals of Memory Management. Mechanism. Policies

CS 537 Lecture 6 Fast Translation - TLBs

Operating Systems Unit 6. Memory Management

CPE300: Digital System Architecture and Design

Chapter 8 Virtual Memory

CS399 New Beginnings. Jonathan Walpole

I.-C. Lin, Assistant Professor. Textbook: Operating System Principles 7ed CHAPTER 8: MEMORY

CS 152 Computer Architecture and Engineering. Lecture 9 - Address Translation

VIRTUAL MEMORY II. Jo, Heeseung

CS 550 Operating Systems Spring Memory Management: Paging

Transcription:

Memory Management Logical vs. physical address space Fragmentation Paging Segmentation An expensive way to run multiple processes: Swapping swap_out OS swap_in start swapping store memory ready_sw ready running waiting_sw jobs are on disk waiting jobs are in memory Memory Management: Paging / Segmentation 1

Memory Management Observations: 1. Process needs at least CPU and memory to run. 2. CPU context switching is relatively cheap. 3. Swapping memory in/out from/to disk is expensive. So, we need to subdivide memory to accommodate multiple processes! Q: How do we manage this memory? Requirements for Memory Management Relocation We do not know a priori where memory of process will reside. Protection No uncontrolled references to memory locations of other processes. Memory references must be checked at run-time. Sharing Ability to share data portions and program text portions. Logical organization Take advantage of semantics of use. Data portions (read/write) vs. program text portions (read only). Memory hierarchy RAM vs. secondary storage Swapping Memory Management: Paging / Segmentation 2

Logical vs. Physical Memory Space Logical address: address as seen by the process (i.e. as seen by the CPU). Physical address: address as seen by the memory. limit register relocation register CPU < + OS physical address space of process P i logical address space of process P i Memory Management Unit Physical Memory addressing error! partition table process base size P 1 28 1000 P 2 1028 3000 P 3 5034 250 Problem with simple Relocation: Fragmentation Internal Fragmentation?! OS 8MB 2MB 4MB 8MB 12MB External Fragmentation P 1 P 1 P 1 P 1 P 2 P 2 P 3 P 3? P 4 Memory Management: Paging / Segmentation 3

Paging Contiguous allocation causes (external) fragmentation. Solution: Partition memory blocks into smaller subblocks (pages) and allow them to be allocated non-contiguously. simple relocation Memory Management Unit logical memory paging Memory Management Unit physical memory logical memory physical memory Basic Operations in Paging Hardware CPU p d f d p f d page table Memory Management Unit physical memory Example: PDP-11 (16-bit address, 8kB pages) Memory Management: Paging / Segmentation 4

Example: Internal Fragmentation in Paging page size 4kB logical memory 13300B 4084 bytes wasted! physical memory Last frame allocated may not be completely full. Average internal fragmentation per block is typically half frame size. Large frames vs. small frames: Large frames cause more fragmentation. Small frames cause more overhead (page table size, disk I/O) Implementation of Page Table Page table involved in every access to memory. Speed very important. Page table in registers? Example: 1MB logical address space, 2kB page size; needs a page table with 512 entries! Page table in memory? Only keep a page table base register that points to location of page table. Each access to memory would require two accesses to memory! Cache portions of page table in registers? Use translation lookaside buffers (TLBs): typically a few dozens entries. Hit ratio: Percentage of time an entry is found. Hit ratio must be high in order to minimize overhead. Memory Management: Paging / Segmentation 5

Hierarchical (Multilevel) Paging Problem: Page tables can become very large! (e.g. 32-bit address space?) Solution: Page the page table itself! (e.g. page directory vs. page table) Two-level paging: Example: 32 bit logical address, page size 4kB page directory (10) page table (10) (12) page table base register f d f Three-level paging (SPARC), four-level paging (68030),... AMD64 (48-bit virtual addresses) has 4 levels. Even deeper for 64 bit address spaces (5 to 6 levels) Variations: Inverted Page Table proc id page no process id page no 0 1 2 3 3 n Array of page numbers indexed by frame number. page lookup: search for matching frame entry Size scales with physical memory. Single table for system (not per process) Used in early virt. memory systems, such as the Atlas computer. Not practical today. (Why?) Memory Management: Paging / Segmentation 6

Variations: Hashed Page Table page number hash function proc id page no frame no chain Used by many 64bit architectures: IBM POWER HP PA-RISC Itanium Scales with physical memory One table for whole system cons: How about collisions? Difficult to share memory between processes Software-loaded TLBs: Paging - MIPS Style Process no. ASID Program (virtual) address VPN Address within page TLB Page table (in memory) ASID VPN/Mask PFN Flags PFN Flags refill when necessary Physical address PFN Address within frame Memory Management: Paging / Segmentation 7

Recap: Memory Translation -- VAX style 1. Split virtual address 2. Concatenate more-significant bits with Process ASID to form page address. 3. Look in the TLB to see if we find translation entry for page. 4. If YES, take high-order physical address bits. (Extra bits stored with PFN control the access to frame.) 5. If NO, system must locate page entry in main-memoryresident page table, load it into TLB, and start again. Memory Translation -- MIPS Style In principle: Do the same as VAX, but with as little hardware as possible. Apart from register with ASID, the MMU is just a TLB. The rest is all implemented in software! When TLB cannot translate an address, a special exception (TLB refill) is raised. Note: This is easy in principle, but tricky to do efficiently. Memory Management: Paging / Segmentation 8

MIPS TLB Entry Fields input output VPN ASID G PFN Flags N D V VPN: higher order bits of virtual address ASID: identifies the address space G: if set, disables the matching with the ASID PFN: Physical frame number N: 0 - cacheable, 1 - noncacheable D: write-control bit (set to 1 if writeable) V: valid bit MIPS Translation Process 1. CPU generates a program (virtual) address on a instruction fetch, a load, or a store. 2. The 12 low-end bits are separated off. 3. Case 1: TLB matches key: 1. Matching entry is selected, and PFN is glued to low-order bits of the program address. 2. Valid?: The V and D bits are checked. If problem, raise exception, and set BadVAddr register with offending program address. 3. Cached?: IF C bit is set, the CPU looks in the cache for a copy of the physical location s data. If C bit is cleared, it neither looks in nor refills the cache. 4. Case 2: TLB does not match: TLB Refill Exception (see next page) Memory Management: Paging / Segmentation 9

TLB Refill Exception Figure out if this was a correct translation. If not, trap to handling of address errors. If translation correct, construct TLB entry. If TLB already full, select an entry to discard. Write the new entry into the TLB. Segmentation Users think of memory in terms of segments (data, code, stack, objects,...) Data within a segment typically has uniform access restrictions. paging Memory Management Unit segmentation logical memory Memory Management Unit physical memory logical memory physical memory Memory Management: Paging / Segmentation 10

Segmentation Hardware CPU s d <? + s limit base segment table Memory Management Unit physical memory Advantages of Segmentation Data in a segment typically semantically related Protection can be associated with segments read/write protection range checks for arrays Data/code sharing Disadvantages? sharing s d <? + s limit base s d <? + s limit base physical memory Memory Management: Paging / Segmentation 11

Example: MULTICS Solution: Paged Segmentation segment number 18bit 16bit Problem: 64kW segments -> external fragmentation! Solution: Page the segments. segment number page# page 18bit 6bit 10bit Problem: need 2^18 segment entries in segment table! Solution: Page the segment table. page# page page# page 8bit 10bit 6bit 10bit Memory Management: Paging / Segmentation 12