Example: (Memory Management)
Example: (Memory Management)
Given five memory partitions of 100 KB, 500 KB, 200 KB, 300 KB, and 600 KB (in order), how
would each of the first-fit, best-fit, and worst-fit algorithms place processes of 212 KB(P1), 417
KB(P2), 112 KB(P3), and 426 KB(P4) (in order)?
Which algorithm makes the most efficient use of memory?
Solution
For first fit
first scan the list from the beginning until a hole big enough to hold the process is found. The
first process(P1) has 212 KB therefore the first fit will be the second space (500 KB). Now the
memory partitions look like this (the shaded part is ocupied)
The next process has 426KB. For this process there is no space that is enough for it. Therefore
the process that has stayed for a long time is removed from the memory(In this particular
example we are not given with an information about the algorithm that is used in removing the
process from the memory. Therefore we assumed that the process that was allocated will be
removed first). In this case the longest process that has stayed is the P1 (on the second partition).
This space is enough for our process. So we allocate it to that memory. If it wasn’t enough, we
should continue removing the next longest staying process, which in our case is the process P2
occupying the 600KB memory.
For best fit and worst fit follow this step and work.