Professional Documents
Culture Documents
(SECONDARY
MEMORY)
CACHE 1
(MAIN
MEMORY)
2
HARD DISK
(SECONDARY
MEMORY)
CACHE 1
(MAIN
MEMORY)
2
Approximate number of clock cycles to access
the various elements of the memory hierarchy.
HARD DISK
(SECONDARY
MEMORY)
CACHE 1
(MAIN
MEMORY)
101
Approximate number of clock cycles to access
the various elements of the memory hierarchy.
HARD DISK
(SECONDARY
MEMORY)
CACHE 1
(MAIN
MEMORY)
101
103
Approximate number of clock cycles to access
the various elements of the memory hierarchy.
HARD DISK
(SECONDARY
MEMORY)
CACHE 1
(MAIN
MEMORY)
101
103
107
Let’s consider an operating system model
with a single user, and how they use memory.
MAIN
MEMOR
Y
MAIN 200K
MEMOR available
Y
If I create a program:
MAIN 200K
MEMOR available
Y
If I create a program:
PROGRAM 1
MAIN 200K
MEMOR available
Y
If I create a program:
PROGRAM 1
MAIN 200K
MEMOR available
to be processed, it has
Y
to be written entirely into
Main Memory, in
contiguous space
PROGRAM 1
MAIN 200K
MEMOR available
Y
If the program is bigger:
MAIN 200K
MEMOR available
PROGRAM 1
Y
If it doesn’t fit in
the memory, it’s
can’t be processed.
MAIN 200K
MEMOR available
Y
This is the limitation of all computers, if a
program is too big, we have to do one of two
things:
PARTITION 2 25K
250K
PARTITION 3 25K
PARTITION 4 50K
PARTITION 5 50K
This leaves us with less memory, but at least
more than one user (and their user process)
can be logged into the system at the same
time.
If we want to adjust the size of the partitions
we need to shut down the system, go into the
boot login, and then restart.
To make this work, the Memory manager
needs to keep a Partition Table to remember
the status of all the partitions.
To make this work, the Memory manager
needs to keep a Partition Table to remember
the status of all the partitions.
Partition Partition Memory Partition
Number Size Address Access Status
1 100K 200K Program1 BUSY
2 25K 300K Program4 BUSY
3 25K 325K FREE
4 50K 350K Program2 BUSY
5 50K 400K FREE
Which looks like this
in memory:
Which looks like this
in memory:
PARTITION 1 100K
PARTITION 2 25K
250K
PARTITION 3 25K
PARTITION 4 50K
PARTITION 5 50K
Let’s add some
programs in:
Let’s add some
programs in:
PARTITION 1 100K
PARTITION 2 25K
250K
PARTITION 3 25K
PARTITION 4 50K
PARTITION 5 50K
Let’s add some
programs in: PROGRAM 1
PARTITION 1 100K
PARTITION 2 25K
250K
PARTITION 3 25K
PARTITION 4 50K
PARTITION 5 50K
Let’s add some
programs in: PROGRAM 1
PARTITION 1 100K
PARTITION
PROGRAM 22 25K
250K
PARTITION 3 25K
PARTITION 4 50K
PARTITION 5 50K
Let’s add some
programs in: PROGRAM 1
PARTITION 1 100K
PARTITION
PROGRAM 22 25K
250K
PARTITION 3 25K
PROGRAM 3
PARTITION 4 50K
PARTITION 5 50K
Let’s add some
programs in: PROGRAM 1
PARTITION 1 100K
INTERNAL FRAGMENTATION
PARTITION
PROGRAM 22 25K
250K
PARTITION 3 25K
PROGRAM 3
PARTITION 4 50K
PARTITION 5 50K
Let’s add some
programs in: PROGRAM 1
PARTITION 1 100K
INTERNAL FRAGMENTATION
PARTITION
PROGRAM 22 25K
250K
PARTITION 3 25K
PROGRAM 3
PARTITION 4 50K
INTERNAL FRAGMENTATION
PARTITION 5 50K
Let’s add some
programs in: PROGRAM 1
PARTITION 1 100K
INTERNAL FRAGMENTATION
PARTITION
PROGRAM 22 25K
250K
EMPTY PARTITION PARTITION 3 25K
PROGRAM 3
PARTITION 4 50K
INTERNAL FRAGMENTATION
PARTITION 5 50K
Let’s add some
programs in: PROGRAM 1
PARTITION 1 100K
INTERNAL FRAGMENTATION
PARTITION
PROGRAM 22 25K
250K
EMPTY PARTITION PARTITION 3 25K
PROGRAM 3
PARTITION 4 50K
INTERNAL FRAGMENTATION
MAIN
250K
MEMOR
Y
Let’s add some
programs in:
PROGRAM 1
MAIN
250K
MEMOR
Y
Let’s add some
programs in: PROGRAM 1
MAIN
250K
MEMOR
Y
Let’s add some
programs in: PROGRAM 1
PROGRAM 2
MAIN
250K
MEMOR
Y
Let’s add some
programs in: PROGRAM 1
PROGRAM 2
MAIN
250K
MEMOR
Y
Let’s add some
programs in: PROGRAM 1
PROGRAM 2
PROGRAM 3
MAIN
250K
MEMOR
Y
Let’s add some
programs in: PROGRAM 1
PROGRAM 2
MAIN
PROGRAM 3
250K
MEMOR
Y
Let’s add some
programs in: PROGRAM 1
PROGRAM 2
PROGRAM 4
MAIN
PROGRAM 3
250K
MEMOR
Y
Let’s add some
programs in: PROGRAM 1
PROGRAM 2
MAIN
PROGRAM 3
250K
MEMOR
Y
PROGRAM 4
Let’s add some
programs in: PROGRAM 1
PROGRAM 2
PROGRAM 5
MAIN
PROGRAM 3
250K
MEMOR
Y
PROGRAM 4
Let’s add some
programs in: PROGRAM 1
PROGRAM 2
PROGRAM 5
MAIN
PROGRAM 3
250K
MEMOR
Y
PROGRAM 4
It isn’t perfect, because the next program will
go into the slot that is freed up by a
completed program.
Let’s add some
programs in: PROGRAM 1
PROGRAM 2
PROGRAM 5
MAIN
PROGRAM 3
250K
MEMOR
Y
PROGRAM 4
Let’s add some
programs in: PROGRAM 1
PROGRAM 2
PROGRAM 5
MAIN 3
PROGRAM
250K
MEMOR
Y
PROGRAM 4
Let’s add some
programs in: PROGRAM 1
PROGRAM 2
PROGRAM 5
250K
PROGRAM 4
Let’s add some
programs in: PROGRAM 1
PROGRAM 2
PROGRAM 5
250K
PROGRAM 4
Let’s add some
programs in: PROGRAM 1
PROGRAM 2
PROGRAM 5
250K
EXTERNAL FRAGMENTATION
PROGRAM 4
So however we partition, we end up with
fragmentation, one way or the other.
PROGRAM 1
PROGRAM 2
PROGRAM 3 250K
PROGRAM 4
PROGRAM 5
So how do we decide
PROGRAM 1
where to slot in a
new program?
PROGRAM 2
PROGRAM 3 250K
PROGRAM 4
PROGRAM 5
So how do we decide
PROGRAM 1
where to slot in a
new program?
PROGRAM 2
PROGRAM 4
PROGRAM 5
Here is the first slot
PROGRAM 1
free
PROGRAM 2
PROGRAM 4
PROGRAM 5
Here is the first slot
PROGRAM 1
free
PROGRAM 2
PROGRAM 6
PROGRAM 3 250K
PROGRAM 4
PROGRAM 5
But here’s a better fit
PROGRAM 1
PROGRAM 2
PROGRAM 6
PROGRAM 3 250K
PROGRAM 4
PROGRAM 5
But here’s a better fit
PROGRAM 1
PROGRAM 2
PROGRAM 3 250K
PROGRAM 6
PROGRAM 4
PROGRAM 5
So we can either add the new block to the
first available slot (FIRST-FIT ALGORITHM) or
we can add the new block to the most
suitable available slot (BEST-FIT ALGORITHM).
If the Memory Manager wants a FIRST-FIT
ALGORITHM then it stores a table in order of
memory locations.
If the Memory Manager wants a BEST-FIT
ALGORITHM then it stores a table in order of
size of memory locations. Starts Size Status
Starts Size Status 315 40 FREE
250 50 FREE
Starts Size
300 15 BUSY Status
315 40 FREE 300 15 BUSY
355 25 BUSY
355 25 BUSY
315 40 BUSY
After a program is completed, there are three
cases for deallocating space in memory:
1. There are programs either side of the freed
space:
PROGRAM 5 PROGRAM 5
PROGRAM 3 PROGRAM 3
PROGRAM 6
PROGRAM 4 PROGRAM 4
PROGRAM 8 PROGRAM 8
2. There are is a program on one side, and
it’s free on the other side of the freed
space:
PROGRAM 5 PROGRAM 5
PROGRAM 3 PROGRAM 3
PROGRAM 6
PROGRAM 8 PROGRAM 8
3. There are no programs on either side of
the freed space:
PROGRAM 5 PROGRAM 5
PROGRAM 6
PROGRAM 8 PROGRAM 8
Let’s look at the implications of each of these
cases in terms of what the Memory Manager
has to do to remember the FREE and BUSY
memory spaces.
1. There are programs either side of the freed
space:
PROGRAM 5 PROGRAM 5
PROGRAM 3 PROGRAM 3
PROGRAM 6
PROGRAM 4 PROGRAM 4
PROGRAM 8 PROGRAM 8
1. There are programs either side of the freed
space:
200- 250 20 0 - 2 5 0
S tarts Size Status Starts Size S tatus
20 0 50 BUSY 200 50 B SY
U 25
25 0 50 BUSY
250- 300 250 50 B SY 0 - 3 0 0
30 0 15 BUSY U 30
300- 315
31 5 25 BUSY EE31
315-340 300 15 F 0-315
340-355 340 15 FREE R 34
315 25 BUSY 35
355-380 355 25 BUSY 5-340
340 15 FREE 0-355
PROGRAM 3 PROGRAM 3
PROGRAM 6
PROGRAM 8 PROGRAM 8
2. There are is a program on one side, and
it’s free on the other side of the freed
space:
200- 250 PROGRAM 5 PROGRAM 5 200- 250
PROGRAM 5 PROGRAM 5
PROGRAM 6
PROGRAM 8 PROGRAM 8
3. There are no programs on either side of
the freed space:
250- 300
315- 355
355- 380
3. There are no programs on either side of
the freed space: