9 OS Memory 1
9 OS Memory 1
9 OS Memory 1
Background
Program must be brought (from disk) into memory and placed within a
process for it to be run
Main memory and registers are only storage CPU can access directly
Memory unit only sees a stream of:
• addresses + read requests, or
• address + data and write requests
Register access is done in one CPU clock (or less)
Cache sits between main memory and CPU registers
Protection of memory required to ensure correct operation
Protection
Need to ensure that a process can access only those addresses in
its address space.
We can provide this protection by using a pair of base and limit
registers define the logical address space of a process
Hardware Address Protection
CPU must check every memory access generated in user mode to
be sure it is between base and limit for that user
the instructions to loading the base and limit registers are privileged
Address Binding
Programs on disk, ready to be brought into memory to execute form
an input queue
First-fit and best-fit better than worst-fit in terms of speed and storage
utilization
Fragmentation
External Fragmentation – total memory space exists to satisfy a
request, but it is not contiguous
Internal Fragmentation – allocated memory may be slightly larger
than requested memory; this size difference is memory internal to a
partition, but not being used
First fit analysis reveals that given N blocks allocated, 0.5 (half) N
blocks lost to fragmentation
Fragmentation (Cont.)
Reduce external fragmentation by compaction
• Shuffle memory contents to place all free memory together in one
large block
• Compaction is possible only if relocation is dynamic, and is done
at execution time
Now consider that backing store has same fragmentation problems
Paging
Physical address space of a process can be noncontiguous;
process is allocated physical memory whenever the latter is
available
• Avoids external fragmentation
• Avoids problem of varying sized memory chunks
Divide physical memory into fixed-sized blocks called frames
Divide logical memory into blocks of same size called pages
Keep track of all free frames
To run a program of size N pages, need to find N free frames and
load program
Set up a page table to translate logical to physical addresses
Still have Internal fragmentation
Paging Model of Logical and Physical Memory
Free Frames