CSIT123 Week 7 Lecture
CSIT123 Week 7 Lecture
Learning objectives
Understand and explain the units of measure of
memory.
Explain the role of memory management.
Understand the reasons for memory partitioning.
Explain the different portioning techniques.
Discuss their advantages and disadvantages
Explain internal and external fragmentation
Understand and explain the compaction technique.
Understand and explain the different placement
techniques ( best fit, first fit, worst fit, next fit)
How memory is used?
Bytes, Kilobytes, Megabytes, Gigabytes,…….
Throughput
Is the number of jobs per hour that the system
completes.
Turnaround time
The actual time to complete a job
• is an important resource
• that must be very carefully
managed.
Memory management
While the average home
computer nowadays has
100,000 times more
memory than the IBM
7094, the largest
computer in the world in
the early 1960s,
Programs are
getting bigger
faster than
memories.
Memory management
‘‘Programs expand to
fill the memory
available to hold them”
Memory management
What every programmer would like:
the concept of a
memory hierarchy,
Memory management
what is a memory hierarchy?
computers have
Case (a),
Case (b)
Case (c)
Look at the OS
The partition
The simplest scheme for
managing this available memory
Fixed Dynamic
Memory management techniques - multiprogramming
Fixed partitioning
Dynamic partitioning
Internal fragmentation
Dynamic partitioning
We will discuss
each of the 8 cases.
From (a)
Through
(h)
Memory management techniques - multiprogramming
Dynamic partitioning- case (a)
Case (a)
main memory is empty,
except for the OS
Which occupies 8MB
And 56 MB free
Memory management techniques - multiprogramming
Dynamic partitioning- case (b)
Case(b)
Process 1(20MB) is
loaded into memory
Case(c)
Process 2(14 MB) is
loaded into memory
Case(d)
Process 3(18 MB) is
loaded into memory
Case (e )
At some point, none of the processes
in memory is ready.
Case(f)
Process 4 (8MB) is loaded into
memory
Case (g)
At some point, none of the processes
in main memory is ready,
Case (h)
Case (h)
And we end up with 3
small size holes
External fragmentation
As this example shows,
For example,
the OS designer
Because
must be clever
memory
in deciding how (how to plug
compaction is
to assign the holes).
time
processes to
consuming,
memory
Memory management techniques - multiprogramming
Dynamic partitioning- placement algorithms
When then
it is time to load or swap a the operating system must
process into main memory, decide which free block to
and if there is more than allocate.
one free block of memory
of sufficient size,
Memory management techniques - multiprogramming
Dynamic partitioning- placement algorithms
First-fit
Best-fit
Placement
algorithms:
Next-fit
Worst-fit
Memory management techniques - multiprogramming
Dynamic partitioning- placement algorithms
First fit.
Allocate the first hole that is big enough.
Searching can start either
Best fit
Allocate the smallest hole that is big enough.
Worst fit.
Allocate the largest hole.
Next-fit
begins to scan memory from the
location of the last placement
Example of
Memory
Configuration
before and
after
Allocation of
16-Mbyte
Block
Memory management techniques - multiprogramming
placement algorithms example
Figure (a)
shows an example
memory configuration
after a number of
placement
and swapping-out
operations.
The last block that was
used was a 22-Mbyte
block
from which a 14-Mbyte
partition was created.
Memory management techniques - multiprogramming
placement algorithms example
Figure b
shows the
difference between
the best-,first-, and
next-fit placement
algorithms
• in satisfying a 16-
Mbyte allocation
request.
Memory management techniques - multiprogramming
placement algorithms example
Best-fit
will search the entire list of
available blocks
and make use of the 18-
Mbyte block,
leaving a 2-Mbyte fragment.
First-fit
results in a 6-Mbyte
fragment,
Next -fit
results in a 20-Mbyte
fragment
Memory management techniques - multiprogramming
placement algorithms: best fit, first fit, next fir Performance
more frequently lead to an allocation from a free block at the end of memory.
The result is that the largest block of free memory, which usually appears
at the end of the memory space, is quickly broken up into small fragments.
It looks for the smallest block that will satisfy the requirement,
Although each memory request always wastes the smallest amount of memory,
the result is that main memory is quickly littered by blocks too small to satisfy memory allocation
requests.
Thus, memory compaction must be done more frequently than with the other algorithms
exercise
• Assume a system with the following holes in memory:
– 10 KB
– 4 KB
– 12 KB
– 8 KB
– 18 KB
– 7 KB
– 9 KB
– 12 KB
– And 15 KB
• Which hole is taken for the next fit successive requests of memory:
– P1 : 12 KB
– P2 : 10 KB
– P3: 9 KB
• Apply all three algorithms; First fit, best fit, Worst fit
Some definitions we will used
A block of memory status is either
– Free (hole) represented by hole
– Or used represented by Used
A process is defined by:
– Its arrival
– And its memory demand
After allocation of a memory block to a process
– The free block (hole) becomes used
– This is reflected in the new status of memory
Fist Fit
Initial status and Arrival of process 1