190 likes | 390 Views
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. Storage Hierarchy. Main Memory Cache on Chip (internal cache)
E N D
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
Storage Hierarchy • Main Memory • Cache on Chip (internal cache) • External Cache memory • RAM Access time decreases Capacity decreases • Secondary Storage • Hard Disk • Tertiary Storage • CD ROM • Floppy • Tape Cost increases
OS & drivers User Program Contiguous Memory Allocation • 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
Basic Memory Management (Monoprogramming) Three simple ways of organizing memory - an operating system with one user process
Process 1 F r a g m e n t F r a g m e n t Process 3 F r a g m e n t Process 2 OS Partition 1 Partition 2 Partition 3 Multiprogramming with Fixed Partitions • 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
Modeling Multiprogramming CPU utilization as a function of number of processes in memory Degree of multiprogramming
OS Memory at system start up OS Process 1 Process 2 Process 3 Three processes started OS Process 1 Process 3 Second processes is finished OS Process 1 Process 3 Process 4 A large fourth process arrives. Process 3 is relocated Multiprogramming with Dynamic Partitions • Partitions are created at load times
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
Question: HOW DO YOU RELOCATE A PROCESS?
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 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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 Memory allocation units: Green - used, Yellow - unused U U 1 9 5 2 Linked list memory map F F 11 6 4 3 How to Keep Track of Unused Memory (Cont.) • Linked Lists
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
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
90KB 128KB 256KB 512KB 90KB 128KB 256KB 300KB 512KB 300KB Another Allocation scheme:Buddy System • Memory is allocated in powers of 2 sized units during load time Initially 1 MB 90 KB request 300 KB request 90 KB returned
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
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
Can We Get Rid of These Problems? • YES! VIRTUAL MEMORY