Project #8: Heap Memory

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

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

Fixing a bug in create.c

As some of you may have seen, sometimes your OS will crash when it gets to the null process. If you wrote more elaborate testcases last assignment that called user_yield, the same error will occur. This was due to user processes sharing the same kernel stack. Since they are sharing the same kernel stack, if one process yields, then the next process will overwrite any contents the first process stored on it's kernel stack. Once the first process runs again, all it's kernel variables will be overwritten! This is very bad! There's a simple one line fix to address this issue, when setting the PREG_KERNSP, instead of setting it to _kernsp, we need to set it to (ulong)pgalloc() + PAGE_SIZE This change will allow all proccess to get their own kernel stack, so they're not overwriting each other. To learn more about stack and how compilers use them, take COSC 4400: Compilers in Fall 2024 (or COSC 3410: Programming Languages next semester) with Dr. Brylow!

Getmem and Freemem

The files include/memory.h and system/vm_userinit.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().

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 2023 Mar 29 13:57 DWB]