\chapter{Allocator}

\noindent
====================

Writing Points:
\begin{itemize}
\item
Objective of @uHeapLmmm@.
\item
Design philosophy.
\item
Background and previous design of @uHeapLmmm@.
\item
Distributed design of @uHeapLmmm@.

----- SHOULD WE GIVE IMPLEMENTATION DETAILS HERE? -----

\PAB{Maybe. There might be an Implementation chapter.}
\item
figure.
\item
Advantages of distributed design.
\end{itemize}

The new features added to @uHeapLmmm@ (incl. @malloc_size@ routine)
\CFA alloc interface with examples.
\begin{itemize}
\item
Why did we need it?
\item
The added benefits.
\end{itemize}

----- SHOULD WE GIVE PERFORMANCE AND USABILITY COMPARISON OF DIFFERENT INTERFACES THAT WE TRIED? -----

\PAB{Often Performance is its own chapter. I added one for now.}

Performance evaluation using u-benchmark suite.

\noindent
====================

\newpage
\paragraph{Design 1: Decentralized}
Fixed number of heaps: shard the heap into N heaps each with a bump-area allocated from the @sbrk@ area.
Kernel threads (KT) are assigned to the N heaps.
When KTs $\le$ N, the heaps are uncontented.
When KTs $>$ N, the heaps are contented.
By adjusting N, this approach reduces storage at the cost of speed due to contention.
In all cases, a thread acquires/releases a lock, contented or uncontented.
\begin{cquote}
\centering
\input{AllocDS1}
\end{cquote}
Problems: need to know when a KT is created and destroyed to know when to create/delete the KT's heap.
On KT deletion, its heap freed-storage needs to be distributed somewhere.

\paragraph{Design 2: Centralized}

One heap, but lower bucket sizes are N-shared across KTs.
This design leverages the fact that 95\% of allocation requests are less than 512 bytes and there are only 3--5 different request sizes.
When KTs $\le$ N, the important bucket sizes are uncontented.
When KTs $>$ N, the free buckets are contented.
Therefore, threads are only contending for a small number of buckets, which are distributed among them to reduce contention.
\begin{cquote}
\centering
\input{AllocDS2}
\end{cquote}
Problems: need to know when a kernel thread (KT) is created and destroyed to know when to assign a shared bucket-number.
When no thread is assigned a bucket number, its free storage is unavailable.
It is possible to use sharing and stealing techniques to share/find unused storage, when a free list is unused or empty.
