\chapter{Introduction} \noindent ==================== Writing Points: \begin{itemize} \item Introduce dynamic memory allocation with brief background. \item Scope of the thesis. \item Importance of memory allocation and micro-benchmark suite. \item Research problem. \item Research objectives. \item The vision behind cfa-malloc. \item An outline of the thesis. \end{itemize} \noindent ==================== \section{Introduction} Dynamic memory allocation and management is one of the core features of C. It gives programmer the freedom to allocate, free, use, and manage dynamic memory himself. The programmer is not given the complete control of the dynamic memory management instead an interface of memory allocator is given to the progrmmer that can be used to allocate/free dynamic memory for the application's use. Memory allocator is a layer between thr programmer and the system. Allocator gets dynamic memory from the system in heap/mmap area of application storage and manages it for programmer's use. GNU C Library (FIX ME: cite this) provides an interchangeable memory allocator that can be replaced with a custom memory allocator that supports required features and fulfills application's custom needs. It also allows others to innovate in memory allocation and design their own memory allocator. GNU C Library has set guidelines that should be followed when designing a standalone memory allocator. GNU C Library requires new memory allocators to have atlease following set of functions in their allocator's interface: \begin{itemize} \item malloc: it allocates and returns a chunk of dynamic memory of requested size (FIX ME: cite man page). \item calloc: it allocates and returns an array in dynamic memory of requested size (FIX ME: cite man page). \item realloc: it reallocates and returns an already allocated chunk of dynamic memory to a new size (FIX ME: cite man page). \item free: it frees an already allocated piece of dynamic memory (FIX ME: cite man page). \end{itemize} In addition to the above functions, GNU C Library also provides some more functions to increase the usability of the dynamic memory allocator. Most standalone allocators also provide all or some of the above additional functions. \begin{itemize} \item aligned_alloc \item malloc_usable_size \item memalign \item posix_memalign \item pvalloc \item valloc \end{itemize} With the rise of concurrent applications, memory allocators should be able to fulfill dynamic memory requests from multiple threads in parallel without causing contention on shared resources. There needs to be a set of a standard benchmarks that can be used to evaluate an allocator's performance in different scenerios. \section{Background} \subsection{Memory Allocation} With dynamic allocation being an important feature of C, there are many standalone memory allocators that have been designed for different purposes. For this thesis, we chose 7 of the most popular and widely used memory allocators. \paragraph{dlmalloc} dlmalloc (FIX ME: cite allocator) is a thread-safe allocator that is single threaded and single heap. dlmalloc maintains free-lists of different sizes to store freed dynamic memory. (FIX ME: cite wasik) \paragraph{hoard} Hoard (FIX ME: cite allocator) is a thread-safe allocator that is multi-threaded and using a heap layer framework. It has per-thred heaps that have thread-local free-lists, and a gloabl shared heap. (FIX ME: cite wasik) \paragraph{jemalloc} jemalloc (FIX ME: cite allocator) is a thread-safe allocator that uses multiple arenas. Each thread is assigned an arena. Each arena has chunks that contain contagious memory regions of same size. An arena has multiple chunks that contain regions of multiple sizes. \paragraph{ptmalloc} ptmalloc (FIX ME: cite allocator) is a modification of dlmalloc. It is a thread-safe multi-threaded memory allocator that uses multiple heaps. ptmalloc heap has similar design to dlmalloc's heap. \paragraph{rpmalloc} rpmalloc (FIX ME: cite allocator) is a thread-safe allocator that is multi-threaded and uses per-thread heap. Each heap has multiple size-classes and each size-calss contains memory regions of the relevant size. \paragraph{tbb malloc} tbb malloc (FIX ME: cite allocator) is a thread-safe allocator that is multi-threaded and uses private heap for each thread. Each private-heap has multiple bins of different sizes. Each bin contains free regions of the same size. \paragraph{tc malloc} tcmalloc (FIX ME: cite allocator) is a thread-safe allocator. It uses per-thread cache to store free objects that prevents contention on shared resources in multi-threaded application. A central free-list is used to refill per-thread cache when it gets empty. \subsection{Benchmarks} There are multiple benchmarks that are built individually and evaluate different aspects of a memory allocator. But, there is not standard set of benchamrks that can be used to evaluate multiple aspects of memory allocators. \paragraph{threadtest} (FIX ME: cite benchmark and hoard) Each thread repeatedly allocates and then deallocates 100,000 objects. Runtime of the benchmark evaluates its efficiency. \paragraph{shbench} (FIX ME: cite benchmark and hoard) Each thread allocates and randomly frees a number of random-sized objects. It is a stress test that also uses runtime to determine efficiency of the allocator. \paragraph{larson} (FIX ME: cite benchmark and hoard) Larson simulates a server environment. Multiple threads are created where each thread allocator and free a number of objects within a size range. Some objects are passed from threads to the child threads to free. It caluculates memory operations per second as an indicator of memory allocator's performance. \section{Research Objectives} Our research objective in this thesis is to: \begin{itemize} \item Design a lightweight concurrent memory allocator with added features and usability that are currently not present in the other memory allocators. \item Design a suite of benchmarks to evalute multiple aspects of a memory allocator. \end{itemize} \section{An outline of the thesis} LAST FIX ME: add outline at the end