<<

Motivation UNIVERSITY of WISCONSIN-MADISON Sciences Department Simple uniprogramming with a single segment per CS 537 A. Arpaci-Dusseau Intro to Operating Systems Spring 2000 Early batch monitors Personal

2^N OS Highest memory holds OS Questions answered in these notes • How do processes share main memory? User • What are the advantages and disadvantages of static ? Process Process starts at memory address 0, up to the OS • What are the advantages and disadvantages of dynamic relocation? • How does the memory management interact with hardware? 0 Readings for this lecture Disadvantages Silberschatz/Galvin: Chapter 8 • Only one process can run at a time • Process can destroy OS

CS 537:Operating Systems Lecture13.fm.2 A.Arpaci-Dusseau

Goals for Multiprogramming Static Relocation

Sharing Transparency --> Relocation • Several processes to coexist in main memory • Processes can run anywhere in memory (can’t predict in advance) • Modify addresses statically (similar to linker) when load process 2^N Transparency OS Highest memory holds OS • Processes not aware that memory is shared • Run regardless of number and/or locations of processes Process 3

Protection Process 2 Processes allocated starting at 0, up to the OS • Cannot corrupt OS or other processes • Privacy: Cannot read of other processes Process 1 0 Efficiency should not be severely degraded Advantages • Allows multiple processes to run • Purpose of sharing is to increase efficiency • • Do not waste CPU or memory resources Requires no hardware support

CS 537:Operating Systems Lecture13.fm.3 A.Arpaci-Dusseau CS 537:Operating Systems Lecture13.fm.4 A.Arpaci-Dusseau Disadvantages of Static Relocation Dynamic Relocation

Process allocation must be contiguous Change address dynamically at every reference • Fragmentation: May not be able to allocate new process Logical Addresses What ? • Processes may not be able to increase • Can’t move process after it has been placed? CPU MMU Memory 2^N OS

OS controls MMU Process 3 Physical Addresses

Process 2 Program-generated address translated to hardware address • Process 1 Program addresses are called logical or virtual addresses 0 • Hardware addresses are called physical or real addresses. No protection: Destroy other processes and/or the OS Address space: View of memory for each process

CS 537:Operating Systems Lecture13.fm.5 A.Arpaci-Dusseau CS 537:Operating Systems Lecture13.fm.6 A.Arpaci-Dusseau

Address Spaces Hardware Support

Translation from logical to physical addresses Two operating modes Memory • Address Space 1 N Privileged (protected, kernel) mode: When OS runs When trap into OS (system calls, interrupts, errors) 1 process, Allows certain instructions to be executed multiple threads Allows OS to access all of physical memory 0 • User mode: When user processes run Address Space 2 Performs translation of to

0 Base and Bounds registers for translation Address Space 3 • Base register: Start location for address space stack • Bounds register: Last valid address the process may generate heap Appears to have private memory of size equal to bounds register code OS 0 0 Logical view Physical view

CS 537:Operating Systems Lecture13.fm.7 A.Arpaci-Dusseau CS 537:Operating Systems Lecture13.fm.8 A.Arpaci-Dusseau Implementation Managing Processes w/ Base and Bounds

Translation on every memory access in user process Context-Switch • Compare logical address to bounds register • Add base and bounds registers to PCB If logical address is greater, then generate error • Steps during context-switch • Add base register to logical address to generate physical address Change to privileged mode Save base and bounds registers of old process CPU 3232 1 Load base and bounds registers of new process registers base bounds rel Memory Change to user mode and jump to new process logical relocation address no rel? Protection Requirement 32 physical yes address • User process can not change base and bounds register • User process can not change to privileged mode <= yes + bounds base What if don’t change base and bounds register when switch? error no

CS 537:Operating Systems Lecture13.fm.9 A.Arpaci-Dusseau CS 537:Operating Systems Lecture13.fm.10 A.Arpaci-Dusseau

Pros and of Base and Bounds

Advantages • Supports dynamic relocation of address spaces • Supports protection across multiple address spaces • Cheap: Few registers and little logic • Fast: Add and compare can be done in parallel

Disadvantages • Each process must be allocated contiguously in real memory Fragmentation: Can not allocate a new process Solution: Swapping • Must allocate memory that may not be used

• No Sharing: Cannot share limited parts of address space (e.g., cannot share code with private data)

CS 537:Operating Systems Lecture13.fm.11 A.Arpaci-Dusseau