Dbss
Dbss
Dbss
SURESH
MEMORY MANAGEMENT
Background
Contiguous Memory Allocation
Paging
Structure of the Page Table
Swapping
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)
Main memory can take many cycles, causing a stall
Cache sits between main memory and CPU registers
Protection of memory required to ensure correct operation
PROTECTION
CPU must check every memory access generated in user mode to be sure it
is between base and limit for that user
BINDING OF INSTRUCTIONS AND DATA TO MEMORY
Address binding of instructions and data to memory addresses can
happen at three different stages
Compile time: If memory location known a priori, absolute code can
be generated; must recompile code if starting location changes
Load time: Must generate relocatable code if memory location is not
known at compile time
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 A USER PROGRAM
LOGICAL VS. PHYSICAL ADDRESS SPACE
Logical address – generated by the CPU; also referred to as virtual
address
Physical address – address seen by the memory unit
Logical and physical addresses are the same in compile-time and
load-time address-binding schemes; logical (virtual) and physical
addresses differ in execution-time address-binding scheme
Logical address space is the set of all logical addresses generated by a
program
Physical address space is the set of all physical addresses generated by
a program
MEMORY-MANAGEMENT UNIT ( MMU)
Hardware device that at run time maps virtual to physical address
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 N
blocks lost to fragmentation
1/3 may be unusable -> 50-percent rule
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
I/O problem
Latch job in memory while it is involved in I/O
Do I/O only into OS buffers
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
PTO
EFFECTIVE ACCESS TIME
Hit ratio – percentage of times that a page number is found in the TLB
An 80% hit ratio means that we find the desired page number in the TLB
80% of the time.
Suppose that 10 nanoseconds to access memory.
If we find the desired page in TLB then a mapped-memory access take 10 ns
Otherwise we need two memory access so it is 20 ns