Exercise 3: Memory compaction
Introduction
Since MINIX does not support virtual memory you run the risk
of running out of memory because of memory fragmentation.
In this exercise you have to modify the memory manager to
prevent this by compacting memory when it runs out.
Assignment and hints
- Modify the memory manager to allow a program to exec when there is
enough free memory for it but not necessarily in one consecutive
block. Effectively this means you have to defragment memory until
you create a large enough hole for the program to fit.
- Programs with separate I and D should be handled as
two separate memory blocks.
- In order to implement memory compaction you should add a new
call to SYSTASK which atomically copies a block of memory
(i.e. text or data) and updates the process map.
This prevents a race condition between MM and blocking device
tasks. You can get bonus points for solving the race condition
between FS and MM for DMA-able character devices.
- Memory compaction only has to work for the exec system
call (i.e. not for the fork system call).
Relevant information can be found in the OS book in sections: 3.10,
4.7.1-6, 4.8.1-5, and 4.8.8. Check at least the index
for the following references:
- MINIX system call: fork
- MINIX system call: exec
Testing
The following are some suggested tests. Your code should pass these tests to
get a grade at all.
- Start a number of 512KB processes until memory runs out.
Kill two consecutive (in memory) processes and start a 1MB process.
- Same as above, but with two non-consecutive (in memory) processes.
The first test should work, with or without memory compaction. The second
test should only work on a MINIX kernel with memory compaction.
To properly test this exercise, you should probably add extra test code to
the kernel to test your exercise.
Manual pages
- chmem(1)
- change memory allocation