Compare the first-fit, best-fit and worst-fit memory allocation strategies.
MediumConceptMemory Management
Answer
When memory is allocated in variable-size contiguous blocks, these strategies decide which free hole a new process gets.
- First fit: take the first hole that is big enough. It is fast and works well in practice.
- Best fit: take the smallest hole that is big enough. It leaves the smallest leftover, but it must search the whole list and creates tiny holes too small to use.
- Worst fit: take the largest hole, hoping the leftover stays useful. It usually performs worst.
- Simulations show that first fit and best fit use memory better than worst fit, and first fit is generally faster.
Example: free holes, in order, of 100, 500, 200, 300 and 600 KB; requests of 212, 417, 112 and 426 KB arrive in that order.
| Request | First fit | Best fit | Worst fit |
|---|---|---|---|
| 212 | 500 (288 left) | 300 | 600 (388 left) |
| 417 | 600 | 500 | 500 |
| 112 | the 288 left over | 200 | the 388 left over |
| 426 | must wait | 600 | must wait |
Only best fit places all four here. With first fit and worst fit, more than 426 KB is free in total, but no single hole is large enough.