CS 354 Spring 2013

Lab 4: Kernel Memory Management (200 pts)

  Due: 04/27/2013 (Sat), 11:59PM


Garbage Collection Support (200 pts)

Xinu uses getmem() to allocate heap memory from a single linked list of free memory segments and freemem() to return unused memory to the free memory pool. The kernel keeps track of per-process stack memory so that when a process terminates its stack memory is returned to the free memory list via freestk(). This is not the case, however, for memory allocated by getmem() which gets only freed if a process explicitly deallocates memory by calling freemem() which is voluntary. This puts the kernel at the mercy of user processes which is undesirable. Even when an application programmer ardently tries to free allocated memory before exiting, programming mistakes and bugs may result in build-up of memory garbage. These memory leakage problems may be addressed by injecting garbage collection support inside the kernel that keeps track of allocated memory on a per-process basis and returns them to the free list when a process terminates (should it not have done so). The goal of this problem is to implement a garbage collection mechanism inside Xinu which allows straightforward book keeping of per-process allocated memory.

Design and implement garbage collection support in Xinu by modifying the system calls, getmem() and freemem(), and relevant parts of the kernel such that perfect garbage collection is assured. That is, when a process terminates, it is guaranteed that all memory segments allocated to the process have been returned to the free list. To achieve clean design and modularity, we will not rewrite getmem() and freemem() but export garbage collection enabled sibling system calls getmemgb() and freememgb() that the application programmer is asked to use instead. Of course, the kernel can always enforce garbage collection by making getmem() and freemem() to be wrapper functions to getmemgb() and freememgb().

Benchmark your garbage collection enabled Xinu kernel on two test scenarios where each involves 3 concurrent processes. To demonstrate correct functioning of your system, your test applications should do their own memory accounting to keep track of how much memory they have been allocated and how much memory they have freed and not freed before termination. One must be careful to do the accounting arithmetic correctly so that they accurately mirror the rounding performed in the Xinu kernel. The result of the accounting done by an application must be compared with accounting performed inside the modified Xinu kernel to gauge correctness of the garbage collection support. Describe the design of your specific implementation and results in Lab4Answers.pdf.


Important: Please comment your code changes in Xinu such that (a) where changes are made is highlighted, and (b) what changes are made is conveyed.


Turnin Instructions

Please follow the same turnin procedure as before with lab4 in place of lab3.