Project #8: Heap Memory on a Multicore Architecture

Submit: Turn in your entire xinu-hw8 directory source files using the turnin command on morbius.mscsnet.mu.edu or one of the other Systems Lab machines. Please run "make clean" in the compile/ subdirectory just before submission to reduce unnecessary space consumption.

Work should be completed in pairs. Be certain to include both names in the comment block at the top of all source code files, with a TA-BOT:MAILTO comment line including any addresses that should automatically receive results. It would be courteous to confirm with your partner when submitting the assignment.

Dynamic Memory Allocation

Preparation

First, make a fresh copy of your work thus far.
      cp -R xinu-hw7 xinu-hw8

Then, untar the new project files on top of it:
      tar xvzf ~brylow/os/Projects/xinu-hw8.tgz

Remember: these two commands should be run in the same path. Don't change directories before running this tar command, or else you'll have two xinu-hw8 directories in different places.

Be certain to make clean before compiling for the first time.

Multicore Memory Safety

What happens when multiple cores attempt to allocate or free the same memory block at the same time? This race condition can be avoided if the proper precautions are taken. To make your implementation multicore-safe, refer to the TODO statements in getmem.c, freemem.c, malloc.c, and free.c.

Getmem and Freemem

The files include/memory.h and system/initialize.c define and initialize four free lists of available memory blocks on the heap, one for each core. Implement system/getmem.c and system/freemem.c to dole out blocks of requested memory and properly maintain the free list. Use First Fit with simple compaction. (Compaction is the "stretch" problem in this assignment -- get everything else working first.)

Malloc and Free

Your getmem() and freemem() functions assume that the programmer independently tracks the size of an allocated block, and passes that size as the second parameter to freemem(). Most operating systems APIs assume that having the pointer to the beginning of the block is enough to free it. This can be accomplished through the use of accounting information, often hidden adjacent to the memory block itself.

Implement malloc() and free() to work as wrappers around getmem() and freemem() to provide this API. The malloc() function should pad the request size to include an accounting block before calling getmem(), and stores the accounting information after the allocation. The free() function recovers the accounting information to provide the size to freemem().

Down With Getstk()

Delete the file system/getstk.c from your kernel. This holdover from our earliest assignments is incompatible with a properly functioning dynamic memory allocation system, and must no longer be used. Replace the lone call to the getstk() function in system/create.c with a proper call to getmem() instead. Modify system/kill.c to call freemem() to deallocate a process stack when a process dies.

Use the stkbase and stklen fields of your process control block to store the base address and length of the dynamically allocated memory block that comprises a process stack.

Grading

Project credit will be divvied up evenly between getting memory, freeing memory, compaction, and getstk() removal. By now, you should be aware that rigorous testing is the key to success in these projects. Our test cases will include at least:


[back]

[Revised 2020 Mar 24 15:11 DWB]