Virtualization Virtualize hardware resources through abstraction CPU

Slides:



Advertisements
Similar presentations
PA0 due today Anyone tried to submit?. Scheduling Workload assumptions Arrive time, run time, I/O, etc. Policies: FIFO, SJF, STCF, RR, MLFQ, and lottery.
Advertisements

MODERN OPERATING SYSTEMS Third Edition ANDREW S. TANENBAUM Chapter 3 Memory Management Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall,
Chapter 15 Address Translation Chien-Chung Shen CIS, UD
Memory Management Questions answered in this lecture: How do processes share memory? What is static relocation? What is dynamic relocation? What is segmentation?
Chapter 6 Limited Direct Execution
CS 153 Design of Operating Systems Spring 2015
1 Operating Systems and Protection CS Goals of Today’s Lecture How multiple programs can run at once  Processes  Context switching  Process.
1 Operating Systems and Protection Professor Jennifer Rexford CS 217.
Memory Management 2010.
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.
Computer Organization and Architecture
U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science Emery Berger University of Massachusetts, Amherst Operating Systems CMPSCI 377 Lecture.
Layers and Views of a Computer System Operating System Services Program creation Program execution Access to I/O devices Controlled access to files System.
Memory Management CSE451 Andrew Whitaker. Big Picture Up till now, we’ve focused on how multiple programs share the CPU Now: how do multiple programs.
Chapter 5 Operating System Support. Outline Operating system - Objective and function - types of OS Scheduling - Long term scheduling - Medium term scheduling.
Memory Management 3 Tanenbaum Ch. 3 Silberschatz Ch. 8,9.
By Teacher Asma Aleisa Year 1433 H.   Goals of memory management  To provide a convenient abstraction for programming  To allocate scarce memory resources.
Chapter 18 Paging Chien-Chung Shen CIS, UD
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.
1 Memory Management Basics. 2 Program P Basic Memory Management Concepts Address spaces Physical address space — The address space supported by the hardware.
By Teacher Asma Aleisa Year 1433 H.   Goals of memory management  To provide a convenient abstraction for programming.  To allocate scarce 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,
1 Computer Systems II Introduction to Processes. 2 First Two Major Computer System Evolution Steps Led to the idea of multiprogramming (multiple concurrent.
Review °Apply Principle of Locality Recursively °Manage memory to disk? Treat as cache Included protection as bonus, now critical Use Page Table of mappings.
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.
Chapter 18 Paging Chien-Chung Shen CIS/UD
Chapter 15 Address Translation Chien-Chung Shen CIS/UD
MODERN OPERATING SYSTEMS Third Edition ANDREW S
Memory Management.
Non Contiguous Memory Allocation
Processes and threads.
Segmentation COMP 755.
Chapter 8: Main Memory.
CSE 120 Principles of Operating
Mechanism: Address Translation
Memory Management © 2004, D. J. Foreman.
Chien-Chung Shen CIS/UD
PA1 is out Best by Feb , 10:00 pm Enjoy early
Instructors: Haryadi Gunawi
Main Memory Management
Chapter 8: Main Memory.
CSCI206 - Computer Organization & Programming
Lecture 6 Memory Management
The Operating System Memory Manager
Memory Management-I 1.
Main Memory Background Swapping Contiguous Allocation Paging
CS399 New Beginnings Jonathan Walpole.
CSE 451: Operating Systems Spring 2012 Module 6 Review of Processes, Kernel Threads, User-Level Threads Ed Lazowska 570 Allen.
Lecture 3: Main Memory.
CSE 451: Operating Systems Autumn 2005 Memory Management
System Calls David Ferry CSCI 3500 – Operating Systems
Virtual Memory Overcoming main memory size limitation
CSE 451: Operating Systems Autumn 2003 Lecture 10 Paging & TLBs
Chapter 8: Memory Management strategies
CSE 451: Operating Systems Autumn 2003 Lecture 9 Memory Management
CSE 451: Operating Systems Autumn 2003 Lecture 10 Paging & TLBs
Operating Systems: A Modern Perspective, Chapter 6
CSE 451: Operating Systems Autumn 2003 Lecture 9 Memory Management
Lecture 7: Flexible Address Translation
Memory Management CSE451 Andrew Whitaker.
CS703 - Advanced Operating Systems
Mechanism: Address Translation
COMP755 Advanced Operating Systems
Page Main Memory.
Presentation transcript:

Virtualization Virtualize hardware resources through abstraction CPU Abstraction: Process Mechanism: Limited direct execution Efficient – process runs directly on the CPU Hardware support for traps, context switching Control – User mode vs. kernel mode Timer interrupts to regain control from a process Policies: Scheduling MLFQ Minimize turnaround time and response time

Memory Virtualization What is memory virtualization? OS virtualizes its physical memory. OS provides an illusion of a unique memory space per process. It seems to the process that it can use the whole memory . Transparent to the process

Benefits of Memory Virtualization Ease of use in programming Memory efficiency in terms of time and space The guarantee of isolation for processes as well as OS Protection from errant accesses of other processes

Start Simple: Early OS Load only one process in memory. Poor utilization and efficiency 0KB 64KB max Operating System (code, data, etc.) Current Program Physical Memory

Multiprogramming and Time Sharing 0KB Operating System (code, data, etc.) Load multiple processes in memory. Execute one for a short time. Next process to execute is already in memory Increase utilization and efficiency. Protection issues Errant memory accesses from other processes 64KB Free 128KB Process C (code, data, etc.) 192KB Process B (code, data, etc.) 256KB Free 320KB Process A (code, data, etc.) 384KB Free 448KB Free 512KB Physical Memory

Address Space OS creates an abstraction of physical memory. Contains all of a running process’s memory Program code, heap, stack and etc. 0KB Program Code (free) 1KB 2KB 15KB 16KB Heap Stack Address Space

Address Space(Cont.) Code Heap Stack Instructions of the program Program Code (free) Heap Stack Code Instructions of the program Heap Dynamically allocated memory malloc in C language Stack Store return addresses or values Local variables Passed parameters Address Space

Virtual Address Every address in a running program is virtual OS translates the virtual address to physical address #include <stdio.h> #include <stdlib.h> int main(int argc, char *argv[]){ printf("location of code : %p\n", (void *) main); printf("location of heap : %p\n", (void *) malloc(1)); int x = 3; printf("location of stack : %p\n", (void *) &x); return x; } A simple program that prints out addresses

Virtual Address(Cont.) Address Space 0x400000 Code (Text) Output in 64-bit Linux machine 0x401000 Data 0xcf2000 Heap 0xd13000 (free) location of code : 0x40057d location of heap : 0xcf2010 location of stack : 0x7fff9ca45fcc heap stack 0x7fff9ca28000 Stack 0x7fff9ca49000

Address Translation Memory virtualization goals: Efficiency – fast address translation Control – process isolation Attained via hardware support Registers TLBs Page-table

Address Translation Hardware translates a virtual address to a physical address. The desired information is actually stored in a physical address. The OS must manage hardware

Example: Address Translation C - Language code Load a value from memory Increment it by three Store the value back into memory void func() int x; ... x = x + 3; // this is the line of code we are interested in

Example: Address Translation(Cont.) Assembly Address of ‘x’ has been placed in ebx Load the value at that address into eax Add 3 to the value in eax Store the value in eax back into memory 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

Example: Address Translation(Cont.) (free) 3000 Stack stack heap Heap 14KB Program Code 16KB 15KB 0KB 1KB 2KB 3KB 4KB 128 132 135 movl 0x0(%ebx),%eax Addl 0x03,%eax movl %eax,0x0(%ebx) Fetch instruction at address 128 Execute this instruction (load from address 15KB) 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)

Example: Address Translation(Cont.) (free) 3000 Stack stack heap Heap 14KB Program Code 16KB 15KB 0KB 1KB 2KB 3KB 4KB 128 132 135 movl 0x0(%ebx),%eax Addl 0x03,%eax movl %eax,0x0(%ebx) Fetch instruction at address 128 Execute this instruction (load from address 15KB) 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 Translation happens all the time! It must be efficient.

Location of Address Spaces in Physical Memory Each process’s address space starts at 0 Physical memory starting at 0 is generally reserved for the OS So…A process’s address space must be located somewhere else in physical memory

(allocated but not in use) A Single Process 0KB 0KB Program Code Operating System 16KB Heap (not in use) (free) 32KB Relocated Process Code Heap heap (allocated but not in use) stack 48KB Stack (not in use) Stack 64KB 16KB Physical Memory Address Space

Base and Bounds Register 0KB 0KB Program Code Operating System 16KB Heap (not in use) base register (free) 32KB 32KB Code Heap heap (allocated but not in use) 48KB Stack stack (not in use) Stack bounds register 64KB 16KB Physical Memory 16KB Address Space

Dynamic (Hardware base) Relocation When a program starts running, the OS decides where in physical memory a process should be loaded. Set the base register to that value. Control through isolation Every virtual address must in [base, base + bound) Efficiency Simple translation: Paddr = base + Vaddr

Relocation and Address Translation 0KB 128 132 135 movl 0x0(%ebx),%eax Addl 0x03,%eax movl %eax,0x0(%ebx) Program Code 128 : movl 0x0(%ebx), %eax 1KB Fetch instruction at address 128 Execute Load from address 15KB 2KB Heap 3KB 4KB (free) heap stack 14KB 3000 Stack Base: 32KB Bounds: 16KB 15KB 16KB

Bounds register as end of interval 0KB 0KB Program Code Operating System 16KB Heap (not in use) (free) 32KB Code Heap (allocated but not in use) bounds bounds 16KB 48KB Stack 48KB (not in use) Stack 64KB Physical Memory 16KB Address Space

OS Responsibilities The OS must take action to implement base-and-bounds approach. Three critical junctures: When a process starts running: Find space for the address space in physical memory When a process is terminated: Reclaim the memory for reuse When context switch occurs: Save and store the base-and-bounds pair Restore the next process’s base-and-bounds pair

When a Process Starts Running The OS must find room for the new address space. free list : Chunks of physical memory not in use 0KB Operating System 16KB Free list (not in use) 16KB 32KB Code Heap (allocated but not in use) 48KB 48KB Stack (not in use) 64KB Physical Memory

When a Process Is Terminated The OS must put the memory back on the free list. 0KB Free list 0KB Free list Operating System Operating System 16KB 16KB 16KB 16KB (not in use) (not in use) 32KB 32KB Process A (not in use) 32KB 48KB 48KB 48KB (not in use) (not in use) 48KB 64KB 64KB Physical Memory Physical Memory

When Context Switch Occurs The OS must save and restore the base-and-bounds pair. In process structure or process control block(PCB) Process A PCB … base : 32KB bounds : 48KB … 0KB Operating System Context Switching 0KB Operating System 16KB 16KB (not in use) (not in use) base base 32KB 48KB 32KB 32KB Process A Currently Running Process A bounds bounds 48KB 64KB 48KB 48KB Process B Process B Currently Running 64KB 64KB Physical Memory Physical Memory

Inefficiency of the Base and Bound (free) 14KB Program Code 16KB 0KB 2KB 4KB Heap Stack 6KB 15KB 5KB 3KB 1KB Big chunk of “free” space “free” space takes up physical memory. Hard to run when an address space does not fit into physical memory

Segmentation Segment is a contiguous portion of the address space Logically-different segments: code, stack, heap Each segment can be placed in a different part of physical memory Base and bounds exist per segment.

Placing Segments In Physical Memory 0KB Operating System 16KB (not in use) Segment Base Size Code 32K 2K Heap 34K 2K Stack 28K 2K Stack (not in use) 32KB Code Heap (not in use) 48KB 64KB Physical Memory

Address Translation on Segmentation The offset of the virtual address 100 is 100. The code segment starts at virtual address 0 in address space. Segment Base Size Code 32K 2K 16KB (not in use) 0KB 2KB Program Code 4KB 32KB Location in Phys. memory Code 100 instruction 34KB Heap (not in use)

Address Translation: Segmentation The offset of the virtual address 4200 is 104. The heap segment starts at virtual address 4096 in address space. Segment Base Size Heap 34K 2K (not in use) 6KB Heap 4KB 32KB Code 34KB Location in Phys. memory 4200 data Heap 36KB (not in use) Address Space Physical Memory

Address Translation: Segmentation The offset of the virtual address 4200 is 104. The heap segment starts at virtual address 4096 in address space. Must use offset into the segment for address translation!! Segment Base Size Heap 34K 2K (not in use) 6KB Heap 4KB 32KB Code 34KB Location in Phys. memory 4200 data Heap 36KB (not in use) Address Space Physical Memory

Segmentation Fault or Violation If an illegal address (ex. 7KB) which is beyond the end of heap is referenced, the OS issues a segmentation fault The hardware detects that address is out of bounds. 4KB Heap 6KB (not in use) 7KB 8KB Address Space

Referring to Segment Explicit approach Chop up the address space into segments based on the top few bits of virtual address. Example: virtual address 4200 (01000001101000) 13 1 12 2 11 3 10 4 9 8 7 6 5 Segment Offset Segment bits Code 00 Heap 01 Stack 10 - 11 13 1 12 2 11 3 10 4 9 8 7 6 5 Segment Offset

Referring to Segment(Cont.) SEG_MASK = 0x3000(11000000000000) SEG_SHIFT = 12 OFFSET_MASK = 0xFFF (00111111111111) 1 // get top 2 bits of 14-bit VA 2 Segment = (VirtualAddress & SEG_MASK) >> SEG_SHIFT 3 // now get offset 4 Offset = VirtualAddress & OFFSET_MASK 5 if (Offset >= Bounds[Segment]) 6 RaiseException(PROTECTION_FAULT) 7 else 8 PhysAddr = Base[Segment] + Offset 9 Register = AccessMemory(PhysAddr)

Referring to Stack Segment Stack grows backward Extra hardware support is needed The hardware checks which way the segment grows. 1: positive direction, 0: negative direction (not in use) Segment Base Size Grows Positive? Code 32K 2K 1 Heap 34K 2K 1 Stack 28K 2K 0 26KB Stack 28KB (not in use) Segment Register(with Negative-Growth Support) Physical Memory

Support for Sharing Segments can be shared between address spaces Code sharing is still in use in systems today. Extra hardware support is need for form of Protection bits A few more bits per segment to indicate permissions of read, write and execute. Segment Base Size Grows Positive? Protection Code 32K 2K 1 Read-Execute Heap 34K 2K 1 Read-Write Stack 28K 2K 0 Read-Write Segment Register Values (with Protection)

Fine-Grained and Coarse-Grained Segmentation Coarse-Grained – small number of segments e.g., code, heap, stack. Fine-Grained – many different segments To support fine-grained segmentation, hardware support is required

OS support: Fragmentation External Fragmentation: little holes of free space in physical memory There is 24KB free, but not in one contiguous segment The OS cannot satisfy a 24KB request Compaction: rearranging the existing segments in physical memory Compaction is costly Stop running process Copy data somewhere else Change segment register values

Memory Compaction Not compacted Compacted 0KB 0KB Operating System (not in use) Allocated 24KB 24KB Allocated 32KB 32KB (not in use) Allocated 40KB 40KB (not in use) (not in use) 48KB 48KB 56KB 56KB Allocated 64KB 64KB

Next: Paging