Project #7: Heap Memory on a Multicore Architecture

Submit: Turn in your entire xinu-hw7 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-hw6 xinu-hw7

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

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

Multicore Memory Safety

What happens when multiple threads/processes 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 thread-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 a free lists of available memory blocks on the heap. 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. Take care to properly adjust the starting stack pointer in create() -- whereas getstk() returned a pointer to the highest address in the newly allocated stack, getmem() will return a pointer to this lowest, or "base" address of the stack.

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 2022 Mar 30 13:57 DWB]