Beruflich Dokumente
Kultur Dokumente
2
OS Performance Issue
(Memory Management)
CSC204
Practical Approach to
Operating System
CS110
Contents
Memory Management
Memory Hierarchy
Physical Memory
Virtual Memory
Page Fault
Trashing
Cache - Principle of Locality
Memory Management
Memory management is the act
Memory Management
Subdividing memory to
Memory Hierarchy
WHY need memory hierarchy in computer
system?
To provide the best performance at the lowest
Processor<->Cache<>Other Memory
bus
Bus itself takes sometime to transfer data
it would more effective to use this
program structure:
Temporal Locality (Locality in Time) :
referenced memory is likely to be referenced again soon
sequentially
The above three are known as Principles of Locality - , is
the phenomenon of the same value or related storage
locations being frequently accessed
Cache
Cache
is a small very fast memory (SRAM, expensive)
contains copies of the most recently accessed memory
General structure
n blocks per cache organized in s sets
b bytes per block
total cache size n*b bytes
Physical Memory
Also referred to as the physical storage or
Physical Memory
Physical Memory :
Memory Allocation
Fixed Partition
Scheme
Dynamic Partition
First Fit
Best Fit
Worst Fit
Compaction
Fixed Partition
Attempt at multiprogramming using fixed
partitions
one partition for each job
size of partition designated by reconfiguring
the system
partitions cant be too small or too large.
Critical to protect jobs memory space.
Entire program stored contiguously in
Fixed Partition
Fixed Partition
Dynamic Partition
Available memory kept in contiguous blocks
Dynamic Partitioning of
Main Memory &
Fragmentation
Dynamic Partition
Allocation Scheme
order to high-order).
Faster in making the allocation.
Best-fit: Allocate the smallest partition that is big
enough
Keep free/busy lists ordered by size (smallest to largest).
Produces the smallest leftover partition.
Makes best use of memory.
Worst-fit:
Best-Fit
More complex
algorithm
Searches entire table
before allocating
memory
Results in a smaller
free space (sliver)
First-Fit Allocation
Example
Job List
J1
J2
J3
J4
Memory
Internal
Memory
location
fragmentation
block size
10K
20K
30K*
10K
Job
Job
number
sizeStatus
10240
30K
J1
10K Busy
20K
40960
15K
J4
10K Busy
5K
56320
50K
J2
20K Busy
30K
107520
20K
Free
Internal Fragmentation - allocated memory may be slightly larger than requested
Total Available: 115K Total Used:
40K
memory; this size difference is memory internal to a partition, but not being used
Release of Memory
Space : Deallocation
block to free.
Deallocation for dynamic partitions tries to
Compaction Steps
Relocate every program in memory so
theyre contiguous.
Adjust every address, and every reference
to an address, within each program to
account for programs new location in
memory.
Must leave alone all other values within the
program (e.g., data values).
Compaction used to reduce external
fragmentation
Virtual Memory
Virtual
Virtual Memory
This technique frees the programmer
1. Paging
Main memory is divided into a number of
Pros
No external fragmentation
Cons
A small amount of internal fragmentation.
1. Paging
Address Translation Architecture
1. Paging
Address generated by CPU is divided into:
Page number (p) used as an index into a
1. Paging (Paging
Example - 1)
1. Paging (Paging
Example -2)
2. Segmentation
Based on common practice by programmers
Segmentation Achitecture
Logical address consists of a two tuple:
<segment-number, offset>
Segment table maps two-dimensional
physical addresses; each table entry has:
base contains the starting physical
2. Segmentation (Address
Translation Architecture)
Virtual Memory
Virtual memory separation of user
Advantages of VM
Works well in a multiprogramming environment
Disadvantages of VM
Increased processor hardware costs.
Increased overhead for handling paging
interrupts.
Increased software complexity to prevent
thrashing.
Page Fault
Page fault - a failure to find a page in memory.
Thrashing a process is busy swapping pages in and
out
Procedure to handle page fault:
1.
2.
3.
4.
5.
6.
Thrashing
Trashing an excessive amount of page