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
Ceng 334 - Operating Systems

Storage Hierarchy
Main Memory
• Cache on Chip (internal cache) • External Cache memory • RAM Access time decreases

Secondary Storage
• Hard Disk

Capacity decreases

Tertiary Storage
• CD ROM • Floppy • Tape
Ceng 334 - Operating Systems

Cost increases


Important Memory Terms
Contiguous Non-contiguous Real memory Virtual memory Logical Physical Block Principle of locality Fragmentation
Ceng 334 - Operating Systems

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

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
Ceng 334 - Operating Systems

Dos Memory Layout
16M B Extended Memory 1M+64KB HMA 1MB Upper Memory Area 640KB Conventional Memory 0
Ceng 334 - Operating Systems

Buffer cache, RAM Disk, Memory for protected mode OS

I/O boards, ROMs, MS-DOS and Device drivers

MS-DOS, Device drivers, program

Basic Memory Management (Monoprogramming)

Three simple ways of organizing memory
- an operating system with one user process
Ceng 334 - Operating Systems

Multiprogramming with Fixed Partitions
Process 1
F r a g m e n t

Process 2

F r a g m e n t

Process 3

F r a g m e n t

• 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
Ceng 334 - Operating Systems

Partition 1

Partition 2

Partition 3

Modeling Multiprogramming

Degree of multiprogramming

CPU utilization as a function of number of processes in memory
Ceng 334 - Operating Systems

Multiprogramming with Dynamic Partitions
• Partitions are created at load times
OS Memory at system start up
Process 1 Process 2 OS Three processes started Process 1 OS Second processes is finished Process 3

Process 3

Process 1 Process 3 Process 4 OS A large fourth process arrives. Process 3 is relocated Ceng 334 - Operating Systems


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
Ceng 334 - Operating Systems


Ceng 334 - Operating Systems


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
Ceng 334 - Operating Systems

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

Ceng 334 - Operating Systems


Placement Algorithms
• First fit
– Process is placed in the first hole it can fit in

• Next fit
– 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
Ceng 334 - Operating Systems

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
Ceng 334 - Operating Systems

Another Allocation scheme: Buddy System
• Memory is allocated in powers of 2 sized units during load time
Initially 90 KB request 300 KB request 90 KB returned
90KB 128KB 90KB 128KB 512KB 256KB 256KB 1 MB 512KB 300KB 300KB

Ceng 334 - Operating Systems


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
Ceng 334 - Operating Systems

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
Ceng 334 - Operating Systems

Can We Get Rid of These Problems?
• YES!

Ceng 334 - Operating Systems


Sign up to vote on this title
UsefulNot useful