Memory Management ()

advertisement
Chapter 3.1 : Memory
Management



Storage hierarchy
Important memory terms
Earlier memory allocation schemes
Contiguous memory allocation
 Fixed partitions
 Dynamic partitions


Managing free & allocated Memory Space
1
Storage Hierarchy
Main Memory
• Cache on Chip (internal cache)
• External Cache memory
• RAM
Secondary Storage
Access time decreases
Capacity decreases
• Hard Disk
Tertiary Storage
• CD ROM
• Floppy
• Tape
Cost increases
2
Important Memory Terms
Term
Meaning
Contiguous
Stored in consecutive memory
addresses
NOT stored in consecutive memory
addresses
Memory area limited to actual
physical RAM
Logical memory area created using a
combination of RAM and hard disk
What software thinks
What hardware knows
Smallest amount of information
transferred by a disk
Program tend to access memory
within some localized area
Splitting of memory into little bits
Non-contiguous
Real memory
Virtual memory
Logical
Physical
Block
Principle of locality
Fragmentation
3
Contiguous Memory Allocation
OS &
drivers



User Program
After loading OS, the rest of the memory is
available for user program
Size of user program is fixed by available
memory
Use of overlays for larger programs
4
Dos Memory Layout
16MB
Extended
Memory
1M+64KB
HMA
1MB
Upper Memory
Area
640KB
Conventional
Memory
Buffer cache, RAM Disk,
Memory for protected mode OS
I/O boards, ROMs, MS-DOS and
Device drivers
MS-DOS, Device drivers, programs
0
5
Basic Memory Management
(Monoprogramming)
Three simple ways of organizing memory
- an operating system with one user process
6
Multiprogramming with Fixed
Partitions
OS
Process 1
F
r
a
g
m
e
n
t
Partition 1


Process 2
Partition 2
F
r
a
g
m
e
n
t
Process 3
F
r
a
g
m
e
n
t
Partition 3
Partition numbers and sizes (equal or unequal) are set by
operator at system start up based on workload statistics
Used by IBM’s MFT (Multiprogramming with a Fixed Number
of Tasks) OS for IBM 360 systems long time ago
7
Modeling Multiprogramming
Degree of multiprogramming
CPU utilization as a function of number of processes in memory
8
Multiprogramming with
Dynamic Partitions

Partitions are created at load times
OS
Memory at system start up
OS
Process 1
Process 2
Three processes started
OS
Process 1
Second processes is finished
Process 3
Process 3
OS
Process 1
Process 3
Process 4
A large fourth process arrives. Process 3 is relocated
9
Problems with Dynamic
Partitions





Fragmentation occurs due to creation and
deletion of memory space at load time
Fragmentation is eliminated by relocation
Relocation has to be fast to reduce overhead
Free (unused) memory has to be managed
Allocation of free memory is done by a
placement algorithm
10
Question:
11
How to Keep Track of Unused
Memory

Bit Maps

Memory is divided into allocation units of fixed
size. A bit map with “0” bits for free and “1” bits
for allocated units
Memory allocation units: Green - used, Yellow - unused
1
1
0
1
0
1
0
0
1
1
0
1
0
1
Bit map of the above memory
12
How to Keep Track of Unused
Memory (Cont.)

Linked Lists
1
2
3
4
5
6
7
8
9
10
11
12
13
14
Memory allocation units: Green - used, Yellow - unused
U
1
5
F
6
3
U
9
2
F
11
4
Linked list memory map
13
Placement Algorithms

First fit


Next fit


Process is placed in the first hole it can fit in
Start searching from the point where the last
search has ended and perform first fit
Best fit

Process is placed in a hole which is closest to the
process size
14
Performance Issues

Best Fit usually performs the worst, since it
leaves behind the smallest possible hole

First Fit is simplest to implement and usually
fastest and best

Next fit is usually a little worse than First Fit
15
Another Allocation scheme:
Buddy System

Memory is allocated in powers of 2 sized
units during load time
Initially
1 MB
90 KB request
90KB 128KB
256KB
512KB
300 KB request
90KB 128KB
256KB
300KB
90 KB returned
512KB
300KB
16
Buddy System (Cont.)


This method makes de-allocation fast. If a block
of size 2k is released then the memory manager
checks only the list of 2k holes to merge them
into a 2k+1 sized partition
Internal fragmentation is caused since memory
requests are fitted in 2k sized partitions
17
Problems with Memory
Management Techniques so far




Unused memory due to fragmentation
Memory may contain parts of program which
are not used during a run (ie., some routines may
not be accessed in that particular run)
Process size is limited with the size of physical
memory
Process needs contiguous space in real memory
for execution
18
Can We Get Rid of These
Problems?

YES!
19
Download