Due date: Wed Jun 01 11:59 pm - Hard deadline: Sat Jun 04 11:59 pm
Assignment by Julie Zelenski, based on original assignment given by Randal Bryant & David O'Hallaron (CMU)
[Quick Links: Implementation details, Advice page, Grading]
In completing this assignment, you will:
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.
malloc man page for what constitutes a well-formed request and the required handling to which your allocator must conform. Note there are a few oddballs (malloc(0) and the like) to take into account. Ignore esoteric details from the NOTES section of the man page.mymalloc, myrealloc, and myfree to avoid clashes with the libc version. You will also implement myinit to configure the initial state and validate_heap to verify internal heap consistency.INT_MAX bytes. If asked for a block larger than the max size, your allocate should return NULL, just as with any request that cannot be serviced. Every allocated block must be aligned to an address that is a multiple of the ALIGNMENT constant (8). It's your choice whether small requests are rounded up to some minimum size.segment.h.segment.h. By "memory-management" we specifically mean those operations that allocate or deallocate memory, so no calls to malloc, realloc, free, calloc, sbrk, brk, mmap, or related variants. The use of other library functions is fine, e.g. memmove and memset can be used as they do not allocate or deallocate memory.validate_heap function will be called from our test harness when checking correctness to verify the internal consistency of the heap data structures after servicing each request. This is here to help you with debugging. The validity check will not be made during any performance testing, so there is no concern about its efficiency (or lack thereof).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.
alloctest with no arguments, it runs all the scripts from /afs/ir/class/cs107/samples/assign7. Invoke wth the -f flag to change which scripts are being run. The -f argument is the path to a single script file or a directory of script files./afs/ir/class/cs107/samples/assign7 contains a collection of varied scripts. These large scripts are best suited for testing the performance of an already-debugged implementation. The ones named x-trace were constructed by tracing the allocation calls made by a running program, e.g. reassemble-trace traces assignment 1. These represent real world testing patterns. The scripts named x-pattern were mechanically generated via patterns such as alternately allocating a small and large chunk.alloctest -c will only verify correctness, alloctest -p will only measure performance. The default (no flags) does both: first correctness, then performance.alloctest calls the allocator's myinit function after executing one script and before starting another. To prevent bugs due to ghost heap housekeeping leftover from the previous script, your myinit function must correctly wipe the slate clean, removing any previous heap contents and starting fresh.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:
U = utilization - 25T = throughput / 2U and T are capped to the range [0, 50]. Full-credit benchmarks are U = 40 (utilization >= 65%) and T = 40 (throughput >= 80%). There are up to 10 bonus points per category for exceeding the benchmarks.= 1.5*min(U,T) + .5*max(U,T). This blend rewards a balance between the two, rather than going to extremes to optimize one at the expense of the other.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)
validate_heap routine.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.
Submissions received by the assignment deadline will receive an on-time bonus equal to 5% of the functionality points earned.
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:
simple and alloctest. Edit ALLOCATOR_EXTRA_CFLAGS to configure the best build settings for your allocator; make no other changes to the Makefile.allocator.c to implement your allocator (remove/replace the trivial implementation given in starter).segment.c module provides the low-level memory allocator. Do not edit these files.fcyc.c module is the cycle-counting timer from Chapter 5 of the Bryant and O'Hallaron. Do not edit these files.simple.c module is a sample program that manipulates linked lists and strings using dynamic allocation. You can use/change/cannibalize this program for testing.alloctest.c module contains the script-driven test harness to evaluate your allocator. Do not edit this file.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.
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 hard 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 hard 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!