EECS 482 Introduction to Operating Systems

Similar documents
Address spaces and memory management

EECS 482 Introduction to Operating Systems

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

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

Memory: Paging System

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

CPS 104 Computer Organization and Programming Lecture 20: Virtual Memory

Multi-level Page Tables & Paging+ segmentation combined

Page Tables. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

Memory Hierarchy Requirements. Three Advantages of Virtual Memory

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

CS162 Operating Systems and Systems Programming Lecture 12. Address Translation. Page 1

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

CSE 120 Principles of Operating Systems

15 Sharing Main Memory Segmentation and Paging

Main Memory: Address Translation

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

Outline. V Computer Systems Organization II (Honors) (Introductory Operating Systems) Advantages of Multi-level Page Tables

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

CS3600 SYSTEMS AND NETWORKS

Address Translation. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

CS 153 Design of Operating Systems Winter 2016

Memory Management. Dr. Yingwu Zhu

Recall: Address Space Map. 13: Memory Management. Let s be reasonable. Processes Address Space. Send it to disk. Freeing up System Memory

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

16 Sharing Main Memory Segmentation and Paging

ECE 571 Advanced Microprocessor-Based Design Lecture 12

Page 1. Review: Address Segmentation " Review: Address Segmentation " Review: Address Segmentation "

Operating Systems (1DT020 & 1TT802) Lecture 9 Memory Management : Demand paging & page replacement. Léon Mugwaneza

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

Virtual Memory. Kevin Webb Swarthmore College March 8, 2018

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

Chapter 8 Memory Management

COSC3330 Computer Architecture Lecture 20. Virtual Memory

VIRTUAL MEMORY II. Jo, Heeseung

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

Multi-Process Systems: Memory (2) Memory & paging structures: free frames. Memory & paging structures. Physical memory

CS 318 Principles of Operating Systems

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

Virtual Memory. control structures and hardware support

EECS 482 Introduction to Operating Systems

6 - Main Memory EECE 315 (101) ECE UBC 2013 W2

Paging. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

Paging. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Paging. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Lecture 13: Address Translation

CSE 120 Principles of Operating Systems Spring 2017

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

Virtual Memory Review. Page faults. Paging system summary (so far)

Today: Segmentation. Last Class: Paging. Costs of Using The TLB. The Translation Look-aside Buffer (TLB)

CS162 Operating Systems and Systems Programming Lecture 11 Page Allocation and Replacement"

ecture 33 Virtual Memory Friedland and Weaver Computer Science 61C Spring 2017 April 12th, 2017

Lecture 21: Virtual Memory. Spring 2018 Jason Tang

CS162 Operating Systems and Systems Programming Lecture 14. Caching (Finished), Demand Paging

UC Berkeley CS61C : Machine Structures

CS 134: Operating Systems

CS252 S05. Main memory management. Memory hardware. The scale of things. Memory hardware (cont.) Bottleneck

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

memory management Vaibhav Bajpai

Paging! 2/22! Anthony D. Joseph and Ion Stoica CS162 UCB Fall 2012! " (0xE0)" " " " (0x70)" " (0x50)"

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

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

Operating Systems. Memory Management. Lecture 9 Michael O Boyle

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

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

CS399 New Beginnings. Jonathan Walpole

The Virtual Memory Abstraction. Memory Management. Address spaces: Physical and Virtual. Address Translation

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

Virtual Memory #2 Feb. 21, 2018

Virtual Memory. Virtual Memory

CS162 Operating Systems and Systems Programming Lecture 10 Caches and TLBs"

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

Goals of Memory Management

CS 61C: Great Ideas in Computer Architecture (Machine Structures) Intro to Virtual Memory

Principles of Operating Systems

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

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

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

PROCESS VIRTUAL MEMORY. CS124 Operating Systems Winter , Lecture 18

CS370 Operating Systems

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

Virtual Memory 1. Virtual Memory

Virtual to physical address translation

EECS 482 Introduction to Operating Systems

Memory Management. Goals of Memory Management. Mechanism. Policies

Lecture 4: Memory Management & The Programming Interface

John Wawrzynek & Nick Weaver

Main Memory (Fig. 7.13) Main Memory

Paging. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

Recap: Memory Management

Lecture 19: Virtual Memory: Concepts

Memory Management. Memory Management

Virtual Memory. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

CS399 New Beginnings. Jonathan Walpole

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

10/7/13! Anthony D. Joseph and John Canny CS162 UCB Fall 2013! " (0xE0)" " " " (0x70)" " (0x50)"

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

Chapter 8 & Chapter 9 Main Memory & Virtual Memory

Chapter 3 - Memory Management

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

Transcription:

EECS 482 Introduction to Operating Systems Fall 2018 Baris Kasikci Slides by: Harsha V. Madhyastha

Base and bounds Load each process into contiguous region of physical memory Prevent process from accessing data outside its region Base register: starting physical address Bound register: size of region physical memory base + bound bound virtual memory base 0 0 February 12, 2018 EECS 482 Lecture 12 2

Base and bounds Pros? Fast Simple hardware support Cons? Virtual address space limited by physical memory No controlled sharing External fragmentation February 12, 2018 EECS 482 Lecture 12 3

Base and bounds Can t share part of an address space between processes physical memory data (P2) virtual address space 1 data code data (P1) code virtual address space 2 data code February 12, 2018 EECS 482 Lecture 12 4

External fragmentation Processes come and go, leaving a mishmash of available memory regions Wasted memory between allocated regions P1 P2 P5 P3 P4 February 12, 2018 EECS 482 Lecture 12 5

Growing address space physical memory base + bound bound 0 virtual memory Stack Heap base 0 How can stack and heap grow independently? February 12, 2018 EECS 482 Lecture 12 6

Segmentation Divide address space into segments Segment: region of memory contiguous in both physical memory and in virtual address space Multiple segments of memory with different base and bounds. February 12, 2018 EECS 482 Lecture 12 7

Segmentation virtual memory segment 3 physical memory fff stack 46ff 4000 code 0 4ff 0 virtual memory segment 1 data 2fff 2000 stack 6ff 0 virtual memory segment 0 code February 12, 2018 4ff 0 data EECS 482 Lecture 12 8

Segmentation Segment # Base Bounds Description 0 4000 700 code segment 1 0 500 data segment 2 n/a n/a unused 3 2000 1000 stack segment Virtual address is of the form: (segment #, offset) Physical address = base for segment + offset Many ways to specify the segment # High bits of address Special register Implicit to instruction opcode February 12, 2018 EECS 482 Lecture 12 9

Segmentation Segment # Base Bounds Description 0 4000 700 code segment 1 0 500 data segment 2 n/a n/a unused 3 2000 1000 stack segment Physical address for virtual address (3, 100)? 2100 Physical address for virtual address (0, ff)? 40ff Physical address for virtual address (2, ff)? Physical address for virtual address (1, 2000)? February 12, 2018 EECS 482 Lecture 12 10

Segmentation Not all virtual addresses are valid Valid à region is part of process s address space Invalid à virtual address is illegal to access» Accessing an invalid virtual address causes a trap to OS (usually resulting in core dump) Reasons for virtual address being invalid? Invalid segment number Offset within valid segment beyond bound February 12, 2018 EECS 482 Lecture 12 11

Segmentation How to grow a segment? Different segments can have different protection E.g., code is usually read only (allows fetch, load) E.g., data is usually read/write (allows fetch, load, store) Fine-grained protection in base and bounds? What must be changed on a context switch? February 12, 2018 EECS 482 Lecture 12 12

Benefits of Segmentation Multiple areas of address space can grow separately Easy to share part of address space Segment # Base Bounds Description Process 1 0 4000 700 code segment 1 0 500 data segment 3 2000 1000 stack segment Segment # Base Bounds Description Process 2 0 4000 700 code segment 1 1000 300 data segment 3 500 1000 stack segment February 12, 2018 EECS 482 Lecture 12 13

Drawbacks of Segmentation Have we eliminated external fragmentation? Can an address space be larger than physical memory? How can we: Make memory allocation easy Not have to worry about external fragmentation Allow address space size to be > physical memory February 12, 2018 EECS 482 Lecture 12 14

Project 2 Due in 6 days Check calendar on web page for extra office hours For every thread, think about where is the current context? Think about memory leaks and how to test if they exist Think about why your thread library may cause a program to run for longer than correct library February 12, 2018 EECS 482 Lecture 12 15

Drawbacks of Segmentation Have we eliminated external fragmentation? Can an address space be larger than physical memory? How can we: Make memory allocation easy Not have to worry about external fragmentation Allow address space size to be > physical memory February 12, 2018 EECS 482 Lecture 12 16

Drawbacks of Segmentation October 19, 2017 EECS 482 Lecture 13 17

Paging Allocate physical memory in fixed-size units (pages) Any free physical page can store any virtual page October 19, 2017 EECS 482 Lecture 13 18

Paging Virtual address is split into Virtual page # (high bits of address, e.g., bits 31-12) Offset (low bits of address, e.g., bits 11-0, for 4 KB page size) Physical Memory Address Space Page 1 Page 2 Page 3 Page N October 19, 2017 EECS 482 Lecture 13 19

Paging Translation data is the page table Virtual page # Physical page # 0 105 1 15 2 283 3 invalid... invalid 1048575 invalid Why no column for bound? How do I check whether offset is within bound? One entry per virtual page à Lots of entries! October 19, 2017 EECS 482 Lecture 13 20

Page Lookups Physical Memory Virtual Address Page number Offset Page Table Physical Address Page frame Offset Page frame October 19, 2017 EECS 482 Lecture 13 21

Paging Translating virtual address to physical address if (virtual page is invalid) { trap to OS fault handler } else { physical page # = pagetable[virtual page #].physpagenum } What must be changed on a context switch? Page table (but can be large) Use indirection: Page Table Base Register» Points to physmem address of page table October 19, 2017 EECS 482 Lecture 13 22

Paging out Each virtual page can be in physical memory or paged out to disk How does processor know that a virtual page is not in physical memory? Virt. page # Phys. page # resident 0 105 1 1 15 0 2 283 1 3 invalid invalid if (virtual page is invalid or non-resident) { trap to OS fault handler; retry } else { physical page # = pagetable[virtual page #].physpagenum } October 12, 2017 EECS 482 Lecture 12 23

Paging Like segments, pages can have different protections (e.g., read, write, execute) Virt. page # Phys. page # resident protected 0 105 1 0 1 15 0 0 2 283 1 1 3 invalid invalid if (virtual page is invalid or non-resident or protected) { trap to OS fault handler; retry } else { } physical page # = pagetable[virtual page #].physpagenum October 12, 2017 EECS 482 Lecture 12 24

Valid versus resident Valid à virtual page is legal for process to access Resident à virtual page is in physical memory Error to access invalid page, but not to access non-resident page Who makes a virtual page resident/non-resident? Who makes a virtual page valid/invalid? Why would a process want one of its virtual pages to be invalid? October 12, 2017 EECS 482 Lecture 12 25

Picking Page Size What happens if page size is really small? What happens if page size is really big? Typically a compromise, e.g., 4 KB or 8 KB Some architectures support multiple page sizes What must be changed on a context switch? October 19, 2017 EECS 482 Lecture 13 26

Growing Address Space Stack Heap Code Virtual page # Physical page # 0 105 1 15 2 283 3 invalid... invalid 1048572 invalid 1048573 1078 1048574 48136 1048575 60 How is this better than base and bounds? October 19, 2017 EECS 482 Lecture 13 27

Paging Pros? Flexible memory allocation/growing address space Virtual memory No external fragmentation Flexible sharing Cons? Large page tables How to modify paging to reduce space needed for translation data? October 19, 2017 EECS 482 Lecture 13 28

Multi-level Paging Standard page table is a simple array Multi-level paging generalizes this into a tree Example: Two-level page table with 4KB pages Index into level 1 page table: virtual address bits 31-22 Index into level 2 page table: virtual address bits 21-12 Page offset: bits 11-0 October 19, 2017 EECS 482 Lecture 13 29

Multi-level Paging level 1 page table 0 1 2 3 level 2 page tables virtual address bits 21-12 physical page # 0 10 1 15 2 20 3 2 virtual address bits 21-12 physical page # 0 30 1 4 2 8 3 3 How does this let translation data take less space? October 19, 2017 EECS 482 Lecture 13 30

Sparse Address Space Stack Heap Code Virtual page # Physical page # 0 105 1 15 2 283 3 invalid... invalid 1048572 invalid 1048573 1078 1048574 48136 1048575 60 October 19, 2017 EECS 482 Lecture 13 31

Sparse Address Space Bits 31-22 Physical page # 0 389 1 invalid 2 invalid invalid 1021 invalid 1022 invalid 1023 7046 Bits 21-12 Physical page # 0 105 1 15 2 283 3 invalid... invalid Bits 21-12 Physical page #... invalid 1020 invalid 1021 1078 1022 48136 1023 60 October 19, 2017 EECS 482 Lecture 13 32

Multi-level paging How to share memory between address spaces? What must be changed on a context switch? Pros: Easy memory allocation Flexible sharing Space efficient for sparse address spaces Cons? Two extra lookups per memory reference October 19, 2017 EECS 482 Lecture 13 33

Translation lookaside buffer TLB caches virtual page # to PTE mapping Cache hit à Skip all the translation steps Cache miss à Get PTE, store in TLB, restart instruction Does this change what happens on a context switch? October 19, 2017 EECS 482 Lecture 13 34