CPS110: Intro to memory Landon Cox February 14, 2008.

Slides:



Advertisements
Similar presentations
Part IV: Memory Management
Advertisements

Memory Protection: Kernel and User Address Spaces  Background  Address binding  How memory protection is achieved.
Memory Management Questions answered in this lecture: How do processes share memory? What is static relocation? What is dynamic relocation? What is segmentation?
OS Memory Addressing.
CS 153 Design of Operating Systems Spring 2015
CS 153 Design of Operating Systems Spring 2015
Operating Systems CMPSCI 377 Lecture 11: Memory Management
Memory Management and Paging CSCI 3753 Operating Systems Spring 2005 Prof. Rick Han.
Multiprocessing Memory Management
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 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.
Memory ManagementCS-502 Fall Memory Management CS-502 Operating Systems Fall 2006 (Slides include materials from Operating System Concepts, 7 th.
Memory Management Chapter 5.
CS 333 Introduction to Operating Systems Class 9 - Memory Management
Memory Management Five Requirements for Memory Management to satisfy: –Relocation Users generally don’t know where they will be placed in main memory May.
Chapter 91 Memory Management Chapter 9   Review of process from source to executable (linking, loading, addressing)   General discussion of memory.
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.
Review of Memory Management, Virtual Memory CS448.
MEMORY MANAGEMENT Presented By:- Lect. Puneet Gupta G.P.C.G. Patiala.
CS333 Intro to Operating Systems Jonathan Walpole.
Operating Systems ECE344 Ding Yuan Memory Management Lecture 7: Memory Management.
CS 153 Design of Operating Systems Spring 2015 Lecture 17: Paging.
Cosc 2150: Computer Organization Chapter 6, Part 2 Virtual Memory.
CIS250 OPERATING SYSTEMS Memory Management Since we share memory, we need to manage it Memory manager only sees the address A program counter value indicates.
Subject: Operating System.
By Teacher Asma Aleisa Year 1433 H.   Goals of memory management  To provide a convenient abstraction for programming  To allocate scarce memory resources.
Chapter 8 – Main Memory (Pgs ). Overview  Everything to do with memory is complicated by the fact that more than 1 program can be in memory.
1 Virtual Memory and Address Translation. 2 Review Program addresses are virtual addresses.  Relative offset of program regions can not change during.
1 Address Translation Memory Allocation –Linked lists –Bit maps Options for managing memory –Base and Bound –Segmentation –Paging Paged page tables Inverted.
PA0 due 60 hours. Lecture 4 Memory Management OSTEP Virtualization CPU: illusion of private CPU RAM: illusion of private memory Concurrency Persistence.
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Memory: Relocation.
Chapter 4 Memory Management Virtual Memory.
Memory Management Fundamentals Virtual Memory. Outline Introduction Motivation for virtual memory Paging – general concepts –Principle of locality, demand.
1 Memory Management Chapter 7. 2 Memory Management Subdividing memory to accommodate multiple processes Memory needs to be allocated to ensure a reasonable.
By Teacher Asma Aleisa Year 1433 H.   Goals of memory management  To provide a convenient abstraction for programming.  To allocate scarce memory.
CPS110: Address translation Landon Cox February 19, 2008.
Memory Management Operating Systems CS550. Memory Manager Memory manager - manages allocation and de-allocation of main memory Plays significant impact.
12/5/20151 Operating Systems Design (CS 423) Elsa L Gunter 2112 SC, UIUC Based on slides by Roy Campbell, Sam King,
Paging (continued) & Caching CS-3013 A-term Paging (continued) & Caching CS-3013 Operating Systems A-term 2008 (Slides include materials from Modern.
Processes and Virtual Memory
Operating Systems ECE344 Ashvin Goel ECE University of Toronto Memory Management Overview.
Copyright ©: Nahrstedt, Angrave, Abdelzaher1 Memory.
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.
CS703 - Advanced Operating Systems By Mr. Farhan Zaidi.
W4118 Operating Systems Instructor: Junfeng Yang.
Memory Management.
Virtualization Virtualize hardware resources through abstraction CPU
Segmentation COMP 755.
Chapter 8: Main Memory.
CSE 120 Principles of Operating
CSC 322 Operating Systems Concepts Lecture - 12: by
Chien-Chung Shen CIS/UD
PA1 is out Best by Feb , 10:00 pm Enjoy early
Instructors: Haryadi Gunawi
Review: memory and address spaces
Lecture 28: Virtual Memory-Address Translation
CS399 New Beginnings Jonathan Walpole.
Memory Management Overview
CSE 451: Operating Systems Autumn 2005 Memory Management
CSE 451: Operating Systems Autumn 2003 Lecture 9 Memory Management
CSE 451: Operating Systems Autumn 2003 Lecture 9 Memory Management
Lecture 7: Flexible Address Translation
Memory Management CSE451 Andrew Whitaker.
EECE.4810/EECE.5730 Operating Systems
Chapter 8 & 9 Main Memory and Virtual Memory
Presentation transcript:

CPS110: Intro to memory Landon Cox February 14, 2008

Operating systems Hardware OS Applications

Remember what a process is  Thread  Stream of execution (unit of concurrency)  Project 1, first month of class  Address space  Memory space that threads use (unit of data)  Project 2, next two weeks of class

Address space abstraction  Address space  All memory data process uses to run  Program code, stack, data segment  Hardware  software  All processes share single small memory  OS  applications  Each process has its own large memory

Hardware, OS interfaces Hardware OS Applications Memory CPU CPU, Mem Job 1 CPU, Mem Job 2 CPU, Mem Job 3

Illusions of the address space 1.Address independence  Can use same numeric address in 2 processes  Each process has its own version of “address 4”  Each “address 4” refers to different data items 2.Protection  One process cannot touch another’s data 3.Virtual memory  Address space can be larger than physical memory

Uni-programming  1 process occupies memory at a time  Always load process into same spot  Must reserve space for the OS fffff (high memory)..Operating system ffff..User process (low memory)

Uni-programming  Virtual address  Address programmer thinks she’s accessing  Physical address  Address from the view of the machine  (actual physical memory location)  What is the V-to-P mapping in uni-progamming?  Identity map (virtual A  physical A)

Uni-programming  How to run another process?  Swap user process 1 to disk  Bring user process 2 to memory  Kernel scheduler swaps address spaces  (when doing a context switch)  This is how early PCs worked (badly)

Uni-programming  What features does this provide?  Address independence  Protection  No virtual memory  Note sum of address spaces > phys mem.

Uni-programming  Problems with uni-programming?  Swapping to/from disk is slow  Moves more data than might be needed  What does this imply about RR slice?  High overhead for swapping  large slice  Large slice  interactivity suffers

Multi-programming  More than 1 process in phys memory  Processes can have same virtual addrs  Cannot share physical addrs  Addresses must be translated  Statically: occurs before execution  Dynamically: occurs during execution  Protection is harder

Static address translation  Want two processes in memory  With address independence  Without translating on-the-fly  Must use static translation  Could you do this?

Static address translation  Adjust loads/stores when put in memory  This is called a linker-loader  Programming  Assume memory starts at 0  Linker-loader  Adds 0x20000 to offsets for P2  Similar to linking phase of compile fffff (high memory).Operating system ffff..User process ffff..User process (low memory) load $1, $base + offset

Linking your programs  Compiler generates.o files + libraries .o files all assume they start at address 0  Linker puts everything together  Resolves cross-module references  (e.g. “how do I jump to thread_create?”)  Spits out single executable file

Multi-programming abstractions  Address independence?  Yes. (my address 4 is different from yours)  Protection?  No.  Why not?

Multi-programming protection  Static translation changes the offset  Process could still issue odd register value  Problem  Buggy/malicious code can corrupt other processes  User (not system) gets last move  Why do we need dynamic addresses?  To make pointers and arrays work load $1, $base + offset

Multi-programming features  Address independence?  Yes. (my address 4 is different from yours)  Protection?  No.  Why not?  Virtual memory?  No.

Multi-programming virtual memory  Virtual address space ≤ phys mem  Proof: static translation cannot provide VM  Each VA maps to a fixed PA  (one-to-one mapping)  Thus, # of VAs must equal # of PAs  (but we want more VAs than PAs)  Our goals require dynamic translation

Course administration  Project 1  Due next Thursday  I am seriously worried …  If you haven’t started the library you are in trouble  Project 1 spec has been out for three weeks  Covered implementing threads/locks two weeks ago  Why have only two groups submitted so far?

Course administration  Extra office hours  Amre: Friday, 3-5  Jason: Sunday, 5-7  Me: Monday, 3-5  Quinn: Monday, 6-8  In addition to normal hours  Jason’s hours today moved to 8-10

Dynamic address translation User process Translator (MMU) Translator (MMU) Physical memory Physical memory Virtual address Physical address Will this allow us to provide protection? Sure, as long as the translation is correct

Dynamic address translation User process Translator (MMU) Translator (MMU) Physical memory Physical memory Virtual address Physical address This is an example of a systems service called “naming”. Can you think of other examples, that you use everyday? Internet DNS (Domain Name Service) File System (human-readable names to blocks on disk)

Dynamic address translation User process Translator (MMU) Translator (MMU) Physical memory Physical memory Virtual address Physical address How does Java use naming to provide protection? What exactly is Java trying to protect (and from what)? Has programming in C++ changed your opinion of Java? Is it better to learn programming protected or not?

Dynamic address translation  Does this enable virtual memory?  Yes  VA only needs to be in phys mem when accessed  Provides flexibility  Translations can change on-the-fly  Different VAs can occupy different Pas  Common technique  Add level of indirection to gain flexibility

Hardware support  Traditional view  Dynamic translation needs hardware support  Agree or disagree?  Basic requirement  Must translate each load/store  Could do this via software simulation  JVM does a lot of the work of the MMU

 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 Looks a lot like the linker-loader. What is different? No rewriting. Every access goes through translator. (system gets the last move)

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 }

1. Base and bounds  What happens on a context switch?  Must translate addresses differently  Load translation data for new process  Set base and bounds registers

1. Base and bounds  How can address spaces grow?  If memory above base+bound is free  Increase the bound  If memory above base+bound isn’t free  Stop program  Copy data  Change base and bounds  Restart process  Does being moved affect the program?  No, it still only knows about virtual addresses Base Base + Bound 0

Base and bounds pros and cons  Pros  Low hardware costs (2 registers, adder, comparator)  Fast (only inserting addition and comparison)  Cons  Single address space can’t easily exceed size of phys mem  Growing virtual address space might be slow  Sharing is difficult (must share all or nothing)

Base and bounds sharing Virtual memory (IE 1) Physical memory 0 Bound Base Base + Bound 0 Size of phys mem Virtual memory (IE 2) 0 Bound Why can’t IE 1 and IE 2 share the same code segment?

Base and bounds pros and cons  Pros  Low hardware costs (2 registers, adder, comparator)  Fast (only inserting addition and comparison)  Cons  Single address space can’t easily exceed size of phys mem  Growing virtual address space might be slow  Sharing is difficult (must share all or nothing)  Waste memory due to external fragmentation

Base and bounds fragmentation Physical memory 0 P1 P2 P3 P4 100KB 300KB 600KB 1MB P5 400KB P6 300KB External fragmentation Heuristics to minimize Best fit (Allocate in smallest free region) First fit (Use first region that fits)

Base and bounds pros and cons  Pros  Low hardware costs (2 registers, adder, comparator)  Fast (only inserting addition and comparison)  Cons  Single address space can’t easily exceed size of phys mem  Sharing is difficult (must share all or nothing)  Growing virtual address space might be slow  Waste memory due to external fragmentation  Hard to grow multiple regions of memory

Base and bounds growth  What grows in a process?  The stack and heap P1 stack frame New bound

Base and bounds growth  What grows in a process?  The stack and heap  How do you do this with both?  If heap grows, extend P1’s bound  If stack grows, must shift heap up  What about pointers into heap? P1 heap stack heap stack heap New data on heap at VA 100 (translated to PA 100+base) Store this address in a variable How can you shift VAs up? VA100 Problem: must fit two growing data structures in one contiguous region

Next class  Segmentation instead of base and bounds  Where “segmentation fault” comes from  Get serious about Project 1!