8/18/2019 9781439079201_PPT_ch02
1/69
8/18/2019 9781439079201_PPT_ch02
2/69
After completing this chapter, you shouldbe able to describe:
The basic functionality of the three
memory allocation schemes presented inthis chapter: xed partitions, dynamicpartitions, relocatable dynamic partitions
Best-t memory allocation as well asrst-t memory allocation schemes
How a memory list keeps track ofaailable memory
Understanding Operating Systems, Sixth
Edition 2!
8/18/2019 9781439079201_PPT_ch02
3/69
Understanding Operating Systems, SixthEdition 3
The importance of deallocation ofmemory in a dynamic partition system
The importance of the bounds register in
memory allocation schemes The role of compaction and how it
improes memory allocation e"ciency
#
8/18/2019 9781439079201_PPT_ch02
4/69
$anagement of main memory is critical% The performance of the entire system has
been directly dependent on two things:
How much memory is aailable How it is optimi&ation while 'obs are being
processed%
This chapter introduces: The memory manager ()A$* +ore memory (primary storage*
Understanding Operating Systems, SixthEdition 4
8/18/2019 9781439079201_PPT_ch02
5/69
This chapter introduces: our types of memory allocation schemes
.ingle-user systems
ixed partitions /ynamic partitions
)elocatable dynamic partitions
These early memory management schemesare seldom used by today0s 1.s but are
important to study because each oneintroduced fundamental concepts that helpedmemory management eole%
Understanding Operating Systems, SixthEdition 5
2
8/18/2019 9781439079201_PPT_ch02
6/69
+ommercially aailable in 345s and 3425s
6ach program was loaded in its entirety intomemory and allocated as much contiguous
memory space allocated as it needed% 7f the program was too large and didn0t t the
aailable memory space, it couldn0t be executed,
Although early computers were physically
large, they had ery little memory% +omputers hae only a nite amount of
memory%
Understanding Operating Systems, SixthEdition 6
8/18/2019 9781439079201_PPT_ch02
7/69
7f a program doesn0t t, then either thesi&e of the main memory must beincreased or the program must be
modied% $aking it smaller
8sing methods that allow program segments(partitions made to the program* to beoerlaid%
Transfer segments of a program from secondarystorage into main memory for execution
Two or more segments take turns occupying thesame memory locations%
Understanding Operating Systems, SixthEdition 7
8/18/2019 9781439079201_PPT_ch02
8/69
9rogram .egmentation .lides
Understanding Operating Systems, SixthEdition 8
8/18/2019 9781439079201_PPT_ch02
9/69
8/18/2019 9781439079201_PPT_ch02
10/69
8/18/2019 9781439079201_PPT_ch02
11/69
M o d u l e 1 : M a i n c o n t r o l a n d k e y d a t a
M o d u l e 2 : N o r m a l d a t a p r o c e s s i n g l o g i c
M o d u l e 3 : E r r o r p r o c e s s i n g
M o d u l e 4 : E n d - o f - j o b s u m m a r y c o m p u t a t i o n s
8/18/2019 9781439079201_PPT_ch02
12/69
M o d u l e 1 : M a i n c o n t r o l a n d k e y d a t a
M o d u l e 2 : N o r m a l d a t a p r o c e s s i n g l o g i c
8/18/2019 9781439079201_PPT_ch02
13/69
M o d u l e 1 : M a i n c o n t r o l a n d k e y d a t a
M o d u l e 3 : E r r o r p r o c e s s i n g
8/18/2019 9781439079201_PPT_ch02
14/69
M o d u l e 1 : M a i n c o n t r o l a n d k e y d a t a
M o d u l e 4 : E n d - o f - j o b s u m m a r y c o m p u t a t i o n s
8/18/2019 9781439079201_PPT_ch02
15/69
A program cannot process data it doesnot hae%
A program spends more time waiting for
71 than processing data%
8/18/2019 9781439079201_PPT_ch02
16/69
The amount of work performed by the$emory $anager is minimal%
1nly two hardware items are needed:
A register to store the base address An accumulator to keep track of the si&e of
the program as it0s being read into memory%
1nce the program is entirely loaded into
memory, it remains there until executionis complete, either through normaltermination or by interention of the 1.%
Understanding Operating Systems, SixthEdition 16
8/18/2019 9781439079201_PPT_ch02
17/69
/isadantages There is no support for multiprogramming or
networking
7t can handle only one 'ob at a time% This conguration was rst used in research
institutions but proed unacceptable for thebusiness community%
7t was not cost e;ectie to spend almost
Understanding Operating Systems, SixthEdition 17
8/18/2019 9781439079201_PPT_ch02
18/69
The rst attempt to followmultiprogramming used fxed partitions (static partitions* within main memory%
1ne partition for each 'ob% The si&e of each partition was designated
when the system was powered on% 6ach partition could only be recongured
when the system was shut down% 1nce the system was in operation, thepartition si&es remained static%
Understanding Operating Systems, SixthEdition 18
8/18/2019 9781439079201_PPT_ch02
19/69
7ntroduced protection of the 'ob0s memoryspace 1nce a partition was assigned to a 'ob, no other 'ob
could be allowed to enter its boundaries, eitheraccidentally or intentionally% >ot a problem in single-user contiguous allocation
schemes%
ixed 9artitions is more ?exible than the .ingle-8ser scheme because it allows seeralprograms to be in memory at the same time%
ixed 9artitions still re=uires that the entireprogram be stored contiguously and in memoryfrom the beginning to the end of its execution%
Understanding Operating Systems, SixthEdition 19
8/18/2019 9781439079201_PPT_ch02
20/69
7n order to allocate memory spaces to 'obs, the 1.0s $emory $anager mustkeep a table which shows: 6ach memory partition si&e 7ts address 7ts access restrictions
7ts current status (free or busy*
As each 'ob terminates, the status of itsmemory partition is changed from busyto free so an incoming 'ob can beassigned to that partition%
Understanding Operating Systems, SixthEdition 20
8/18/2019 9781439079201_PPT_ch02
21/69
$emory manager allocates memory space to 'obs 8ses a table
Understanding Operating Systems, SixthEdition 21
8/18/2019 9781439079201_PPT_ch02
22/69
Understanding Operating Systems, SixthEdition 22
8/18/2019 9781439079201_PPT_ch02
23/69
/isadantages The ixed 9artition scheme works well if all the 'obs run on the system are of the same si&e orif the si&es are known ahead of time and don0t
ary between reconguration% 7f the partition si&es are too small:
larger 'obs will be re'ected if they0re too big to tinto the largest partition%
@arge 'obs will wait if the large partitions arebusy%
@arge 'obs may hae a longer turnaround time asthey wait for free partitions of su"cient si&e ormay neer run%
Understanding Operating Systems, SixthEdition 23
8/18/2019 9781439079201_PPT_ch02
24/69
/isadantages 7f the partition si&es are too big, memory is
wasted% 7f a 'ob does not occupy the entire partition, the
unused memory in the partition will remain idle% 7t can0t be gien to another 'ob because each
partition is allocated to only one 'ob at a time%
9artial usage of xed partitions and the
coinciding creation of unused spaces withinthe partition is called internalfragmentation and is a ma'or drawback tothe xed partition memory allocation scheme%
Understanding Operating Systems, SixthEdition 24
8/18/2019 9781439079201_PPT_ch02
25/69
ith Dynamic Partitions aailable memoryis still kept in contiguous blocks but 'obs aregien only as much memory as they re=uest
when they are loaded for processing% A dynamic partition scheme fully utili&es
memory when the rst 'obs are loaded%
As new 'obs enter the system that are not the
same si&e as those that 'ust acated memory,they are t into the aailable spaces on apriority basis% irst +ome irst .ere priority
Understanding Operating Systems, SixthEdition 25
8/18/2019 9781439079201_PPT_ch02
26/69
The subse=uent allocation of memory createsfragments of free memory between blocks ofallocated memory%
6xternal fragmentation
@ets memory go to waste
Understanding Operating Systems, SixthEdition 26
8/18/2019 9781439079201_PPT_ch02
27/69
Understanding Operating Systems, SixthEdition 27
8/18/2019 9781439079201_PPT_ch02
28/69
or both xed and dynamic memoryallocation schemes, the 1. must keeplists of each memory location notingwhich are free and which are busy%
As new 'obs come into the system, thefree partitions must be allocated%
These partitions may be allocated on thebasis of: First-t memory allocation:
irst partition tting the re=uirements
Best-t memory allocation:
.mallest partition tting the re=uirements
@east wasted spaceUnderstanding Operating Systems, SixthEdition 28
8/18/2019 9781439079201_PPT_ch02
29/69
or both schemes, the $emory $anagerorgani&es the memory lists of the freeand used partitions either by si&e or by
location% The Best-t allocation method keeps the
freebusy lists in order by si&e, smallest tolargest%
$akes the best use of memory space%
The rst-t method keeps the freebust listorgani&ed by memory locations, low-ordermemory to high-order memory%
aster in making the allocation%
Understanding Operating Systems, SixthEdition 29
8/18/2019 9781439079201_PPT_ch02
30/69
Understanding Operating Systems, SixthEdition 30
8/18/2019 9781439079201_PPT_ch02
31/69
Understanding Operating Systems, SixthEdition 31
8/18/2019 9781439079201_PPT_ch02
32/69
Algorithm for rst-t Assumes memory manager keeps two lists
1ne for free memory blocks
1ne for busy memory blocks
The operation consists of a simple loop thatcompares the si&e of each 'ob to the si&e ofeach memory block until a block is found thatis large enough to t the 'ob%
The 'ob is stored into that block of memoryand the $emory $anager moes out of theloop to fetch the next 'ob from the entry =ueue
Understanding Operating Systems, SixthEdition 32
8/18/2019 9781439079201_PPT_ch02
33/69
Algorithm for rst-t (cont'd.): 7f the entire list is searched in ain, then the 'ob is placed into a waiting =ueue%
The $emory $anager then fetches the next 'ob and repeats the process%
Understanding Operating Systems, SixthEdition 33
8/18/2019 9781439079201_PPT_ch02
34/69
Understanding Operating Systems, SixthEdition 34
8/18/2019 9781439079201_PPT_ch02
35/69
Algorithm for best-t The goal is to nd the smallest memory block
into which the 'ob will t
The entire table must be searched before theallocation can be made because the memoryblocks are physically stored in se=uenceaccording to their location in memory%
Understanding Operating Systems, SixthEdition 35
8/18/2019 9781439079201_PPT_ch02
36/69
Understanding Operating Systems, SixthEdition 36
8/18/2019 9781439079201_PPT_ch02
37/69
Hypothetical allocation schemes >ext-t:
.tarts searching from last allocated block, fornext aailable block when a new 'ob arries
orst-t:
Allocates largest free aailable block to new 'ob
1pposite of best-t
Cood way to explore theory of memoryallocation
>ot best choice for an actual system
Understanding Operating Systems, SixthEdition 37
8/18/2019 9781439079201_PPT_ch02
38/69
There eentually comes a time whenmemory space must be released ordeallocated %
or a xed-partition system: hen the 'ob is completed, the $emory
$anager resets the status of the memoryblock where the 'ob was stored to DfreeE%
Any code may be used% 6xample code: binary alues with &ero indicating
free and one indicating busy%
Understanding Operating Systems, SixthEdition 38
8/18/2019 9781439079201_PPT_ch02
39/69
or dynamic-partition system: A more complex Algorithm is used because
the algorithm tries to combine free areas ofmemory wheneer possible%
The system must be prepared for threealternatie solutions:
Case : hen the block to be deallocated isadjacent to another free block
Case !: hen the block to be deallocated isbetween two free blocks
Case ": hen the block to be deallocated isisolated from other free blocks
Understanding Operating Systems, SixthEdition 39
8/18/2019 9781439079201_PPT_ch02
40/69
8sing the deallocation algorithm, the systemsees that the memory to be released is next toa free memory block (@ocation FG55*%
The @ist must be changed changes to re?ect
the starting address of the new free block(F55* which was the address of the rstinstruction of the 'ob that 'ust released thisblock%
7n addition, the memory block si&e for this newfree space must be changed to show its newsi&e, which is the combined total of the two freepartitions (!55 I 2*%
Understanding Operating Systems, SixthEdition 40
8/18/2019 9781439079201_PPT_ch02
41/69
Understanding Operating Systems, SixthEdition 41
8/18/2019 9781439079201_PPT_ch02
42/69
Understanding Operating Systems, SixthEdition 42
8/18/2019 9781439079201_PPT_ch02
43/69
hen the deallocated memory space isbetween two free memory blocks:
8sing the deallocation algorithm, the systemlearns that the memory to be deallocated isbetween two free blocks of memory%
The si&es of the three free partitions (!5 I !5I!52* must be combined and the total stored
with the smallest beginning address, F25% Because the entry at location F55 has been
combined with the preious entry, we mustempty out this entry%
Understanding Operating Systems, SixthEdition 43
8/18/2019 9781439079201_PPT_ch02
44/69
e do that by changing the status to n#llentry, with no beginning address and nomemory block si&e as indicated by an asterisk%
This negates the need to rearrange the list at
the expense of memory%
Understanding Operating Systems, SixthEdition 44
8/18/2019 9781439079201_PPT_ch02
45/69
Understanding Operating Systems, SixthEdition 45
8/18/2019 9781439079201_PPT_ch02
46/69
Understanding Operating Systems, SixthEdition 46
8/18/2019 9781439079201_PPT_ch02
47/69
The third alternatie is when the space to bedeallocated is isolated from all other freeareas% 8sing the deallocation algorithm, the system
learns that the memory block to be released isnot ad'acent to any free blocks of memory
7t is between two other busy areas
The system must search the table for a null entry%
hen the null entry is found:
The beginning memory location of the terminating 'ob is entered in the beginning address column%
Understanding Operating Systems, SixthEdition 47
8/18/2019 9781439079201_PPT_ch02
48/69
The 'ob si&e is entered under the memory blocksi&e column
The status is changed from a null entry to free toindicate that a new block of memory is aailable%
Understanding Operating Systems, SixthEdition 48
8/18/2019 9781439079201_PPT_ch02
49/69
Understanding Operating Systems, SixthEdition 49
8/18/2019 9781439079201_PPT_ch02
50/69
Understanding Operating Systems, SixthEdition 50
8/18/2019 9781439079201_PPT_ch02
51/69
Understanding Operating Systems, SixthEdition 51
8/18/2019 9781439079201_PPT_ch02
52/69
8/18/2019 9781439079201_PPT_ch02
53/69
Both the xed and dynamic memoryallocation schemes described thus farshared some unacceptable fragmentationcharacteristics that had to be resoledbefore the number of 'obs waiting to beaccepted became unwieldy%
7n addition, there was a growing need to useall the sliers of memory often left oer%
The solution to both problems was thedeelopment of relocatable dynamic partitions%
Understanding Operating Systems, SixthEdition 53
8/18/2019 9781439079201_PPT_ch02
54/69
Relocatable Dynamic Partitions The $emory $anager relocates programs to
gather together all of the empty blocks andcompact them to make one block of memory
large enough to accommodate some or all ofthe 'obs waiting to get in%
The compaction of memory is performedby the 1. to reclaim fragmented sections
of the memory space% 6ery program in memory must be relocated so
they0re contiguous%
Understanding Operating Systems, SixthEdition 54
8/18/2019 9781439079201_PPT_ch02
55/69
$he compaction of memory 6ery address, and eery reference to an
address, within each program must bead'usted to account for the program0s new
location in memory% All other alues within the program must be
left alone%
Understanding Operating Systems, SixthEdition 55
8/18/2019 9781439079201_PPT_ch02
56/69
Understanding Operating Systems, SixthEdition 56
8/18/2019 9781439079201_PPT_ch02
57/69
Understanding Operating Systems, SixthEdition 57
8/18/2019 9781439079201_PPT_ch02
58/69
Understanding Operating Systems, SixthEdition 58
8/18/2019 9781439079201_PPT_ch02
59/69
Understanding Operating Systems, SixthEdition 59
8/18/2019 9781439079201_PPT_ch02
60/69
8/18/2019 9781439079201_PPT_ch02
61/69
%hat lists ha&e to be #pdated After relocation and compaction, both the free
list and the busy list are updated%
ree list is changed to show the partition for the
new block of free memory The one formed as a result of compaction that will
be located in memory starting after the last locationused by the last 'ob%
Busy list is changed to show the new locationsfor all of the 'obs already in process that wererelocated%
Understanding Operating Systems, SixthEdition 61
8/18/2019 9781439079201_PPT_ch02
62/69
.pecial-purpose registers used for relocation: Bo#nds register
8sed to store the highest (or lowest* location inmemory accessible by each program%
This ensures that, during execution, a programwon0t try to access memory locations that don0tbelong to it%
elocation register
+ontains the alue that must be added to each
address referenced in the program so that thesystem will be able to access the correct memoryaddresses after relocation%
7f the program isn0t relocated, the alue, D&eroE isstored in the program0s relocation register%
Understanding Operating Systems, SixthEdition 62
8/18/2019 9781439079201_PPT_ch02
63/69
By compacting and relocating, the$emory $anager optimi&es use ofmemory and, thus, 7mproes throughput%
An unfortunate side e;ect is that moreoerhead is incurred than with the twopreious memory allocation schemes%
The crucial factor is the timing of the
compaction% hen and how often should it be done%
Understanding Operating Systems, SixthEdition 63
8/18/2019 9781439079201_PPT_ch02
64/69
There are three options for the timing ofcompaction: 1ne approach is to do it when a certain
percentage of memory becomes busy F2K
The disadantage of this approach is that thesystem would incur unnecessary oerhead if no 'obswere waiting to use the remaining !2K%
A second approach is to compact memory onlywhen there are 'obs waiting to get in%
This would entail constant checking of the entry=ueue, which might result in unnecessary oerheadand slow down the processing of the 'obs in thesystem%
Understanding Operating Systems, SixthEdition 64
8/18/2019 9781439079201_PPT_ch02
65/69
There are three options for the timing ofcompaction: A third approach is to do it after a prescribed
amount of time has elapsed%
7f the amount of time chosen is too small, thesystem will spend more time on compaction thanon processing%
7f the amount of time is too large, too many 'obs
will congregate in the waiting =ueue and theadantages of compaction are lost%
Understanding Operating Systems, SixthEdition 65
8/18/2019 9781439079201_PPT_ch02
66/69
There are three options for the timing ofcompaction: The best choice for any system is decided by
the 1. designer who, based on the 'ob mix
and other factors, tries to optimi&e bothprocessing time and memory use whilekeeping oerhead as low as possible%
Understanding Operating Systems, SixthEdition 66
8/18/2019 9781439079201_PPT_ch02
67/69
our memory management techni=ues .ingle-user systems
ixed partitions
/ynamic partitions )elocatable dynamic partitions
+ommon re=uirements of four memorymanagement techni=ues 6ntire program loaded into memory
+ontiguous storage
$emory residency until 'ob completed
Understanding Operating Systems, SixthEdition 67
8/18/2019 9781439079201_PPT_ch02
68/69
6ach places seere restrictions on 'obsi&e
.u"cient for rst three generations of
computers which processed 'obs in batchmode% Turnaround time was measured in hours%
Understanding Operating Systems, Sixth
Edition 68
8/18/2019 9781439079201_PPT_ch02
69/69
>ew modern memory managementtrends in late 345s and early 34F5s /iscussed in next chapter
+ommon characteristics of memory schemes 9rograms are not stored in contiguous memory
>ot all segments reside in memory during 'obexecution