This memory allocator was implemented in the C programming language and utilizes the concept of segregated storage to maintain multiple free lists to reduce the allocation time.
This implementation is a special case of segregated fits; the buddy system. Each allocated new block is rounded to the nearest power of 2. Upon allocation, it finds the first available block of size 2^j where k <= j <= m. If j = k there is no need to split the block, otherwise, the block is split in half until j = k. The other half is placed on the appropriate free list. Coalescing stops when the other half (buddy) is allocated.
This approach is efficient because it approximates a best-fit search of the entire heap. The major advantage of this approach is fast searching and coalescing. Every block in the allocator has a header and footer that contain the information for the size of the block, and the allocation information.
The allocator uses tags in the header and footer to determine where to place each free block and whether the block was allocated or not.
mm.{c,h}
: Your solution malloc package.mm.c
is the file that you will be handing in, and is the only file you should modify.mdriver.c
: The malloc driver that tests yourmm.c
fileshort{1,2}-bal.rep
: Two tiny tracefiles to help you get started.Makefile
: Builds the driver
config.h
: Configures the malloc lab driverfsecs.{c,h}
: Wrapper function for the different timer packagesclock.{c,h}
: Routines for accessing the Pentium and Alpha cycle countersfcyc.{c,h}
: Timer functions based on cycle countersftimer.{c,h}
: Timer functions based on interval timers and gettimeofday()memlib.{c,h}
: Models the heap and sbrk function
To build the driver, type "make" to the shell.
To run the driver on a tiny test trace:
unix> mdriver -V -f short1-bal.rep
mm_init
: Initializes the initial memory heap and the segregated free lists.mm_malloc
: Allocates a block by incrementing the brk pointer. Always allocate a block whose size is a multiple of the alignment.mm_free
: Freeing a block. Only works if the pointer was not freed earlier by a call tomm_malloc
ormm_realloc
.mm_realloc
: Implemented simply in terms ofmm_malloc
andmm_free
.
coalesce
: Implements Boundary tag coalescing. Returns pointer to coalesced block based on the textbook CSAPA.extend_heap
: Extends heap with a free block and returns its block pointer.place
: Places a block of asize bytes at start of free block bp and splits if remainder would be at least minimum block size.node
: Adds information to the header and footer of the block about size allocation info and sets the pointer for the previous and next block in the segregated list.free_node
: Frees all block header and footer info in the free list and segregated list.
#####################################################################
# CS:APP Malloc Lab
# Handout files for students
#
# Copyright (c) 2002, R. Bryant and D. O'Hallaron, All rights reserved.
# May not be used, modified, or copied without permission.
#
######################################################################