Docsity

Memory Management - Lecture Notes | EECS 678, Study notes of Operating Systems

Partial preview of the text

Download Memory Management - Lecture Notes | EECS 678 and more Study notes Operating Systems in PDF only on Docsity!

Memory Management – Outline

n Background

n Swapping

n Contiguous Memory Allocation

n Paging

n Segmentation

n Segmented Paging

Background

n Memory is a large array of bytes

l (^) memory and registers are only storage CPU can access directly l (^) both instructions and data are fetched from memory l (^) memory unit just sees a stream on memory addresses

n Accessing memory is slow (why?)

l (^) register access in one CPU clock (or less) l (^) cache sits between main memory and CPU registers

n Protection of memory required to ensure correct

operation

l (^) isolate processes from one another and from the OS

Address Binding

n Address binding of instructions and data to memory

addresses can happen at three different stages

l (^) compile time : If memory location known a priori, absolute code can be generated  (^) must recompile code if starting location changes l (^) load time : Must generate relocatable code if memory location is not known at compile time  (^) code can be placed anywhere in memory l (^) execution time : Binding delayed until run time if the process can be moved during its execution from one memory segment to another  (^) need hardware support for address maps (e.g., base and limit registers)

Multistep Processing of User Program

Memory-Management Unit (MMU)

n Hardware device that maps

virtual to physical address.

n Simple MMU scheme

l (^) start each process's logical address from 0 l (^) base memory address for each process stored in relocation register l (^) max. process address stored in limit register l (^) relocation register added to every logical address l (^) logical: 0 – max correspond to physical: R+0 – R+limit

Dynamic Loading

n Static loading

l (^) entire program in memory before program starts l (^) program size limited by size of memory

n Dynamic loading

l (^) routine is not loaded until it is called l (^) better memory-space utilization; unused routine is never loaded l (^) useful when large amounts of code are needed to handle infrequently occurring cases l (^) no special support from the operating system is required implemented through program design

Swapping

n What is swapping?

l (^) moving a process currently resident in memory to a backing store and swapping another process into the freed space l (^) swap individual pages of the same process in-out of memory

n When is swapping needed?

l (^) if there is no free memory for the new process dispatched by the scheduler l (^) if some process needs more physical memory than is available

n Backing store is generally maintained on disk

l (^) swapping is costly l (^) if swapped out memory needs to be brought back in immediately all the time, then it will lead to memory thrashing

n See 'top' and 'swapon -s' under Linux.

Schematic View of Swapping

Hardware Support for Protection

n Relocation and limit registers used to protection

l (^) of user processes from each other, and l (^) operating system from the user processes

n Hardware checks

l (^) base register contains value of smallest physical address l (^) each logical address must be less than the limit register l (^) MMU maps logical address dynamically

Contiguous Memory Allocation (2)

n Multiple-partition method

l (^) hole – block of available memory  (^) holes of various size are scattered throughout memory l (^) when a process arrives, it is allocated memory from a hole large enough to accommodate it l (^) operating system maintains information about: a) allocated partitions b) free partitions (hole) OS process 5 process 8 process 2 OS process 5 process 2 OS process 5 process 2 OS process 5 process 9 process 2 process 9 process 10

Fragmentation

n External Fragmentation – total memory space exists to

satisfy a request, but it is not contiguous

n 50-percent rule

l (^) given N allocated blocks, 0.5N blocks will be lost to fragmentation

n Solutions to external fragmentation

l (^) compaction  (^) move allocated blocks to place all holes together  (^) compaction is possible only if relocation is dynamic l (^) permit non-contiguous allocation of logical address space

n Internal Fragmentation

l (^) occurs with fixed sized blocks used to reduce cost of managing extremely small holes l (^) size of last block may be slightly larger than requested memory l (^) what is the greatest memory loss due to internal fragmentation?

Paging

n Solution to external fragmentation and compaction

l (^) logical address space of a process can be noncontiguous l (^) commonly used in most OS l (^) frequently depend on hardware support

n Scheme

l (^) divide physical memory into fixed-sized blocks called frames  (^) size is generally power of 2, between 512 bytes and 8,192 bytes l (^) divide logical memory into blocks of same size called pages l (^) OS keeps track of all free frames l (^) a program of size n pages, needs n free frames before loading l (^) needs a page table to translate logical to physical addresses

n Problem of internal fragmentation still exists

Paging Hardware

Paging Model of Logical and

Physical Memory