Abstraction is our Business What I have A single (or a finite number) of CPUs Memory Management Many programs I would like to run What I want : a Thread Each program has full control of one or more CPUs � 1 Abstraction Address Space is our Business Set of all names used to identify and What I have manipulate unique instances of a given resource A certain amount of physical memory memory locations (determined by the size of the Multiple programs I would like to run machine’ s word) together, they may need more than the available physical memory for 32-bit-register machine, the address space goes from 0x00000000 to 0xFFFFFFFF What I want : an Address Space memory locations (determined by the number of Each program has as much memory as the machine’ s memory banks mounted on the machine) architecture will allow to name phone numbers (XXX) (YYY-YYYY) All for itself colors: R (8 bits) + G (8 bits) + B (8 bits) � 3 � 4
Virtual Address Space: Physical Address Space: An Abstraction for Memory How memory actually looks 0 Virtual addresses start at 0 Program Code Processes loaded in memory at some 0 OS memory location Heap Heap and stack can be placed far free virtual address 0 is not loaded at away from each other, so they can physical address 0 code, nicely grow Process 2 data, etc free free Multiple processes may be loaded in Addresses are all contiguous memory at the same time, and yet… free Size is independent of physical …physical memory may be too small code, Process 1 data, memory on the machine etc to hold even a single virtual address code, Process 3 data, 63KB space in its entirety etc Stack free 64KB 64-bit registers, anyone? 512K � 5 � 6 Address Translation Protection The functions used by different processes map their A function that maps ⟨ pid, virtual address ⟩ virtual addresses to disjoint ranges of physical addresses into a corresponding physical address Virtual Physical p i function implemented through p i a combination of hw and sw Advantages: a486d9 protection p j relocation 5e3a07 data sharing multiplexing � 7 � 8
Relocation Relocation The range of the function used by a process can The range of the function used by a process change over time can change over time p i p i The same physical address can map over time to different physical addresses or the mapping can be (temporarily) undefined � 9 � 10 Multiplexing Multiplexing The set of virtual addresses that map to a The set of virtual addresses that map to a given range of physical addresses can change given range of physical addresses can change over time over time p i p i � 11 � 12
Multiplexing Multiplexing The set of virtual addresses that map to a The set of virtual addresses that map to a given range of physical addresses can change given range of physical addresses can change over time over time p i p i � 13 � 14 Multiplexing Data Sharing The set of virtual addresses that map to a Map different virtual addresses of different given range of physical addresses can change processes to the same physical address over time p i p i 04d26a 5e3a07 p j 119af3 � 15 � 16
Contiguity Contiguity Contiguous virtual addresses need not map to Contiguous virtual addresses need not map to contiguous physical addresses contiguous physical addresses p i p i � 17 � 18 More sophisticated The Identity Mapping address translation Map each virtual address onto the 0 How to perform the mapping efficiently? identical physical address OS So that it can be represented concisely? 16KB Virtual and physical address spaces Heap have the same size So that it can be computed quickly? So that it makes efficient use of the limited Run a single program at a time physical memory? OS can be a simple library free So that multiple processes coexist in physical very early computers memory while guaranteeing isolation? Friendly amendment: leave some of So that it decouples the size of the virtual and the physical address space for the OS physical addresses? Use loader to relocate process Stack Ask hardware for help! Max early PCs � 19 � 20
Base & Bound Base & Bound 0 P 1 : Base = 1000; Bound = 300 P 1 1000 300 Goal: allow multiple processes to coexist in P 2 : Base = 500; Bound = 400 memory while guaranteeing isolation Needed hardware Memory Exception two registers: Base and Bound (a.k.a. Limit) 1000 no Stored in the PCB 150 CPU ≤ + 1300 yes Mapping Virtual Physical address address pa = va + Base as long as 0 ≤ va ≤ Bound On context switch, change B&B (privileged instruction) Bound Base Register Register � 21 � 22 MAX sys Base & Bound Base & Bound 0 0 P 1 : Base = 1000; Bound = 300 P 1 : Base = 1000; Bound = 300 P 2 : Base = 500; Bound = 400 P 2 : Base = 500; Bound = 400 Memory Memory Exception Exception 1000 1000 no no 150 150 1150 CPU ≤ + 1300 CPU ≤ + 1300 yes yes Virtual Physical Virtual Physical address address address address P 1 P 1 300 300 1000 1000 Bound Base Bound Base Register Register Register Register � 23 � 24 MAX sys MAX sys
Base & Bound Base & Bound 0 0 P 1 : Base = 1000; Bound = 300 P 1 : Base = 1000; Bound = 300 P 2 : Base = 500; Bound = 400 500 P 2 : Base = 500; Bound = 400 P 2 400 Memory Memory Exception Exception 1000 1000 no no 1150 CPU ≤ + 1300 CPU ≤ + 1300 yes yes Virtual Physical Virtual Physical address address address address P 1 P 2 300 400 500 1000 Context Switch Context Switch Bound Base Bound Base Base & Bound saved in P 1 ’ s PCB Register Register Register Register � 25 � 26 MAX sys MAX sys On Base & Bound Contiguous Allocation contiguous virtual addresses are mapped to contiguous physical addresses But mapping entire address space to physical memory is wasteful lots of free space between heap and stack… makes sharing hard does not work if the address space is larger than physical memory think 64-bit registers… � 27
Recommend
More recommend