CPS110: Address translation Landon Cox February 19, 2008.

Slides:



Advertisements
Similar presentations
Memory Management: Overlays and Virtual Memory
Advertisements

OS Memory Addressing.
1 A Real Problem  What if you wanted to run a program that needs more memory than you have?
Virtual Memory & Address Translation Vivek Pai Princeton University.
CS 300 – Lecture 22 Intro to Computer Architecture / Assembly Language Virtual Memory.
Memory Management. 2 How to create a process? On Unix systems, executable read by loader Compiler: generates one object file per source file Linker: combines.
Memory Management 1 CS502 Spring 2006 Memory Management CS-502 Spring 2006.
CS-3013 & CS-502, Summer 2006 Memory Management1 CS-3013 & CS-502 Summer 2006.
Memory ManagementCS-502 Fall Memory Management CS-502 Operating Systems Fall 2006 (Slides include materials from Operating System Concepts, 7 th.
Memory Management Five Requirements for Memory Management to satisfy: –Relocation Users generally don’t know where they will be placed in main memory May.
Memory ManagementCS-3013 C-term Memory Management CS-3013 Operating Systems C-term 2008 (Slides include materials from Operating System Concepts,
03/22/2004CSCI 315 Operating Systems Design1 Virtual Memory Notice: The slides for this lecture have been largely based on those accompanying the textbook.
U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science Emery Berger University of Massachusetts, Amherst Operating Systems CMPSCI 377 Lecture.
03/17/2008CSCI 315 Operating Systems Design1 Virtual Memory Notice: The slides for this lecture have been largely based on those accompanying the textbook.
CS 346 – Chapter 8 Main memory –Addressing –Swapping –Allocation and fragmentation –Paging –Segmentation Commitment –Please finish chapter 8.
Review of Memory Management, Virtual Memory CS448.
Computer Architecture and Operating Systems CS 3230: Operating System Section Lecture OS-7 Memory Management (1) Department of Computer Science and Software.
Operating Systems Chapter 8
CS 153 Design of Operating Systems Spring 2015 Lecture 17: Paging.
COSC 3407: Operating Systems Lecture 13: Address Translation.
Lecture 11 Page 1 CS 111 Online Memory Management: Paging and Virtual Memory CS 111 On-Line MS Program Operating Systems Peter Reiher.
1 Address Translation Memory Allocation –Linked lists –Bit maps Options for managing memory –Base and Bound –Segmentation –Paging Paged page tables Inverted.
CE Operating Systems Lecture 14 Memory management.
PA0 due 60 hours. Lecture 4 Memory Management OSTEP Virtualization CPU: illusion of private CPU RAM: illusion of private memory Concurrency Persistence.
Chapter 4 Memory Management Virtual Memory.
By Teacher Asma Aleisa Year 1433 H.   Goals of memory management  To provide a convenient abstraction for programming.  To allocate scarce memory.
Review (1/2) °Caches are NOT mandatory: Processor performs arithmetic Memory stores data Caches simply make data transfers go faster °Each level of memory.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 9: Virtual Memory.
Operating Systems Lecture 14 Segments Adapted from Operating Systems Lecture Notes, Copyright 1997 Martin C. Rinard. Zhiqing Liu School of Software Engineering.
12/5/20151 Operating Systems Design (CS 423) Elsa L Gunter 2112 SC, UIUC Based on slides by Roy Campbell, Sam King,
CPS110: Page replacement Landon Cox. Replacement  Think of physical memory as a cache  What happens on a cache miss?  Page fault  Must decide what.
Review °Apply Principle of Locality Recursively °Manage memory to disk? Treat as cache Included protection as bonus, now critical Use Page Table of mappings.
Lecture Topics: 11/24 Sharing Pages Demand Paging (and alternative) Page Replacement –optimal algorithm –implementable algorithms.
Processes and Virtual Memory
CPS110: Intro to memory Landon Cox February 14, 2008.
Memory Management Continued Questions answered in this lecture: What is paging? How can segmentation and paging be combined? How can one speed up address.
COMP091 – Operating Systems 1 Memory Management. Memory Management Terms Physical address –Actual address as seen by memory unit Logical address –Address.
OS Memory Addressing. Architecture CPU – Processing units – Caches – Interrupt controllers – MMU Memory Interconnect North bridge South bridge PCI, etc.
Memory Management. 2 How to create a process? On Unix systems, executable read by loader Compiler: generates one object file per source file Linker: combines.
Memory Management Chapter 5 Advanced Operating System.
Lecture 4 Page 1 CS 111 Online Modularity and Memory Clearly, programs must have access to memory We need abstractions that give them the required access.
Chapter 8: Memory Management. 8.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 8: Memory Management Background Swapping Contiguous.
Scheduler activations Landon Cox March 23, What is a process? Informal A program in execution Running code + things it can read/write Process ≠
8 July 2015 Charles Reiss
Non Contiguous Memory Allocation
Segmentation COMP 755.
CS703 - Advanced Operating Systems
Outline Paging Swapping and demand paging Virtual memory.
Chien-Chung Shen CIS/UD
PA1 is out Best by Feb , 10:00 pm Enjoy early
Modularity and Memory Clearly, programs must have access to memory
Review: memory and address spaces
Chapter 8: Main Memory.
CSE 153 Design of Operating Systems Winter 2018
Main Memory Background Swapping Contiguous Allocation Paging
CS399 New Beginnings Jonathan Walpole.
Virtual Memory Hardware
Lecture 3: Main Memory.
CSE 451: Operating Systems Autumn 2005 Memory Management
CSE 451: Operating Systems Autumn 2003 Lecture 10 Paging & TLBs
CSE451 Virtual Memory Paging Autumn 2002
CSE 451: Operating Systems Autumn 2003 Lecture 9 Memory Management
Translation Buffers (TLB’s)
CSE 451: Operating Systems Autumn 2003 Lecture 10 Paging & TLBs
CSE 451: Operating Systems Autumn 2003 Lecture 9 Memory Management
CSE 153 Design of Operating Systems Winter 2019
Translation Buffers (TLBs)
Review What are the advantages/disadvantages of pages versus segments?
Chapter 8 & 9 Main Memory and Virtual Memory
Presentation transcript:

CPS110: Address translation Landon Cox February 19, 2008

 Translator: just a data structure  Tradeoffs  Flexibility (sharing, growth, virtual memory)  Size of translation data  Speed of translation Dynamic address translation User process Translator (MMU) Translator (MMU) Physical memory Physical memory Virtual address Physical address

1. Base and bounds  For each process  Single contiguous region of phys mem  Not allowed to access outside of region  Illusion own physical mem [0, bound)

1. Base and bounds Virtual memoryPhysical memory 0 Bound Base Base + Bound 0 Size of phys mem

1. Base and bounds  Translator algorithm  Only kernel can change base, bound if (virtual address > bound) { trap to kernel kernel can kill process with segmentation fault } else { physical address = virtual address + base }

2. Segmentation  Segment  Region of contiguous memory  (both virtually and physically)  Idea  Generalize base and bounds  Create a table of base and bound pairs

2. Segmentation Segment #BaseBound Segment Segment Segment 2Unused Segment Code Data segment Stack segment  Virtual address has two parts 1.Segment # (could be in high-order bits) 2.Offset (e.g. low-order bits of address) Virtual info Physical info Same for both

Virtual addresses VA={b 31,b 30,…,b 12,b 11,…,b 1,b 0 } Low-order bits (offset) High-order bits (segment number)

2. Segmentation Segment #BaseBound Segment Segment Segment 2Unused Segment Code Data segment Stack segment Virtual memory (3,fff). (Stack) (3,000) … (1,4ff). (Data) (1,000) … (0,6ff). (Code) (0,0) Physical memory 46ff. (Code segment) 4000 … 2fff. (Stack segment) 2000 … 4ff. (Data segment) 0 Segment # Offset

2. Segmentation Segment #BaseBound Segment Segment Segment 2Unused Segment Code Data segment Stack segment  Not all virtual addresses are valid  Nothing in segment 2  Nothing in segment 1 above 4ff  Valid = part of process’s address space  Accesses to invalid addresses are illegal  Hence a “segmentation fault” Virtual memory (3,fff). (Stack) (3,000) … (1,4ff). (Data) (1,000) … (0,6ff). (Code) (0,0)

2. Segmentation Segment #BaseBound Segment Segment Segment 2Unused Segment Code Data segment Stack segment  Segments can grow  (can move to new physical location)  Protection  Different protections for segments  E.g. read-only or read-write  B&B forced uniform protection Virtual memory (3,fff). (Stack) (3,000) … (1,4ff). (Data) (1,000) … (0,6ff). (Code) (0,0)

2. Segmentation Segment #BaseBound Segment Segment Segment 2Unused Segment Code Data segment Stack segment  What changes on a context switch?  Contents of segment table  Typically small (not many segments) Virtual memory (3,fff). (Stack) (3,000) … (1,4ff). (Data) (1,000) … (0,6ff). (Code) (0,0)

Segmentation pros and cons  Pros  Multiple areas of address space can grow separately  Easy to share parts of address space  (can share code segment)

Segmentation sharing Segment #BaseBound Segment Segment Segment 2Unused Segment Code Data segment Stack segment Segment #BaseBound Segment Segment Segment 2Unused Segment Code Data segment Stack segment Virtual infoPhysical info

Segmentation pros and cons  Pros  Multiple areas of address space can grow separately  Easy to share parts of address space  (can share code segment)  Cons  Complex memory allocation  (still have external fragmentation)

2. Segmentation  Do we get virtual memory?  (can an address space be larger than phys mem?)  Segments must be smaller than physical memory  Address space can contain multiple segments  Can swap segments in and out  What makes this tricky?  Performance (segments are relatively large)  Complexity (odd segment sizes  packing problem)  Solution: fixed-size segments called pages!

Course administration  Wednesday discussion section  Moved to D344 (same time)  Project 1 drawing to a close  Median score: 67% (not so hot)  Last semester at this time median was 98%  One group with 100% (another is close)  Some final tips …

Course administration  What to carefully reread  Section 4.4 of the spec (ordering stuff)  Thread implementation slides  Lock implementation slides  I see a lot of code that ignore these sources  Other hints …

Course administration /* * Allocate space for thread control block and * new stack. */ try { thread_ptr = new thread_t; thread_ptr->stack = NULL; thread_ptr->stack = new char [stack_size]; } catch(bad_alloc) { if (thread_ptr != NULL) { if (thread_ptr->stack != NULL) { delete [] thread_ptr->stack; } delete thread_ptr; } return(-1); }

Course administration  Project 2 (virtual memory) out next Thursday  In some ways easier than P1  In some ways harder than P1 (not given a solution)  Next deadline: midterm exam (February 26 th )  In-class  One sheet (two sides) of notes  No laptops or other electronic resources  Practice exam in discussion section this week

Midterm exam  What will be covered?  All threads/concurrency material  Project 1  Lectures  Homework problems

Analysis vs synthesis  No regurgitation questions  Analysis questions  Analyze system/program/design  Trace through program  Compute performance  Determine properties (deadlock, starvation, races)  Synthesis  Design/construct a new system/program/design  I like these more (e.g. learn the most doing projects)

How to study  Do homework problems  Understand Project 1  In groups  Create and answer questions I might ask  (you might get lucky; happened in past)

Syntax for programs  Real or pseudo is fine (just be clear)  STL is fine  queue.{push, pop, front, empty}  Monitors  Project 1 syntax or OO syntax  thread_lock (lock_num) or mutex.lock ()  Semaphores  OO syntax  sem1.up (), sem1.down (), sem2.up (), …  There is no “getVal” call!  Remember to specify initial value!!

Syntax for traces  Thread: line number (or range of lines) 1: checkMilk () { 2: if (noNote) { 3: leave note 4: if (noMilk){ 5: buy milk; 6: } 7: remove note; 8: } 9: } Landon: 1-2 Melissa: 1-2 Landon: 3-6 Melissa: 3-6

On-board review

3. Paging  Very similar to segmentation  Allocate memory in fixed-size chunks  Chunks are called pages  Why fixed-size pages?  Allocation is greatly simplified  Just keep a list of free physical pages  Any physical page can store any virtual page

3. Paging  Virtual addresses  Virtual page # (e.g. upper 20 bits)  Offset within the page (e.g. low 12 bits)  Each address refers to a byte of data  For 12-bit offset, how big are pages?  4KB (2^12 different offsets)

3. Paging  Translation data is a page table Virtual page #Physical page # invalid …… Invalid invalid 2^20 – 1 Why? Why no bound column?

3. Paging  Translation data is a page table Virtual page #Physical page # invalid …… Invalid invalid How does page table’s size compare to segment table’s? Page table must reside in memory. Too large for registers alone.

3. Paging  Translation process if (virtual page # is invalid) { trap to kernel } else { physical page = pagetable[virtual page].physPageNum physical address is {physical page}{offset} }

3. Paging  What happens on a context switch?  Copy out contents of entire page table  Copy new page table into translation box  (hideously slow)  Instead, use indirection  Change page table base pointer (register)  Should point to new page table  Does this look like anything else we’ve seen?  Stack pointer

3. Paging  Pages can be in memory or swapped to disk  “Swapped out” = “paged out”  How can the processor know?  Is it in physical memory or paged out to disk?  Page table entry must have more info  Resident bit

3. Paging  Resident bit in page table entry  If bit is 1 (vp is in physical memory)  Page table entry has valid translation  Use to look up physical page  If bit is 0 (vp is swapped out)  MMU causes a page fault to OS  (runs kernel’s page fault handler)  (just like how timer interrupts are handled)

3. Paging  On a page fault, what does the OS do?  OS finds free physical page  (may have to page out another virtual page)  OS does I/O to read virtual page into mem  (or zero fills it, if it’s a new page)  What happens next?  OS reruns process’s at last faulting instruction  How does it know the last instruction?  Hardware provides process’s PC to handler on fault

Valid vs. resident pages  Resident = page is in memory  Accessing non-resident pages is not an error  Access triggers page fault, OS handles it  Valid = page is legal to address  Who makes a virtual page resident (or not)?  OS memory manager (allocating physical memory)

Valid vs. resident pages  Resident = page is in memory  Accessing non-resident pages is not an error  Access triggers page fault, OS handles it  Valid = page is legal to address  Who makes a virtual page valid (or not)?  User process controls this (with limits from OS)

Valid vs. resident pages  Resident = page is in memory  Accessing non-resident pages is not an error  Access triggers page fault, OS handles it  Valid = page is legal to address  Why would a process make a page invalid?  Make the process fail-stop  Accidental/buggy references kill the process  Same for process making pages read-only  (writes to code segment are probably bugs)