Memory Questions? • What is main memory? CSCI [4|6]730 • How does multiple processes share memory space? Operating Systems – Key is how do they refer to the memory addresses. • Utilizing memory access for everyone! Dynamically! • What is static and dynamic allocation? Main Memory • What is segmentation ? Maria Hybinette, UGA Maria Hybinette, UGA Maria Hybinette, UGA Maria Hybinette, UGA Review: Motivation for Multiprogramming Goals Multiprogramming Uni- processing: One process runs at a time High Address (0xff ff ff ff) • Sharing 2 n -1 Physical Memory – Several processes co-exist in main memory OS – Cooperating processes can share portions of address space ( Stack Linux 32 bit – • Transparency - typical 1G/4G – Processes are not aware that memory is shared Windows - typical 2G/2G – Works regardless of number and/or location of processes User - not as wieldy • Protection Address Process Space Heap – Cannot corrupt OS or other processes – Privacy: Cannot read data of other processes Code • Efficiency 0 – Do not waste CPU or memory resources • Disadvantages: Low Address – Keep fragmentation low (later) (0x00000000) – Only one process runs at a time – Process can destroy OS (need to avoid) Maria Hybinette, UGA Maria Hybinette, UGA Maria Hybinette, UGA Maria Hybinette, UGA http://duartes.org/gustavo/blog/post/anatomy-of-a-program-in-memory/
Memory Addresses Static Relocation (after loading) • Address space • Goal: Allow transparent System Memory sharing - Each address – What we got so far: • Physical addresses space may be placed 0000 • How can we make access to these transparent? Initial P 0 anywhere in memory 0150 Process P 1 – OS finds free space for new process – Modify (rewrite) addresses (similar to Process P 2 • Need to provide support for multiple processes linker) when loading the process 1004 loaded into memory (and make memory (addresses modified only once). Process P 3 0000 accessible). – Fixed addresses. • Advantages: – Option 1: Static Reallocation (IBM S/360) – Allows multiple processes to run – Requires no hardware support Maria Hybinette, UGA Maria Hybinette, UGA Maria Hybinette, UGA Maria Hybinette, UGA Dynamic Relocation Static Reallocation (hardware support) System Memory • Disadvantages: • Goal: Protect processes from one another • Requires hardware support – No protection Initial P 0 • Process can destroy OS or other – Memory Management Unit (MMU) processes • MMU dynamically changes process address at every Process P 1 • No privacy memory reference (compute address on-the-fly) – Address space must be allocated – Process generates logical or virtual addresses Process P 2 contiguously – Memory hardware uses physical or real addresses • Allocate space for worst-case stack and heap Process P 3 Process runs here • Processes may not grow (in size). OS can control MMU – Cannot move process after they are placed or loaded (static addresses) CPU MMU Memory – Fragmentation (later) Process P 4 Logical address Physical address Maria Hybinette, UGA Maria Hybinette, UGA Maria Hybinette, UGA Maria Hybinette, UGA
Hardware Support for Implementation of Dynamic Relocation Dynamic Relocation • Two operating modes • Translation on every memory access of user process – Privileged (protected, kernel) mode: OS runs – MMU compares logical address to bounds register • When enter OS (trap, system calls, interrupts, exceptions) • if logical address is greater, then generate error • Allows certain instructions to be executed – MMU adds base register to logical address to form physical address – Can manipulate contents of MMU • Allows OS to access all of physical memory – User mode: User processes run logical • Perform translation of logical address to physical address address mode � no physical • MMU contains base and bounds registers = � (relative to address user ? Registers: – base: start location for address space (physical address) process starts @0). – bounds: size limit of address space (memory span) 1 bit mode yes bounds no + 32 < error bounds? bits base base Maria Hybinette, UGA Maria Hybinette, UGA Maria Hybinette, UGA Maria Hybinette, UGA Example of Dynamic Relocation Example of Dynamic Relocation • What are the physical addresses for the following 16-bit • What are the physical addresses for the following 16-bit logical addresses (HEX: highest F:1111)? logical addresses (HEX: highest F: 0x1111)? • Process 1: base: 0x4320 , bounds: 0x2220 (in HEX) • Process 1: base: 0x4320 , bounds: 0x2220 (in HEX) – 0x0000: – 0x0000: 0x4320 – 0x1110: – 0x1110: 0x5430 – 0x3000: – 0x3000: segmentation fault • Process 2: base: 0x8540 , bounds: 0x3330 • Process 2: base: 0x8540 , bounds: 0x3330 – 0x0000: – 0x0000: 0x8540 – 0x1110: – 0x1110: 0x9650 – 0x3000: – 0x3000: 0xB540 • Operating System • Operating System – 0x0000: – 0x0000: 0x0000 – 0x5FFF: – 0x5FFF: 0x5FFF Maria Hybinette, UGA Maria Hybinette, UGA Maria Hybinette, UGA Maria Hybinette, UGA
Managing Processes Base and Bounds Discussion with Base and Bounds 0 • Advantages Operating • Context-switch – Provides protection (both read and write) System across address spaces – Add base and bounds registers to (process control block) PCB – Supports dynamic relocation 30004 30004 – Steps: • Can move address spaces Process base • Why might you want to do this? 1. Change to privileged mode – Simple, inexpensive: Few registers, little 42094 12090 2. Save base and bounds registers of old process logic in MMU bound 3. Load base and bounds registers of new process Process – Fast: Add and compare can be done in 4. Change to user mode and jump to new process parallel • What if don’t change base and bounds registers • Disadvantages when switch? – Each process must be allocated contiguously in physical memory • Protection requirement • Must allocate memory that may not be used Process by process in advance – User process cannot change base and bounds registers – No partial sharing: Cannot share limited – User process cannot change to privileged mode parts of address space • Examples: MINIX, IBM 360, UNIVAC Maria Hybinette, UGA Maria Hybinette, UGA Maria Hybinette, UGA Maria Hybinette, UGA Segmentation Segmented Addressing • Divide address space into • How does process designate a particular heap logical segments segment? – Each segment stack corresponds to logical – Use part of logical address entity in address space symbol subroutine • code, • Top bits of logical address select segment table • stack, • Low bits of logical address select offset within segment • heap • Each segment can symbol Example: 4 bits - nibble subroutine table independently: main 0x1108 table program – be placed separately in Segment Number (1 in example) physical memory Logical Address stack Offset (108 in example) – grow and shrink main – be protected (separate program read/write/execute heap protection bits) Need Base Address • Example: MULTICS, UNIX Need Bounds ancestor. Logical Address Physical Address Space Space Maria Hybinette, UGA Maria Hybinette, UGA Maria Hybinette, UGA Maria Hybinette, UGA
Recommend
More recommend