memory allocation scheme

advertisement
Chapter 2 Memory Management,
Early Systems
CIS106
Microcomputer Operating Systems
Gina Rue
CIS Faculty
Ivy Tech State College Northwest Region 01
Memory Manager
Four types of memory allocation schemes
• single-user systems
• fixed partitions
• dynamic partitions
• re-locatable dynamic partitions
2
Memory Manager
• Memory performance is dependent on
two things:
– how much memory is available
– how it is optimized while jobs are being
processed
3
Single-user
Contiguous Scheme
First memory allocation scheme
• early computers had limited memory
• allocated as much contiguous space
– if the job was too large, it couldn’t execute
• jobs processed sequentially
– OS algorithm used to allocate memory
• did not support multiprogramming
See Single User Algorithm p.18
4
Fixed-Partitions
• First attempt to allow for
multiprogramming
• created within main memory - one
partition for each job
• to protect job’s memory space critical
– algorithm used to store jobs in memory, size
of job must match size of partition
– major drawback: internal fragmentation is
unused space within the fixed partition
See Table & Fig. 2.1 p.20
5
Dynamic Partitions
• available memory kept in contiguous
blocks
• jobs are given only as much memory as
they request when loaded for processing
• first-come first-served priority basis
– subsequent allocation of memory creates
fragments
– called external fragmentation, free memory
blocks between allocated memory
See Fig. 2.2 p.22
6
Best-Fit vs First-Fit Allocation
New jobs come into the system, the free
partitions must be allocated
• first-fit
first partition fitting the requirement, low to high
order memory list
• best-fit
closest fit, smallest partition fitting the
requirements, smallest to largest memory list
For both schemes, memory manager keeps
lists of free & used partitions (free/busy) by
size or location See Table 2.2 & 2.3 p.24
7
Best-Fit vs First-Fit Allocation
Which is best?
• For many years, no answer
• best-fit resulted in a better “fit”, it also
resulted in smaller “free” space (sliver)
• In recent years, access times have improved
so that the scheme that saves more
resources & memory space is the best choice
• Research continues to find the optimum
allocation scheme
8
Deallocation
Memory space must be released
• fixed partitions - when a job is complete, the
memory manager resets status of memory block
where the job was stored to “free”
• dynamic partitions - more complex algorithm tries
to combine free areas of memory wherever possible
3 alternative situations systems must prepare for
deallocation
– block is adjacent to another free block
– block is between two free blocks
– block is isolated from other free blocks
9
Relocatable Dynamic Partitions
Both fixed & dynamic leave “slivers” of
memory left over
Solution - Memory Manager relocates
programs to gather together all empty
blocks & compact them into one large
enough to accommodate jobs waiting
compaction - every program in memory
must be relocated so they are contiguous
10
Relocatable Dynamic Partitions
What goes on behind the scenes when
relocation and compaction take place?
What keeps track of how far each job has
moved from its original location?
• Special-purpose registers are used to help
with relocation
• bound register-stores highest or lowest
location in memory accessible by each
program
• relocation register-contains the value that
must be added to each address referenced in
11
the program
Relocatable Dynamic Partitions
What lists have to be updated?
• After relocation & compaction, both free
lists and busy lists are updated
• Each job will have a new address except for
those that already reside in the lowest
memory locations
12
Relocatable Dynamic Partitions
In effect,
by compacting & relocating,
the Memory Manager optimizes the use
of memory thus improves throughput -one of the measures of the system
performance. The crucial factor is the
timing of the compaction….
13
Relocatable Dynamic Partitions
Compaction - when & how often should it
be done?
– When a certain % of memory becomes busy,
75 percent
– Only when there are jobs waiting to get in
– After a prescribed amount of time
The best choice depends on the job mix to
optimize both processing time & memory
use while keeping overhead low
14
Summary
• 4 memory management techniques
– single-user, fixed partitions, dynamic
partitions, relocatable partitions
– all 4 require that the entire program
• loaded into memory
• be stored contiguously
• remain in memory until the job is completed
15
Summary
• 4 memory management techniques
(schemes)
– sufficient for first 3 generations of
computers which processed jobs in batch
mode
– turnaround time was delayed to hours or
even days between job submission and
completion
16
Download