Operating System Labs. Yuanbin Wu

Similar documents
Operating System Labs. Yuanbin Wu

CS 550 Operating Systems Spring Memory Management: Paging

Virtual Memory. Yannis Smaragdakis, U. Athens

Virtual Memory 1. To do. q Segmentation q Paging q A hybrid system

CS 471 Operating Systems. Yue Cheng. George Mason University Fall 2017

Paging: Introduction A Simple Example And Overview

Operating Systems. Pablo Prieto Torralbo. 3. Memory Virtualizing DEPARTMENT OF COMPUTER ENGINEERING

Virtual Memory. Today. Segmentation Paging A good, if common example

Virtualizing Memory: Paging. Announcements

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

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

Virtual Memory. Today. Handling bigger address spaces Speeding translation

Virtual memory - Paging

The process. one problem

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

(page 0 of the address space) (page 1) (page 2) (page 3) Figure 12.1: A Simple 64-byte Address Space

20. Paging: Smaller Tables

Virtual Memory I. Jo, Heeseung

CS399 New Beginnings. Jonathan Walpole

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

Administrivia. Lab 1 due Friday 12pm. We give will give short extensions to groups that run into trouble. But us:

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

CS 537 Lecture 6 Fast Translation - TLBs

11.1 Segmentation: Generalized Base/Bounds

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

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2018 Lecture 23

Virtual Memory. Physical Addressing. Problem 2: Capacity. Problem 1: Memory Management 11/20/15

Paging. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

MEMORY: SWAPPING. Shivaram Venkataraman CS 537, Spring 2019

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

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

Fall 2017 :: CSE 306. Introduction to. Virtual Memory. Nima Honarmand (Based on slides by Prof. Andrea Arpaci-Dusseau)

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2015 Lecture 23

EECS 482 Introduction to Operating Systems

14 May 2012 Virtual Memory. Definition: A process is an instance of a running program

Paging. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Paging. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

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

Virtual Memory 1. Virtual Memory

Virtual Memory 1. Virtual Memory

Virtual Memory. CS61, Lecture 15. Prof. Stephen Chong October 20, 2011

Main Memory: Address Translation

15. Address Translation

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

Memory Hierarchy. Goal: Fast, unlimited storage at a reasonable cost per bit.

A Few Problems with Physical Addressing. Virtual Memory Process Abstraction, Part 2: Private Address Space

Memory Hierarchy Requirements. Three Advantages of Virtual Memory

CS 153 Design of Operating Systems Winter 2016

Virtual Memory. Computer Systems Principles

198:231 Intro to Computer Organization. 198:231 Introduction to Computer Organization Lecture 14

VIRTUAL MEMORY. Operating Systems 2015 Spring by Euiseong Seo

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

Address spaces and memory management

Recap: Memory Management

Paging. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

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

Virtual Memory: From Address Translation to Demand Paging

Computer Systems. Virtual Memory. Han, Hwansoo

CS 5523 Operating Systems: Memory Management (SGG-8)

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

Virtual Memory. CS 3410 Computer System Organization & Programming

Virtual Memory. Motivations for VM Address translation Accelerating translation with TLBs

CPS 104 Computer Organization and Programming Lecture 20: Virtual Memory

The UtePC/Yalnix Memory System

Virtual Memory. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

Mechanism: Address Translation

Lecture 19: Virtual Memory: Concepts

Chapter 8. Virtual Memory

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

CSE 153 Design of Operating Systems

Another View of the Memory Hierarchy. Lecture #25 Virtual Memory I Memory Hierarchy Requirements. Memory Hierarchy Requirements

Lecture 21: Virtual Memory. Spring 2018 Jason Tang

EECS 470. Lecture 16 Virtual Memory. Fall 2018 Jon Beaumont

Virtual Memory II CSE 351 Spring

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

Virtual Memory Oct. 29, 2002

virtual memory Page 1 CSE 361S Disk Disk

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

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

Memory Management. Dr. Yingwu Zhu

Virtual Memory Nov 9, 2009"

Memory Management. Disclaimer: some slides are adopted from book authors slides with permission 1

Chapter 5. Large and Fast: Exploiting Memory Hierarchy

CSE 351. Virtual Memory

! What is main memory? ! What is static and dynamic allocation? ! What is segmentation? Maria Hybinette, UGA. High Address (0x7fffffff) !

UC Berkeley CS61C : Machine Structures

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

virtual memory. March 23, Levels in Memory Hierarchy. DRAM vs. SRAM as a Cache. Page 1. Motivation #1: DRAM a Cache for Disk

CSE 120 Principles of Operating Systems

Virtual Memory Worksheet

PROCESS VIRTUAL MEMORY. CS124 Operating Systems Winter , Lecture 18

CISC 360. Virtual Memory Dec. 4, 2008

Carnegie Mellon. Bryant and O Hallaron, Computer Systems: A Programmer s Perspective, Third Edition

Protection. - Programmers typically assume machine has enough memory - Sum of sizes of all processes often greater than physical memory 1 / 36

ECE 598 Advanced Operating Systems Lecture 14

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

Processes, Address Spaces, and Memory Management. CS449 Spring 2016

- Established working set model - Led directly to virtual memory. Protection

Carnegie Mellon. 16 th Lecture, Mar. 20, Instructors: Todd C. Mowry & Anthony Rowe

Virtual Memory: From Address Translation to Demand Paging

Transcription:

Operating System Labs Yuanbin Wu cs@ecnu

Operating System Labs Review of Memory Management

Early days Memory Management

Memory Management Multiprogramming and Time Sharing Multiple processes live in memory simutaneously Easy-to-use virtualization of memory

Memory Management Virtualize memory Address space

Memory Management Goals of Virtualize Memory Transparency Efficiency Protection

Memory Management Virtualize Memory From the programmer's point of view: Every address is fraud Only OS know the truth

Memory Management Virtualize Memory Limited Direct Execute Hardware: transparency, efficiency, protection OS: configure hardware correctly manage free memory handle exception Hardware-based address translation

Memory Management Hardware: Transparency We starts with a simple idea called Base and bounds Dynamical (hardware-based) allocation

An Example void func () { int x; x = x + 3; } 128: movl 0x0(%ebx), %eax ;load 0+ebx into eax 132: addl $0x03, %eax ;add 3 to eax register 135: movl %eax, 0x0(%ebx) ;store eax back to mem Fetch instruction at address 128 Execute this instruction (load from address 15 KB) Fetch instruction at address 132 Execute this instruction (no memory reference) Fetch the instruction at address 135 Execute this instruction (store to address 15 KB)

Address space Physical Memory Hardware: - 2 register in CPU - Base: the start of phy mem - Bound: the size of phy mem physical = virtual + base Base: 32K Bound: 16K

physical = virtual + base Address Space Physical Memory Fetch instruction at address 128 Execute (load from address 15 KB) Fetch instruction at address 132 Execute (no memory reference) Fetch the instruction at address 135 Execute (store to address 15 KB) Visiting address 128 128 + 32K = 128 + 32768 = 32896 Base: 32K Bound: 16K

physical = virtual + base Address Space Physical Memory Fetch instruction at address 128 Execute (load from address 15 KB) Fetch instruction at address 132 Execute (no memory reference) Fetch the instruction at address 135 Execute (store to address 15 KB) 128: movl 0x0(%ebx), %eax 15K + 32K = 47K Base: 32K Bound: 16K

Memory Management Hardware: Protection Bounds reg Raise an exception when the required address is illegal Know how to do when exceptions are raised E.g. Base: 0 Bound: 4K Then address 4400 is illegal according to the Bound

Memory Management Hardware: Efficiency The registors are in CPU chip The part of CPU related to address translation is called: MMU (memory management unit)

Memory Management Hardware requirements summary Privileged mode Base/bounds registers Ability to translate virtual addresses and check if within bounds Privileged instruction(s) to update base/bounds Privileged instruction(s) to register exception handlers Ability to raise exceptions

Memory Management OS: Maintain a data structure: free list Find place in physical memory for a process when creating it Collect the space when a process terminate Context switch Correctly config base / bound registor Handle exception

Memory Management Two implementation of virtual memory Segmentation Paging

Segmentation Base and Bound Load entire address space The problem: Can not be used by other processes Wasteful Motivation How to support large address space

Segmentation Solution: Multiple base/bound 3 logical segmentations Code Stack Heap 3 groups of base/bound registers

Segmentation Multiple base/bound Physical memroy Segmentation Base Size Code 32K 2K Heap 34K 2K Stack 28K 2K

Example: multiple base/bound Visit virtual memory 100 Address translation: 32K+100 = 32868 Address checking: 100 < 2K Visit physical memory: 32868 Segmentati on Base Size Code 32K 2K Heap 34K 2K Stack 28K 2K

Example: multiple base/bound Visit virtual memory 4200 Address translation: 34K+(4200-4K)=34920 Address checking: 104 < 2K Visit physical memory: 34920 Segmentati on Base Size Code 32K 2K Heap 34K 2K Stack 28K 2K

Example: multiple base/bound Visit virtual memory 4200 Address translation: 34K+(4200-4K)=34920 Address checking: 104 < 2K Visit physical memory: 34920 Problem: How we know 4200 is at heap? How to interprete an virtual address?

Segmentation Which Segmentation are We Refering to Explicit approach top few bits of the virtual address Example: 16K address space 14 bit

Segmentation Which Segmentation are We Refering to Example: 4200

Segmentation Which Segmentation are We Refering to // get top 2 bits of 14-bit VA Segment = (VirtualAddress & SEG_MASK) >> SEG_SHIFT // now get offset Offset = VirtualAddress & OFFSET_MASK if (Offset >= Bounds[Segment]) RaiseException(PROTECTION_FAULT) else PhysAddr = Base[Segment] + Offset Register = AccessMemory(PhysAddr)

Segmentation What about the stack Difference growth backwards 28K - 26K Segmentation Base Size Code 32K 2K Heap 34K 2K Stack 28K 2K

Segmentation What about the stack Solution: extra hardware support one bit in MMU 1: growth in positve direction 0: growth in negative direction Segmentati on Base Size Grows Postive Code 32K 2K 1 Heap 34K 2K 1 Stack 28K 2K 0

Example: multiple base/bound Visit virtual memory 15K 11 11 00 00 00 00 00 Address translation: [1] segment = 11 stack reg [2] offset = 3K [3] maximum segment = 4K [4] 3K 4K = -1K [5] physical addr: 28K + (-1K)= 27K Address checking: -1K < 2K Visit physical memory: 27K Segmentation Base Size Grows Postive Code 32K 2K 1 Heap 34K 2K 1 Stack 28K 2K 0

Segmentation Support for Sharing Protection bit Segmentatio n Base Size Grows Postive Protection Code 32K 2K 1 Read- Execute Heap 34K 2K 1 Read-Write Stack 28K 2K 0 Read-Write

Segmentation Summary Base/Bound registers in MMU Multiple Base/Bound Growth direction Protection Problem Where to place new address spaces External fragmentation Free memory management

Paging Segmentation Spliting address space with variable size logical segmentations Paging Divide address space into fixed size units (pages)

Example: Paging 64 Byte address space 16 Byte page 128 Byte physical memory Pages of the virtual address space are placed at different locations throughout physical memory

Paging Advantages Flexible make no assumptions about the direction the heap/stack grow, how they are used. Simple Simple free memory management A free list of free pages

Paging Virtual page physical frame Page Table A data structure VP0 PF3 VP1 PF7 VP2 PF5 VP3 PF2 In each process

Paging Address translation Virtual address: Virtual Page Num (VPN) Offset Example 64 Byte virtual address 16 Byte page

Address translation movl 21, %eax Binary of 21: 010101 5 th byte (0101) of 1 st virtual page (01) VP1 FP7

Address translation Paging

Paging Questions Where are page tables stored? What are the typical contents of the page table? How big are the tables? Does paging make the system (too) slow?

Paging How big are the tables? 32bit address space 4K page size 20bit VPN + 12bit offset 2 20 = 1M translations that the OS would manage For each process! Page Table Entry (PTE) 4 Byte Page table size: 2 20 * 4 = 4M If we have 100 active processes: 400M How about 64bit systems?

Paging Where are page tables stored? Not in MMU (so big) In OS's memory Physical memory managed by OS Virtual memory of OS (can be swapped out)

Paging What's actually in a page table? Page Table Entry (PTE) An array (linear page table) OS indexes the array with VPN PTE PFN Valid bit Protection bit Present bit Dirty bit Reference bit

Paging Too slow VPN = (VirtualAddress & VPN_MASK) >> SHIFT PTEAddr = PageTableBaseRegister + (VPN * sizeof(pte)) Example int array[1000];... for (i = 0; i < 1000; i++) array[i] = 0; 0x1024 movl $0x0, (%edi,%eax,4) 0x1028 incl %eax 0x102c cmpl $0x03e8, %eax 0x1030 jne 0x1024

Too slow Paging

Paging Faster translation With the help of hardware (in MMU) Translation Lookaside Buffer (TLB) Cache Temporal and spatial locality Smaller page table Hybrid segmentaion and paging Multi-layer page table