Main Memory
Main Memory
Main Memory
Mohiuddin Ahmed
Lecturer
Department of CSE
RUET
A pair of base and limit registers define the logical address space
CPU must check every memory access generated in user mode to be sure it is between base and limit
for that user
Programs on disk, ready to be brought into memory to execute form an input queue
Without support, must be loaded into address 0000
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
Hardware device that at run time maps virtual to physical address
A process can be swapped temporarily out of memory to a backing store, and then brought back into
memory for continued execution
Total physical memory space of processes can exceed physical memory
Roll out, roll in – swapping variant used for priority-based scheduling algorithms; lower-priority
process is swapped out so higher-priority process can be loaded and executed
Main memory must support both OS and user processes
Limited resource, must allocate efficiently
Contiguous allocation is one early method
Main memory usually into two partitions:
Resident operating system, usually held in low memory with
interrupt vector
User processes then held in high memory
Each process contained in single contiguous section of memory
Multiple-partition allocation
Degree of multiprogramming limited by number of partitions
Variable-partition sizes for efficiency (sized to a given process’ needs)
Hole – block of available memory; holes of various size are scattered throughout memory
When a process arrives, it is allocated memory from a hole large enough to accommodate it
Process exiting frees its partition, adjacent free partitions combined
Operating system maintains information about:
a) allocated partitions b) free partitions (hole)
How to satisfy a request of size n from a list of free holes?
Best-fit: Allocate the smallest hole that is big enough; must search entire list, unless
ordered by size
Produces the smallest leftover hole
Worst-fit: Allocate the largest hole; must also search entire list
Produces the largest leftover hole
First-fit and best-fit better than worst-fit in terms of speed and storage utilization
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
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
Memory-management scheme that supports user view of memory
A program is a collection of segments
A segment is a logical unit such as:
main program
procedure
function
method
object
local variables, global variables
common block
stack
symbol table
arrays
1
1 4
2
3
4 2
Segment table – maps two-dimensional physical addresses; each table entry has:
base – contains the starting physical address where the segments reside in memory
limit – specifies the length of the segment