Operating System - Memory Management Strategies
Operating System - Memory Management Strategies
Chapter -8
Chapter 8: Memory Management
• Background
• Swapping
• Contiguous Memory Allocation
• Segmentation
• Paging
• Structure of the Page Table
Objectives
• To provide a detailed description of various
ways of organizing memory hardware
• To discuss various memory-management
techniques, including paging and
segmentation
• To provide a detailed description of the Intel
Pentium, which supports both pure
segmentation and segmentation with paging
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 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
Base and Limit Registers
• 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
Hardware Address Protection
Address Binding
• Programs on disk, ready to be brought into memory to execute form an input
queue
– Without support, must be loaded into address 0000
• Inconvenient to have first user process physical address always at 0000
– How can it not be?
• Further, addresses represented in different ways at different stages of a program’s
life
– Source code addresses usually symbolic
– Compiled code addresses bind to relocatable addresses
• i.e. “14 bytes from beginning of this module”
– Linker or loader will bind relocatable addresses to absolute addresses
• i.e. 74014
– Each binding maps one address space to another
Binding of Instructions and Data to Memory
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
• 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
Segmentation
• 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
User’s View of a Program
Logical View of Segmentation
1
4
1
3 2
4