Assignment 7: Heap allocator

Due: Fri Mar 17 11:59 pm
No late submissions accepted.

Assignment by Julie Zelenski, based on original assignment given by Randal Bryant & David O'Hallaron (CMU)

Learning goals

In completing this assignment, you will:

  1. study the internals of the heap allocator
  2. experiment with the process of evaluating and choosing among alternative designs
  3. apply optimization techniques to find and mitigate runtime/memory inefficiencies
  4. explore performance trade-offs and weigh improvements against the complexity of code required to achieve them
  5. bring together all of your CS107 skills and knowledge into a satisfying capstone experience!

Your assignment

You are to design and implement an allocator that implements malloc, realloc, and free. Your allocator obtains a large contiguous segment from the OS and parcels out this segment to service dynamic allocation requests. The key goals for the allocator include:

Just three little functions? How hard can that be? :-) The challenge is to strike a balance between tight memory utilization and high throughput, while maintaining correctness in all situations. It is possible to write an efficient allocator with a couple hundred lines of code. However, it will require your most skilled and sophisticated coding and you may end up more proud of those three functions than any code you've written heretofore. What a great way to finish off an awesome quarter!

For this assignment, you have the option of working in a team of two or working individually. The project requirements are the same either way. A team makes one submission and both partners receive the same score. Read our advice for successful partnership.

Implementation requirements

Using the alloctest program and script files

You can do simple testing of your allocator with an ordinary C program that makes targeted malloc/realloc/free calls. The given simple.c program can be used in this way. We also provide alloctest.c, a script-based test harness for the allocator. The alloctest program reads a script file, executes its requests, verifies they were correctly serviced, and measures allocator performance. A sample report on one script is shown below.

alloctest -f tiny1.script
Evaluating allocator on tiny1....done.

 script name     correct?    utilization   requests       secs        Kreq/sec
-------------------------------------------------------------------------------
tiny1                Y            33%           12       0.000018        675
-------------------------------------------------------------------------------

Aggregate 1 of 1                  33%           12       0.000018        675
33% (utilization) 6% (throughput, expressed relative to performance target)

Below is an overview of how alloctest operates. You can review the code in alloctest.c for further details.

Grading

Background information on how we grade assignments. The focus of this assignment, and much of the weight in grading, is concentrated on efficiency.

Correctness (48 points)

Performance (80 points)

We will use alloctest to measure your allocator's utilization and throughput on a set of mixed scripts that are similar, but not identical, to the published samples. The scoring formula will be as follows:

Submissions with bugs that interfere with performance testing will earn points at a reduced rate. The performance points formula will be applied to the scripts which operate correctly with a penalty adjustment for the failures.

The scripts use for performance grading will be similar to the set of sample scripts. Your allocator's performance on the published samples is predictive of the measurement we will make for grading, but not an exact match. The goal is not to tune your allocator to perform at its best on exactly and only the samples, but instead develop a design that fares well in a wide variety of scenarios, for which the samples are representative possibilities.

Code quality (buckets weighted to contribute ~20 points)

Design documentation (32 points)

A number of points are allocated for the readme file where you will document your allocator design, along with your process and results. You are to address the issues below with clear, complete, and concise writing. The intended audience is a programmer-literate peer.

We will evaluate your design document on its thoughtfulness and completeness in describing, analyzing, and evaluating your design and process. Readme credit is not tied to successful performance results. If your results are not what you'd hoped for, use the readme to tell us about it, i.e. the observed problems, what its root cause seems to be, what you tried that didn't pan out, what you learned in the process, and so on.

Getting started

Check out a copy of the starter project from your cs107 repository using the command

hg clone /afs/ir/class/cs107/repos/assign7/$USER assign7

The starter repo contains these files:

Special attention to the Honor Code

Before you begin coding, you'll want to consider a range of design options. The textbook contains good foundation material which you are encouraged to review as a starting point. You may also find it helpful to talk over implementation options and trade-offs with classmates. Your readme must properly cite any external resources or discussions that influenced your design. When it comes to code-level specifics, your allocator must be your independent work. Under no circumstances should you be studying code from outside sources nor incorporating such code. If you accidentally stumble across allocator code written by someone else, we expect you to immediately about-face from it and get back to designing and writing your own allocator. We have a zero-tolerance policy for submissions containing code that has been adopted/borrowed from others. Lacking citation, this act constitutes plagiarism and will handled as a violation of the Honor Code.

A student who is retaking the course may not re-use the design, code, or documentation from any previous effort. The prohibition against re-use applies regardless of whether the original submission was partnered or individual. The best approach to avoiding problems is to discard all work from the past, as it can be a temptation that you're better off without.

Finishing

When finished, don't forget to submit your files for grading. Only one partner makes the submission, not both.

Absolutely no submissions will be accepted after the deadline, nor will there be any option to make up from a missed/poor submission. Cutting it too close can land you on the wrong side of the deadline with no recourse other than to discard all your hard work into the rubbish bin. Do not let this happen to you -- submit early, submit often, so you'll have an insurance policy against any unexpected last-minute mishap.

Check in with post-task self-check and it's definitely time to celebrate-- congratulations on an awesome quarter!



Contents