Memory Management : Background
- Memory : one linear array of bytes
- Memory hierarchies
- Registers
- L1/L2/L3 cache
- Disks
- Main memory (RAM)
- Higher Memory : Faster, More Expensive and Volatile
- Lower Memory : Slower, Cheaper and Non-Volatile
- Volatile : if power is lost then all the contents are gone
- OS Responsibilities (in Managing Memory)
- Allocate/Deallocate memory when requested by processes
- Keep track of used/unused memory
- Distribute memory between processes
- Control access (only if system is multi-programmed)
- Move data from memory to disk and back
Partitioning
- Contiguous : block of memory allocated to a process (without breaks)
- Non-Contiguous : blocks of memory allocated to a process (anywhere in main memory)
Approaches to Partitioning : Contiguous
Mono-Programming Multiprogramming Multiprogramming
(Fixed Partitions) (F. Non-Equal Partition)
About Single user process at a Fixed equal size partitions Fixed non-equal size
time partitions
Divide memory in static,
Fixed region of memory contiguous and equal size
allocated to OS/kernel partitions
Remaining memory for a Processes can take large
single process enough partition
Process has direct access Allocation of fixed equal
to physical memory size partitions (simple,
little overhead)
Common in consumer
electronics (E.g, washing OS keeps track of which
machine) partition is used/free
, Good No address translation Little overhead Reduces internal
needed fragmentation
Allocation is easy (=>
Contains no holes and gaps simple implementation)
One process has whole
memory space
Overlays (enable
programmer to user more
memory than available)
Bad Direct access to physical Low memory utilization Allocation of partitions
memory (may have access (internal fragmentation: need to be carefully
to OS memory) partition is too large) considered
OS is a process (have 2 overlays used to manage
process anyway) memory (burden on the
programmer)
Underutilisation of hardware
Not good on modern
machines
Approaches to Partitioning : Detour (Probabilistic Model to Simulate Multiprogramming)
Variable(s) / Assumption(s) N : process in memory
p : time spent by the process to wait for I/O
cUtil : 1 - p
p^n : probability of N process waiting for I/O
cUtil : 1 - p^n
Assumes that all processes are independent
of each other.
Sample Calculation Assume
- Computer has 1 MB of memory
- OS takes up 200KB of memory
- I/O wait time of 80% (0.8)
Based on assumptions 1 and 2
- Space for 4 200KB processes left
cUtil = 1 - (0.8)^4 = 0.5904 ( ~ 60%)
, Assume
- Another 1MB added to memory
Based on Assumption 4
- Space for 5 more 200KB processes
cUtil = 1 - (0.8)^9 = 0.865 (~ 87%)
Assume
- Another 1MB added to memory
Based on Assumption 5
- Space for 5 more 200KB processes
- Totally 5 + 5 + 4 = 14 processes
cUtil = 1 - (0.8)^14 = 0.956 (~ 96%)
Observation(s) CPU Utilisation
- Increases with no of processes
- Decreases with level of I/O
Other Notes When a system is multiprogrammed and
more memory is added then the cpu
utilization increases
This model can be used to approximate but
more complex models built using queueing
theory
Memory Allocation Model
Private Queue per Partition Single Queue for all Partitions
Each process is assigned the smallest Allocate small processes to larger partitions
partition it would fit in
Can result in increase internal fragmentation
Reduces internal fragmentation
Reduces memory utilization (can also result
in starvation : small jobs in unused larger
partitions)
- Memory : one linear array of bytes
- Memory hierarchies
- Registers
- L1/L2/L3 cache
- Disks
- Main memory (RAM)
- Higher Memory : Faster, More Expensive and Volatile
- Lower Memory : Slower, Cheaper and Non-Volatile
- Volatile : if power is lost then all the contents are gone
- OS Responsibilities (in Managing Memory)
- Allocate/Deallocate memory when requested by processes
- Keep track of used/unused memory
- Distribute memory between processes
- Control access (only if system is multi-programmed)
- Move data from memory to disk and back
Partitioning
- Contiguous : block of memory allocated to a process (without breaks)
- Non-Contiguous : blocks of memory allocated to a process (anywhere in main memory)
Approaches to Partitioning : Contiguous
Mono-Programming Multiprogramming Multiprogramming
(Fixed Partitions) (F. Non-Equal Partition)
About Single user process at a Fixed equal size partitions Fixed non-equal size
time partitions
Divide memory in static,
Fixed region of memory contiguous and equal size
allocated to OS/kernel partitions
Remaining memory for a Processes can take large
single process enough partition
Process has direct access Allocation of fixed equal
to physical memory size partitions (simple,
little overhead)
Common in consumer
electronics (E.g, washing OS keeps track of which
machine) partition is used/free
, Good No address translation Little overhead Reduces internal
needed fragmentation
Allocation is easy (=>
Contains no holes and gaps simple implementation)
One process has whole
memory space
Overlays (enable
programmer to user more
memory than available)
Bad Direct access to physical Low memory utilization Allocation of partitions
memory (may have access (internal fragmentation: need to be carefully
to OS memory) partition is too large) considered
OS is a process (have 2 overlays used to manage
process anyway) memory (burden on the
programmer)
Underutilisation of hardware
Not good on modern
machines
Approaches to Partitioning : Detour (Probabilistic Model to Simulate Multiprogramming)
Variable(s) / Assumption(s) N : process in memory
p : time spent by the process to wait for I/O
cUtil : 1 - p
p^n : probability of N process waiting for I/O
cUtil : 1 - p^n
Assumes that all processes are independent
of each other.
Sample Calculation Assume
- Computer has 1 MB of memory
- OS takes up 200KB of memory
- I/O wait time of 80% (0.8)
Based on assumptions 1 and 2
- Space for 4 200KB processes left
cUtil = 1 - (0.8)^4 = 0.5904 ( ~ 60%)
, Assume
- Another 1MB added to memory
Based on Assumption 4
- Space for 5 more 200KB processes
cUtil = 1 - (0.8)^9 = 0.865 (~ 87%)
Assume
- Another 1MB added to memory
Based on Assumption 5
- Space for 5 more 200KB processes
- Totally 5 + 5 + 4 = 14 processes
cUtil = 1 - (0.8)^14 = 0.956 (~ 96%)
Observation(s) CPU Utilisation
- Increases with no of processes
- Decreases with level of I/O
Other Notes When a system is multiprogrammed and
more memory is added then the cpu
utilization increases
This model can be used to approximate but
more complex models built using queueing
theory
Memory Allocation Model
Private Queue per Partition Single Queue for all Partitions
Each process is assigned the smallest Allocate small processes to larger partitions
partition it would fit in
Can result in increase internal fragmentation
Reduces internal fragmentation
Reduces memory utilization (can also result
in starvation : small jobs in unused larger
partitions)