Download presentation
Presentation is loading. Please wait.
Published byAugust Logan Modified over 8 years ago
1
CHAPTER 3-1, 3-2 MEMORY MANAGEMENT
2
MEMORY HIERARCHY Small amount of expensive, fast, volatile cache Larger amount of still fast, but slower, volatile ram Vast amount of inexpensive, not volatile, but slow secondary storage
3
MEMORY MANAGER Keeps track of which parts of memory are in use Allocate memory to processes when needed Deallocate memory when processes complete
4
MEMORY MODEL Abstraction of how memory appears to the programmer Simplest: No abstraction at all Memory is divided between o/s, process, device drivers o/s signals user when process is finished. Waits for command to load another Two drawbacks: A single process can run. Time wasted waiting on i/o Physical (and so o/s) is exposed
5
MONOPROGRAMMING a) Pre-1960 mainframes from another era b) Embedded systems C) Early PCs
6
MULTIPROGRAMMING Degree of multiprogramming Processes spend up to 80% of time waiting for i/o Suppose process spends fraction, t, waiting for i/o If N processes, probability that all are waiting is t N Then CPU use is 1 - t N N is called degree of multiprogramming Suppose we want 90% CPU use.9 = 1 -.8 N N ~ 10 Suppose we want 95% CPU use.95 = 1 -.8 N 5/100 = (8/100) N ln 5 – ln 100 = n * (ln 8 – ln 10) N ~ 13.6 Diminishing returns. Is the trade-off in response time worth it? Still, some amount of multiprogramming is correct
7
BUT A GREAT PROBLEM WITHOUT A MEMORY ABSTRACTION a)16 kb program runs alone. Finishes b)os loads new program. Finishes c)Now suppose os tries to multiprogram. d)jmp 28 causes an error e)Problem: both programs reference static, physical addresses -
8
FIRST THINGS FIRST Multiprogramming requires solution to two problems protection: process 1 may not overwrite process 2 relocation: remap process memory to different parts of physical memory Address Space The set of addresses available to a process Each process has its own address space Key idea: address 28 in process 1 is not the same physical address as address 28 in process 2
9
BASE AND LIMIT REGISTERS Simple solution to relocation problem. Base register holds the beginning address of the process Limit register holds length of the process jmp 28 jumps base register + 28 Problem: What if the RAM required by all processes is more than physical RAM? Windows/osx/linux load up to 100 processes at boot time
10
SOLUTION 1: SWAPPING Memory allocation changes as processes come into memory and leave it. The shaded regions are unused memory
11
SWAPPING ISSUES Problem 1 Swapping creates holes in memory Can be relieved through (very expensive) memory compaction Problem 2 Have assumed that programs have a fixed size But many programming languages allow for dynamically allocated memory If free store is adjacent to a process, it can be claimed If not, the growing process will have to be moved to a hole large enough to accommodate it or swapped out and suspended.
12
SOLUTION a)allocate extra space at load time b)Distinguishes between dynamically allocated heap memory and local stack memory
13
KEEPING TRACK OF GROWING/SHRINKING MEMORY WITH BIT MAPS AND LINKED LISTS a)A part of memory with five processes and three holes. The tickmarks show the memory allocation units. The shaded regions (0 in the bitmap) are free. b)The corresponding bitmap c)Linked list memory management Problems with bit maps Large allocation unit results in holes Small allocation unit requires large bitmap Bitmap must be searched at each load to look for the right size space
14
PROCESS TERMINATES Is X adjacent to another process?
15
FINDING A WHOLE LARGE ENOUGH FOR THE PROCESS First fit Scan linked list looking for the first whole that is big enough Results fragmentation Next fit Start search where last search ended to avoid small hole clustering Best fit Scan all of memory looking for the best fit Sounds good, but results in many tiny and useless holes Worst fit OK. Look for the largest available hole. Also produces fragmentation There are other possibilities, including a doubly linked list to make merging easier. Fragmentation is a problem with all possibilites
16
DYNAMIC ALLOCATION Amount of memory a process needs varies over the course of execution Begin with some small amount of memory If a process requests more, move it to a larger hole. Major Problem Requires address translation because processes are being moved about in memory
17
COMPACTION AND DYNAMICALLY ALLOCATED MEMORY Require that processes by moved in memory Start address of a program in memory is not known when the program is written This simple observation implies that programs go through a series of transformations
18
TRANSFORMATIONS 1.Compilation Conversion from symbolic to numerical Output: relocatable module 2.Linking Resolution of external references Output: absolute module 3.Relocation Determine start address All internal address references can be recomputed relative to start address
19
WHEN RELOCATION OCCURS Load Time Static Relocation if start address is determined statically, compaction/dynamic memory allocation are difficult Run Time Dynamic Relocation If start address is determined dynamically, compaction/dynamic memory allocation are easier
20
STATIC RELOCATION Linker generates address relative to all procedures within the module Loader has a relocation constant: Starting address Relocation constant is added to all linker-generated addresses Branch A... A Branch 50... Proc_A __________________ Branch 150... Other Procs... ____________________________ Proc_A ____________________________ Branch 1150... 0 50 0 100 150 0 1000 1100 1150 static relocation comp link
21
DYNAMIC RELOCATION Address binding occurs at run-time before each memory allocation Loader does not need to transform program
22
TECHNIQUES OF DYNAMIC RELOCATION (1) Relocation Register Memoryprocessor Relocation Register + logical address physical address read/write
23
TECHNIQUES OF DYNAMIC RELOCATION (2) Address Map Memoryprocessor Address Map Table logical address physical address read/write Begins to look like Virtual Memory
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.