Académique Documents
Professionnel Documents
Culture Documents
inspire posterity
CHAPTER 4
Memory Management Issues
Lecture 22
22/10/2019 1
discover yourself
inspire posterity
Buddy System
1. In buddy systems memory can be divided into
sections, with each location being a buddy of
another location.
2. Whenever possible the buddies are combined to
create a larger memory location.
3. If smaller memory needs to be allocated the
buddies are divided, and then reunited (if possible)
when the memory is returned.
4. In reality the memory is combined and only
broken down when requested.
discover yourself
inspire posterity
discover yourself
inspire posterity
discover yourself
inspire posterity
discover yourself
inspire posterity
discover yourself
inspire posterity
discover yourself
inspire posterity
discover yourself
inspire posterity
discover yourself
inspire posterity
discover yourself
inspire posterity
Buddy System in 1MB memory
discover yourself
inspire posterity
Sequence of Requests
• Program A requests memory 34K..64K in size
• Program B requests memory 66K..128K in size
• Program C requests memory 35K..64K in size
• Program D requests memory 67K..128K in size
• Program C releases its memory
• Program A releases its memory
• Program B releases its memory
• Program D releases its memory
discover yourself
inspire posterity
If memory is to be allocated
• Look for a memory slot of a suitable size
– If it is found, it is allocated to the program
– If not, it tries to make a suitable memory slot. The system
does so by trying the following:
• Split a free memory slot larger than the requested memory size
into half
• If the lower limit is reached, then allocate that amount of memory
• Go back to step 1 (look for a memory slot of a suitable size)
• Repeat this process until a suitable memory slot is found
discover yourself
inspire posterity
A binary buddy heap before allocation
A binary buddy heap after allocating a 10 KB block; note the 6 KB wasted because of
rounding up
discover yourself
inspire posterity
If memory is to be freed
• Free the block of memory
• Look at the neighbouring block - is it free too?
• If it is, combine the two, and go back to step 2 and repeat this
process until either the upper limit is reached (all memory is
freed).
discover yourself
inspire posterity
10/22/201
9 23
discover yourself
inspire posterity
FIFO Page Replacement Algorithms
10/22/201
9 24
discover yourself
inspire posterity
Page Replacement Algorithms
10/22/201
9 25
discover yourself
inspire posterity
Page Replacement Algorithms
EXERCISE-1
Evaluate algorithm by running it on a particular string
of memory references (reference string) and computing
the number of page faults on that string
1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5
10/22/201
9 26
discover yourself
inspire posterity
Notice that the number of faults for 4 frames is greater than the number of faults
for 3 frames!! This unexpected result is known as Belady’s anomaly
discover yourself
inspire posterity
EXERCISE-2
Apply FIFO, Using 3 frames
discover yourself
inspire posterity