Assignment #4: Dynamic Storage Allocator

Trivia email to TA by 11:59pm, Monday, April 6.
Full assignment due by 11:59pm, Monday, April 13.

Introduction:

In this lab you will be writing a dynamic storage allocator for C programs, i.e., your own version of the malloc, free, and realloc routines. You are encouraged to explore the design space creatively and implement an allocator that is correct, efficient and fast.

The managing TA for this assignment is Brandon Allard (ballard@u.rochester.edu). Please first direct your questions about this assignment to the managing TA who has the most intimate knowledge about the assignment setup and specific details. The TA's office hours for this assignment are:

The office hours are held at Hylan 301.

You can form a group of two for this assignment. You can also choose to work alone. You are able to choose to work in a group of two for four assignments (assignments #2/#3/#4/#5). It is our policy that you can NOT work with the same team partner for more than two assignments. If you do, we will apply 50% penalty on your third and four assignments with the same grouping.

Hand Out Instructions:

Start by copying /u/cs252/labs15/malloclab-handout.tar to a protected directory in which you plan to do your work. Then give the command:

    tar xvf malloclab-handout.tar
      
This will cause a bunch of files to be unpacked into the directory. The only file you will be modifying and handing in is mm.c.

The mdriver.c program is a driver program that allows you to evaluate the performance of your solution. Use the command make to generate the driver code and run it with the command ./mdriver –V. (The –V flag displays helpful summary information.)

Looking at the file mm.c you'll notice a C structure team into which you should insert the requested identifying information about the one or two individuals comprising your programming team. Do this right away so you don't forget.

When you have completed the lab, you will hand in only one file (mm.c), which contains your solution.

How to Work on the Lab:

Your dynamic storage allocator will consist of the following four functions, which are declared in mm.h and defined in mm.c.

The mm.c file we have given you implements the simplest but still functionally correct malloc package that we could think of. Using this as a starting place, modify these functions (and possibly define other private static functions), so that they obey the following semantics:

These semantics match the the semantics of the corresponding libc malloc, realloc, and free routines. Type man malloc to the shell for complete documentation.

Heap Consistency Checker:

Dynamic memory allocators are notoriously tricky beasts to program correctly and efficiently. They are difficult to program correctly because they involve a lot of untyped pointer manipulation. You will find it very helpful to write a heap checker that scans the heap and checks it for consistency.

Some examples of what a heap checker might check are:

Your heap checker will consist of the function int mm_check(void) in mm.c. It will check any invariants or consistency conditions you consider prudent. It returns a nonzero value if and only if your heap is consistent. You are not limited to the listed suggestions nor are you required to check all of them. You are encouraged to print out error messages when mm_check fails.

This consistency checker is for your own debugging during development. When you submit mm.c, make sure to remove any calls to mm_check as they will slow down your throughput. Style points will be given for your mm_check function. Make sure to put in comments and document what you are checking.

Support Routines:

The memlib.c package simulates the OS portion of the memory system for your dynamic memory allocator. You can invoke the following functions in memlib.c:

The Trace-driven Driver Program:

The driver program mdriver.c in the malloclab-handout.tar distribution tests your mm.c package for correctness, space utilization, and throughput. The driver program is controlled by a set of trace files. Some small traces are included in the malloclab-handout.tar distribution. The larger traces that we will test your file with are located at /u/cs252/labs15/malloctraces/. These larger traces are automatically run if you execute mdriver without a -f argument. Each trace file contains a sequence of allocate, reallocate, and free directions that instruct the driver to call your mm_malloc, mm_realloc, and mm_free routines in some sequence.

The driver mdriver.c accepts the following command line arguments:

Programming Rules:

Evaluation:

You will receive zero points if you break any of the rules or your code is buggy and crashes the driver.  Otherwise, your grade will be calculated as follows:

Hints:

“Trivia” Assignment:

By Monday, April 6, send email to TA Brandon Allard with the subject line "[CSC252] Assign#4 Trivia - uname1 uname2" (without the quotes, where uname is your login name) containing answers to the following questions (a single email per team is expected):

  1. Are you working alone or in a team of two?  If the latter, who is your partner?
  2. After you have inputed your team information, what output do you get when you run the following command?
        mdriver -V -f short2-bal.rep
    	  
  3. What is the value of ALIGNMENT defined in mm.c? How many words is this?
  4. What does the mem_sbrk function do?  How does it indicate an allocation error?
  5. How do the default implementations of mm_malloc, mm_free, and mm_realloc work? What is obviously bad about these implementations?

Turn-in:

The “trivia” assignment will be submitted via email. You should electronically turn in your main assignment through Blackboard. You only need to turn in your completed mm.c. Before turn-in, be sure that you have

Late Turn-in Policy:

Late turn-ins will be accepted for up to three days, with 10% penalty for each late day. No turn-ins more than three-day late will be accepted.