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

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

15 Sharing Main Memory Segmentation and Paging

CSL373: Operating Systems more VM fun

16 Sharing Main Memory Segmentation and Paging

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

Multi-level Page Tables & Paging+ segmentation combined

CS399 New Beginnings. Jonathan Walpole

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

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

Virtualizing Memory: Paging. Announcements

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

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

Memory Management. Dr. Yingwu Zhu

Virtual Memory 1. Virtual Memory

Virtual Memory. CS 351: Systems Programming Michael Saelee

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

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

Memory Management (Chaper 4, Tanenbaum)

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

Page Tables. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

Paging. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

Virtual Memory 1. Virtual Memory

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

Recap: Memory Management

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

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

Chapter 8 Memory Management

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

Paging. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Virtual Memory. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

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

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

CS 153 Design of Operating Systems Winter 2016

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

Memory Management (Chaper 4, Tanenbaum)

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

MEMORY: SWAPPING. Shivaram Venkataraman CS 537, Spring 2019

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

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

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

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

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

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

Agenda. CS 61C: Great Ideas in Computer Architecture. Virtual Memory II. Goals of Virtual Memory. Memory Hierarchy Requirements

Memory Management. Memory Management

EECS 482 Introduction to Operating Systems

CS 61C: Great Ideas in Computer Architecture. Virtual Memory

Changelog. Virtual Memory (2) exercise: 64-bit system. exercise: 64-bit system

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

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

Midterm 1. Administrivia. Virtualizing Resources. CS162 Operating Systems and Systems Programming Lecture 12. Address Translation

Virtual Memory. CS 3410 Computer System Organization & Programming

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

Chapter 9 Memory Management

Classifying Information Stored in Memory! Memory Management in a Uniprogrammed System! Segments of a Process! Processing a User Program!

CS 134: Operating Systems

Memory Hierarchy Requirements. Three Advantages of Virtual Memory

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

Lecture 17: Address Translation. James C. Hoe Department of ECE Carnegie Mellon University

COS 318: Operating Systems. Virtual Memory and Address Translation

Motivation. Memory Management. Memory Management. Computer Hardware Review

Virtual Memory. 11/8/16 (election day) Vote!

Recall from Tuesday. Our solution to fragmentation is to split up a process s address space into smaller chunks. Physical Memory OS.

Virtual Memory I. Jo, Heeseung

Modeling Page Replacement: Stack Algorithms. Design Issues for Paging Systems

Goals of memory management

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

Paging. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

Paging. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Address spaces and memory management

Memory management: outline

Memory management: outline

CPS 104 Computer Organization and Programming Lecture 20: Virtual Memory

Chapter 8: Main Memory

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

CSC 369 Operating Systems

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

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

Virtual Memory (2) 1

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

238P: Operating Systems. Lecture 5: Address translation. Anton Burtsev January, 2018

Virtual Memory. Kevin Webb Swarthmore College March 8, 2018

Virtual Memory Management

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

Background. Contiguous Memory Allocation

Chapter 8: Memory-Management Strategies

Goals of Memory Management

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

Virtual Memory. CS 3410 Computer System Organization & Programming. [K. Bala, A. Bracy, E. Sirer, and H. Weatherspoon]

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

CHAPTER 8 - MEMORY MANAGEMENT STRATEGIES

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

VIRTUAL MEMORY. Operating Systems 2015 Spring by Euiseong Seo

CIS Operating Systems Memory Management Address Translation. Professor Qiang Zeng Fall 2017

Computer Architecture Lecture 13: Virtual Memory II

Computer Science 146. Computer Architecture

Chapter 7: Main Memory. Operating System Concepts Essentials 8 th Edition

Memory Management. Goals of Memory Management. Mechanism. Policies

ECE4680 Computer Organization and Architecture. Virtual Memory

ECE 7650 Scalable and Secure Internet Services and Architecture ---- A Systems Perspective. Part I: Operating system overview: Memory Management

Transcription:

Our main questions! How is protection enforced?! How are processes relocated?! How is ory partitioned? Simple idea 1: load-time linking! Link as usual, but keep the list of references! At load time, determine where process will reside in ory and adjust all references (using addition). static a.out jump x2 x4 Prob 1: protection? Prob 2: how to move in ory? (Consider: data pointers) Prob 3: more than one ment? a.out jump x5 x6 Simple idea 2: base + bound register! Use hardware to solve problem: on every load and store relocation: physical addr = virtual addr + base register protection: check that address falls in [base, base+bound) a.out Base: jump x2 Bound: x2 x4 When process runs, base register =, bounds register = x2. Jump addr = x2 + = x5 How to move process in ory? What happens on process switch? a.out jump x2 x6 Some terminology! Definitions: program addresses are called logical or virtual addresses actual addresses are called physical or real addresses! Translation (or relocation) mechanism: Physical logical addrs addrs CPU ory Each load and store supplied virtual address translated to real address by (ory management unit) All other mechanisms for dynamic relocation use a similar organization. All lead to multiple (per process) views of ory, called address spaces Address spaces Logical Address View Physical Address View Protection mechanics! How to prevent users from changing base/bound register?! General mechanism: privileged instructions runs in privileged mode (set a bit in process status word) application processes run in user mode Certain instructions can only be issued in privileged mode (checked by hardware: illegal instruction trap)! How to switch? ( usually how its done, many variations) User->: application issues a system call, hardware then:» sets program counter to known address (can t trust user to)» updates process status word» and disables relocation ( has different address space) ->User:» sets base and bounds register (recall: relocation off)» issues an instruction that simultaneously (1) sets pc to given address, (2) turns relocation back on, and (3) lowers privilege.

Base & bound trade-offs! Pro: cheap in terms of hardware: only two registers cheap in terms of cycles: do add and compare in parallel examples: Cray-1! Con: only one ment prob 1: growing processes. Free space How to expand? bochs1 prob 2: how to share code and data?? how can bochs copies share code? prob 3: how to separate code and data? bochs2 p2! A solution: multiple ments mentation Segmentation! Big idea: let processes have many base&bounds ranges Process address space built from multiple ments. Each has its own base&bound values. Since we can now share, add protection bits for r/w Real ory x2 x5 x6 Text r/o Stack r/w Base&bound? x8 x6 Big result: Lets processes be split across ory!! Problem: how to specify what ment address refers to? Segmentation Mechanics! Each process has an array of its ments (ment table)! Each ory reference indicates a ment and offset: Top bits of addr select, low bits select offset (PDP-1) Seg select by instruction, or operand (pc selects text) Virtual addr 3 128 Seg# offset Seg table Prot base? len r 512 no yes fault + 128 Segmentation example! 2-bit ment number (1st digit), 12 bit offset (last 3) Seg base bounds rw x4 x6ff 1 physical logical 1 x x4ff 11 2 xfff 11 x4 x47 3! where is x24?! x118?! x265c?! x32?! x16? x2 x15 x7 x x4 x5 x Segmentation Tradeoffs! Pro: Multiple ments per process Allows sharing! (how?) Don t need entire process in ory!!! where?! Con: Extra layer of translation speed = hardware support More subtle: an n byte ment requires n *contiguous* bytes of physical ory. (why?) Makes fragmentation a real problem. Fragmentation! The inability to use ory that is free.! Over time: variable-sized pieces = many small holes (external frag.) fixed-sized pieces = no external holes, but force internal waste (internal fragmentation) Pintos?? allocated WoW heap External fragmentation Unused ( internal fragmentation )

Page based virtual ory! Quantize ory into fixed sized pieces ( pages ) Pages typical: 4k-8k! Tradeoff: pro: eliminates external fragmentation pro: simplifies allocation, free and swapping internal frag Page-based mechanics ory is divided into chunks of the same size (pages) each process has a table ( page table ) that maps virtual page numbers to corresponding physical page numbers» PT entry also includes protection bits (r, w, valid) translation process: virtual page number extracted from an address s upper bits and used as table index. Virtual addr 3 128 (12bits) VPN page offsetpage table Prot VPN PPN? PPN invalid r 3 1 ((1<<12) 128) 128 Page-based translation example! MIPS R2: 32 bit addr. space, 2-bit VPN and 12-bit offset: Page number page offset 2 bits 12 bits /* partial page table entry */ struct pte { unsigned ppn:2, valid:1, writeable:1; }; /* given virtual address and r/w indication, return physical addr. Uses a simple direct page table (I.e., an array) with (conceptually) an entry for every possible vpn */ unsigned xlate(unsigned va, int wr) { struct pte *pte = &page_table[va >> 12]; if(!pte->valid (wr &&!pte->writeable)) raise address_fault; return (pte->ppn << 12) (va & xfff); } Page tables vs. mentation! Good: Easy to allocate: keep a free list of available pages and grab the first one easy to swap since everything is the same size and since pages usually same size as disk blocks! Bad: size: PTs need one entry for each page-sized unit of virtual ory, vs one entry for every contiguous range.» e.g., given a range [x, xffff] need one ment descriptor but, assuming 4K pages, 16 page table entries B=x,len=xffff x Page table xffff Page size tradeoffs More Overhead locality page size Internal frag writeback cost! Small page = large PT overhead: 32-bit address space with 1K pages. How big PT?! Large page = internal frag. (doesn t match info. size) most Unix processes have few ments (code, data, stack, heap) so not much of a problem (except for page table ory itself) Paging + mentation: best of both?! Dual problems: Paged VM: simple page table = lots of storage Segmentation: All bytes in ment must map to contiguous set of storage locations. Makes paging problematic: all of in or none.! Idea: use paging + mentation! Map program w/ page table Map page table w/ table Call virtual address chunk a ment 4MB Phys heap text

Paging + mentation tradeoffs! Page-based virtual ory lets ments come from noncontiguous ory makes allocation flexible portion of ment can be on disk!! Segmentation = way to keep page table space manageable Page tables correspond to logical units (code, stack). Often relatively large. (But what happens if page tables really large?)! Going from paging to P+S is like going from single ment to multiple ments, except at a higher level. Instead of having a single page table, have many page tables with base and bound for each. Example: IBM System 37! System 37: 24 bit virtual address space (old machine): Seg # page # (8 bits) page offset (12 bits) (4 bits) 4 bits of ment # 8 bits of page # 12 bits of offset:! The mappings: Segment table: maps ment number to physical address & size of that ment s page table. Page table maps virtual page to 12 bit physical page #, which is concatenated to the 12 bit offset to get a 24 bit address 1 2 Example System 37 translation Base bound prot x2 x14 R x x xd RW Segment table Read of VA x27 x 2 7 x2216 read? x14c84 read? Page table (2-byte entries) SEG: page 2 * 2 bytes +x2 = x24 (x3 << 12 x7) = x37 Table entry addresses x1f x11 x22 x3 x2a x13 x2 xc x7 x12 x4 xb x6 P+S discussion! If ment not used then no need to have page table for it! Can share at two levels: single page or single ment (whole page table)! Pages eliminate external fragmentation and make it possible for ments to grow, page without shuffling! If page size small compared to most fragments then internal fragmentation not too bad (.5 of page per )! User not given write access to page tables read access can be quite useful (e.g., to let garbage collectors see dirty bits), but only experimental es provide this! If translation tables kept in main ory, overhead high 1 or 2 overhead reference for every real ref (I.e., op)! Other example systems: VAX, Multics, x86, Who won?! Simplicity = good (and fast): Most new architectures have gone with pages Examples: MIPS, SPARC, Alpha. And many old architectures have added paging even if they started with mentation!! But: to efficiently map large regions (both in page table and to save TLB entries) many new machines backsliding into super pages large, multi-page pages: have strict alignment restrictions; (typically) small # of sizes 32K alignment (VA%32K = ) 16K superpage 4K page inflexibility = speed, but handles 8% of the cases we want (e.g. that 8 MB frame buffer!) Virtual ory summary! VM gives flexibility + protection + speed (if clever)! Base & bounds = simple relocation + protection Pro: simple, fast Con: inflexible! Segmentation = generalization of base & bounds. Pro: Gives more flexible sharing and space usage Con: ments need contiguous physical ory ranges! Paging: instead of using extents, use fixed sized units Quantize ory into pages & use (page) table to map 3 virtual to physical pages