Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • doc/papers/llheap/Paper.tex

    r765ee42 r77afbb4  
    7777\lstset{
    7878columns=fullflexible,
    79 basicstyle=\linespread{0.9}\sf,                 % reduce line spacing and use sanserif font
    80 stringstyle=\small\tt,                                  % use typewriter font
    81 tabsize=5,                                                              % N space tabbing
    82 xleftmargin=\parindentlnth,                             % indent code to paragraph indentation
    83 escapechar=\$,                                                  % LaTeX escape in CFA code
    84 %mathescape=true,                                               % LaTeX math escape in CFA code $...$
    85 keepspaces=true,                                                %
    86 showstringspaces=false,                                 % do not show spaces with cup
    87 showlines=true,                                                 % show blank lines at end of code
    88 aboveskip=4pt,                                                  % spacing above/below code block
    89 belowskip=2pt,
    90 numberstyle=\footnotesize\sf,                   % numbering style
    91 moredelim=**[is][\color{red}]{@}{@},
     79basicstyle=\linespread{0.9}\sf,                                                 % reduce line spacing and use sanserif font
     80stringstyle=\tt,                                                                                % use typewriter font
     81tabsize=5,                                                                                              % N space tabbing
     82xleftmargin=\parindentlnth,                                                             % indent code to paragraph indentation
     83%mathescape=true,                                                                               % LaTeX math escape in CFA code $...$
     84escapechar=\$,                                                                                  % LaTeX escape in CFA code
     85keepspaces=true,                                                                                %
     86showstringspaces=false,                                                                 % do not show spaces with cup
     87showlines=true,                                                                                 % show blank lines at end of code
     88aboveskip=4pt,                                                                                  % spacing above/below code block
     89belowskip=3pt,
     90moredelim=**[is][\color{red}]{`}{`},
    9291}% lstset
    9392
     
    10831082
    10841083The primary design objective for llheap is low-latency across all allocator calls independent of application access-patterns and/or number of threads, \ie very seldom does the allocator have a delay during an allocator call.
    1085 Excluded from the low-latency objective are (large) allocations requiring initialization, \eg zero fill, and/or data copying, which are outside the allocator's purview.
     1084(Large allocations requiring initialization, \eg zero fill, and/or copying are not covered by the low-latency objective.)
    10861085A direct consequence of this objective is very simple or no storage coalescing;
    10871086hence, llheap's design is willing to use more storage to lower latency.
    10881087This objective is apropos because systems research and industrial applications are striving for low latency and computers have huge amounts of RAM memory.
    1089 Finally, llheap's performance should be comparable with the current best allocators, both in space and time (see performance comparison in Section~\ref{c:Performance}).
     1088Finally, llheap's performance should be comparable with the current best allocators (see performance comparison in Section~\ref{c:Performance}).
    10901089
    10911090% The objective of llheap's new design was to fulfill following requirements:
     
    12061205% \label{s:AllocationFastpath}
    12071206
    1208 llheap's design was reviewed and changed multiple times during its development, with the final choices are discussed here.
     1207llheap's design was reviewed and changed multiple times during its development.  Only the final design choices are
     1208discussed in this paper.
    12091209(See~\cite{Zulfiqar22} for a discussion of alternate choices and reasons for rejecting them.)
    12101210All designs were analyzed for the allocation/free \newterm{fastpath}, \ie when an allocation can immediately return free storage or returned storage is not coalesced.
    1211 The heap model chosen is 1:1, which is the T:H model with T = H, where there is one thread-local heap for each KT.
     1211The heap model choosen is 1:1, which is the T:H model with T = H, where there is one thread-local heap for each KT.
    12121212(See Figure~\ref{f:THSharedHeaps} but with a heap bucket per KT and no bucket or local-pool lock.)
    12131213Hence, immediately after a KT starts, its heap is created and just before a KT terminates, its heap is (logically) deleted.
     
    14261426
    14271427
    1428 Algorithm~\ref{alg:heapObjectFreeOwn} shows the deallocation (free) outline for an object at address $A$ with ownership.
     1428Algorithm~\ref{alg:heapObjectFreeOwn} shows the de-allocation (free) outline for an object at address $A$ with ownership.
    14291429First, the address is divided into small (@sbrk@) or large (@mmap@).
    14301430For large allocations, the storage is unmapped back to the OS.
     
    14331433If the bucket is not local to the thread, the allocation is pushed onto the owning thread's associated away stack.
    14341434
    1435 Algorithm~\ref{alg:heapObjectFreeNoOwn} shows the deallocation (free) outline for an object at address $A$ without ownership.
     1435Algorithm~\ref{alg:heapObjectFreeNoOwn} shows the de-allocation (free) outline for an object at address $A$ without ownership.
    14361436The algorithm is the same as for ownership except if the bucket is not local to the thread.
    14371437Then the corresponding bucket of the owner thread is computed for the deallocating thread, and the allocation is pushed onto the deallocating thread's bucket.
     
    17921792The C dynamic-memory API is extended with the following routines:
    17931793
    1794 \medskip\noindent
    1795 \lstinline{void * aalloc( size_t dim, size_t elemSize )}
    1796 extends @calloc@ for allocating a dynamic array of objects with total size @dim@ $\times$ @elemSize@ but \emph{without} zero-filling the memory.
    1797 @aalloc@ is significantly faster than @calloc@, which is the only alternative given by the standard memory-allocation routines for array allocation.
     1794\paragraph{\lstinline{void * aalloc( size_t dim, size_t elemSize )}}
     1795extends @calloc@ for allocating a dynamic array of objects without calculating the total size of array explicitly but \emph{without} zero-filling the memory.
     1796@aalloc@ is significantly faster than @calloc@, which is the only alternative given by the standard memory-allocation routines.
     1797
     1798\noindent\textbf{Usage}
     1799@aalloc@ takes two parameters.
     1800\begin{itemize}[topsep=3pt,itemsep=2pt,parsep=0pt]
     1801\item
     1802@dim@: number of array objects
     1803\item
     1804@elemSize@: size of array object
     1805\end{itemize}
    17981806It returns the address of the dynamic array or @NULL@ if either @dim@ or @elemSize@ are zero.
    17991807
    1800 \medskip\noindent
    1801 \lstinline{void * resize( void * oaddr, size_t size )}
    1802 extends @realloc@ for resizing an existing allocation, @oaddr@, to the new @size@ (smaller or larger than previous) \emph{without} copying previous data into the new allocation or preserving sticky properties.
     1808\paragraph{\lstinline{void * resize( void * oaddr, size_t size )}}
     1809extends @realloc@ for resizing an existing allocation \emph{without} copying previous data into the new allocation or preserving sticky properties.
    18031810@resize@ is significantly faster than @realloc@, which is the only alternative.
     1811
     1812\noindent\textbf{Usage}
     1813@resize@ takes two parameters.
     1814\begin{itemize}[topsep=3pt,itemsep=2pt,parsep=0pt]
     1815\item
     1816@oaddr@: address to be resized
     1817\item
     1818@size@: new allocation size (smaller or larger than previous)
     1819\end{itemize}
    18041820It returns the address of the old or new storage with the specified new size or @NULL@ if @size@ is zero.
    18051821
    1806 \medskip\noindent
    1807 \lstinline{void * amemalign( size_t alignment, size_t dim, size_t elemSize )}
    1808 extends @aalloc@ and @memalign@ for allocating a dynamic array of objects with the starting address on the @alignment@ boundary.
     1822\paragraph{\lstinline{void * amemalign( size_t alignment, size_t dim, size_t elemSize )}}
     1823extends @aalloc@ and @memalign@ for allocating an aligned dynamic array of objects.
    18091824Sets sticky alignment property.
     1825
     1826\noindent\textbf{Usage}
     1827@amemalign@ takes three parameters.
     1828\begin{itemize}[topsep=3pt,itemsep=2pt,parsep=0pt]
     1829\item
     1830@alignment@: alignment requirement
     1831\item
     1832@dim@: number of array objects
     1833\item
     1834@elemSize@: size of array object
     1835\end{itemize}
    18101836It returns the address of the aligned dynamic-array or @NULL@ if either @dim@ or @elemSize@ are zero.
    18111837
    1812 \medskip\noindent
    1813 \lstinline{void * cmemalign( size_t alignment, size_t dim, size_t elemSize )}
     1838\paragraph{\lstinline{void * cmemalign( size_t alignment, size_t dim, size_t elemSize )}}
    18141839extends @amemalign@ with zero fill and has the same usage as @amemalign@.
    18151840Sets sticky zero-fill and alignment property.
    18161841It returns the address of the aligned, zero-filled dynamic-array or @NULL@ if either @dim@ or @elemSize@ are zero.
    18171842
    1818 \medskip\noindent
    1819 \lstinline{size_t malloc_alignment( void * addr )}
    1820 returns the object alignment, where objects not allocated with alignment return the minimal allocation alignment.
    1821 For use in aligning similar allocations.
    1822 
    1823 \medskip\noindent
    1824 \lstinline{bool malloc_zero_fill( void * addr )}
    1825 returns true if the objects zero-fill sticky property is set and false otherwise.
    1826 For use in zero filling similar allocations.
    1827 
    1828 \medskip\noindent
    1829 \lstinline{size_t malloc_size( void * addr )}
    1830 returns the object's request size, which is updated when an object is resized or zero if @addr@ is @NULL@ (see also @malloc_usable_size@).
    1831 For use in similar allocations.
    1832 
    1833 \medskip\noindent
    1834 \lstinline{int malloc_stats_fd( int fd )}
    1835 changes the file descriptor where @malloc_stats@ writes statistics (default @stdout@) and returns the previous file descriptor.
    1836 
    1837 \medskip\noindent
    1838 \lstinline{size_t malloc_expansion()}
     1843\paragraph{\lstinline{size_t malloc_alignment( void * addr )}}
     1844returns the alignment of the dynamic object for use in aligning similar allocations.
     1845
     1846\noindent\textbf{Usage}
     1847@malloc_alignment@ takes one parameter.
     1848\begin{itemize}[topsep=3pt,itemsep=2pt,parsep=0pt]
     1849\item
     1850@addr@: address of an allocated object.
     1851\end{itemize}
     1852It returns the alignment of the given object, where objects not allocated with alignment return the minimal allocation alignment.
     1853
     1854\paragraph{\lstinline{bool malloc_zero_fill( void * addr )}}
     1855returns true if the object has the zero-fill sticky property for use in zero filling similar allocations.
     1856
     1857\noindent\textbf{Usage}
     1858@malloc_zero_fill@ takes one parameters.
     1859
     1860\begin{itemize}[topsep=3pt,itemsep=2pt,parsep=0pt]
     1861\item
     1862@addr@: address of an allocated object.
     1863\end{itemize}
     1864It returns true if the zero-fill sticky property is set and false otherwise.
     1865
     1866\paragraph{\lstinline{size_t malloc_size( void * addr )}}
     1867returns the request size of the dynamic object (updated when an object is resized) for use in similar allocations.
     1868See also @malloc_usable_size@.
     1869
     1870\noindent\textbf{Usage}
     1871@malloc_size@ takes one parameters.
     1872\begin{itemize}[topsep=3pt,itemsep=2pt,parsep=0pt]
     1873\item
     1874@addr@: address of an allocated object.
     1875\end{itemize}
     1876It returns the request size or zero if @addr@ is @NULL@.
     1877
     1878\paragraph{\lstinline{int malloc_stats_fd( int fd )}}
     1879changes the file descriptor where @malloc_stats@ writes statistics (default @stdout@).
     1880
     1881\noindent\textbf{Usage}
     1882@malloc_stats_fd@ takes one parameters.
     1883\begin{itemize}[topsep=3pt,itemsep=2pt,parsep=0pt]
     1884\item
     1885@fd@: file descriptor.
     1886\end{itemize}
     1887It returns the previous file descriptor.
     1888
     1889\paragraph{\lstinline{size_t malloc_expansion()}}
    18391890\label{p:malloc_expansion}
    18401891set the amount (bytes) to extend the heap when there is insufficient free storage to service an allocation request.
    18411892It returns the heap extension size used throughout a program when requesting more memory from the system using @sbrk@ system-call, \ie called once at heap initialization.
    18421893
    1843 \medskip\noindent
    1844 \lstinline{size_t malloc_mmap_start()}
     1894\paragraph{\lstinline{size_t malloc_mmap_start()}}
    18451895set the crossover between allocations occurring in the @sbrk@ area or separately mapped.
    18461896It returns the crossover point used throughout a program, \ie called once at heap initialization.
    18471897
    1848 \medskip\noindent
    1849 \lstinline{size_t malloc_unfreed()}
     1898\paragraph{\lstinline{size_t malloc_unfreed()}}
    18501899\label{p:malloc_unfreed}
    18511900amount subtracted to adjust for unfreed program storage (debug only).
    1852 It returns the new subtraction amount and called by @malloc_stats@ (discussed in Section~\ref{}).
     1901It returns the new subtraction amount and called by @malloc_stats@.
    18531902
    18541903
     
    18571906The following extensions take advantage of overload polymorphism in the \CC type-system.
    18581907
    1859 \medskip\noindent
    1860 \lstinline{void * resize( void * oaddr, size_t nalign, size_t size )}
    1861 extends @resize@ with an alignment requirement, @nalign@.
     1908\paragraph{\lstinline{void * resize( void * oaddr, size_t nalign, size_t size )}}
     1909extends @resize@ with an alignment re\-quirement.
     1910
     1911\noindent\textbf{Usage}
     1912takes three parameters.
     1913\begin{itemize}[topsep=3pt,itemsep=2pt,parsep=0pt]
     1914\item
     1915@oaddr@: address to be resized
     1916\item
     1917@nalign@: alignment requirement
     1918\item
     1919@size@: new allocation size (smaller or larger than previous)
     1920\end{itemize}
    18621921It returns the address of the old or new storage with the specified new size and alignment, or @NULL@ if @size@ is zero.
    18631922
    1864 \medskip\noindent
    1865 \lstinline{void * realloc( void * oaddr, size_t nalign, size_t size )}
    1866 extends @realloc@ with an alignment requirement, @nalign@.
    1867 It returns the address of the old or new storage with the specified new size and alignment, or @NULL@ if @size@ is zero.
     1923\paragraph{\lstinline{void * realloc( void * oaddr, size_t nalign, size_t size )}}
     1924extends @realloc@ with an alignment re\-quirement and has the same usage as aligned @resize@.
    18681925
    18691926
     
    19221979object size: like the \CFA's C-interface, programmers do not have to specify object size or cast allocation results.
    19231980\end{itemize}
    1924 Note, postfix function call is an alternative call syntax, using backtick @`@, so the argument appears before the function name, \eg
     1981Note, postfix function call is an alternative call syntax, using backtick @`@, where the argument appears before the function name, \eg
    19251982\begin{cfa}
    19261983duration ?@`@h( int h );                // ? denote the position of the function operand
     
    19301987\end{cfa}
    19311988
    1932 The following extensions take advantage of overload polymorphism in the \CC type-system.
    1933 
    1934 \medskip\noindent
    1935 \lstinline{T * alloc( ... )} or \lstinline{T * alloc( size_t dim, ... )}
     1989\paragraph{\lstinline{T * alloc( ... )} or \lstinline{T * alloc( size_t dim, ... )}}
    19361990is overloaded with a variable number of specific allocation operations, or an integer dimension parameter followed by a variable number of specific allocation operations.
    19371991These allocation operations can be passed as named arguments when calling the \lstinline{alloc} routine.
     
    19421996
    19431997The allocation property functions are:
    1944 
    1945 \medskip\noindent
    1946 \lstinline{T_align ?`align( size_t alignment )}
     1998\subparagraph{\lstinline{T_align ?`align( size_t alignment )}}
    19471999to align the allocation.
    1948 The alignment parameter must be $\ge$ the default alignment (@libAlign()@ in \CFA) and a power of two.
    1949 The following example returns a dynamic object and object array aligned on a 4096-byte boundary.
     2000The alignment parameter must be $\ge$ the default alignment (@libAlign()@ in \CFA) and a power of two, \eg:
    19502001\begin{cfa}
    19512002int * i0 = alloc( @4096`align@ );  sout | i0 | nl;
     
    195520060x555555574000 0x555555574000 0x555555574004 0x555555574008
    19562007\end{cfa}
    1957 
    1958 \medskip\noindent
    1959 \lstinline{S_fill(T) ?`fill ( /* various types */ )}
     2008returns a dynamic object and object array aligned on a 4096-byte boundary.
     2009
     2010\subparagraph{\lstinline{S_fill(T) ?`fill ( /* various types */ )}}
    19602011to initialize storage.
    19612012There are three ways to fill storage:
    1962 \begin{enumerate}[itemsep=0pt,parsep=0pt]
     2013\begin{enumerate}
    19632014\item
    19642015A char fills each byte of each object.
     
    19692020\end{enumerate}
    19702021For example:
    1971 \begin{cfa}[numbers=left,xleftmargin=2.5\parindentlnth]
     2022\begin{cfa}[numbers=left]
    19722023int * i0 = alloc( @0n`fill@ );  sout | *i0 | nl;  // disambiguate 0
    19732024int * i1 = alloc( @5`fill@ );  sout | *i1 | nl;
     
    19782029int * i6 = alloc( 5, @[i3, 3]`fill@ );  for ( i; 5 ) sout | i6[i]; sout | nl;
    19792030\end{cfa}
    1980 \begin{lstlisting}[numbers=left,xleftmargin=2.5\parindentlnth]
     2031\begin{lstlisting}[numbers=left]
    198120320
    198220335
     
    19902041Examples 4 to 7 fill an array of objects with values, another array, or part of an array.
    19912042
    1992 \medskip\noindent
    1993 \lstinline{S_resize(T) ?`resize( void * oaddr )}
     2043\subparagraph{\lstinline{S_resize(T) ?`resize( void * oaddr )}}
    19942044used to resize, realign, and fill, where the old object data is not copied to the new object.
    19952045The old object type may be different from the new object type, since the values are not used.
    19962046For example:
    1997 \begin{cfa}[numbers=left,xleftmargin=2.5\parindentlnth]
     2047\begin{cfa}[numbers=left]
    19982048int * i = alloc( @5`fill@ );  sout | i | *i;
    19992049i = alloc( @i`resize@, @256`align@, @7`fill@ );  sout | i | *i;
    20002050double * d = alloc( @i`resize@, @4096`align@, @13.5`fill@ );  sout | d | *d;
    20012051\end{cfa}
    2002 \begin{lstlisting}[numbers=left,xleftmargin=2.5\parindentlnth]
     2052\begin{lstlisting}[numbers=left]
    200320530x55555556d5c0 5
    200420540x555555570000 7
     
    20072057Examples 2 to 3 change the alignment, fill, and size for the initial storage of @i@.
    20082058
    2009 \begin{cfa}[numbers=left,xleftmargin=2.5\parindentlnth]
     2059\begin{cfa}[numbers=left]
    20102060int * ia = alloc( 5, @5`fill@ );  for ( i; 5 ) sout | ia[i]; sout | nl;
    20112061ia = alloc( 10, @ia`resize@, @7`fill@ ); for ( i; 10 ) sout | ia[i]; sout | nl;
     
    20132063ia = alloc( 3, @ia`resize@, @4096`align@, @2`fill@ );  sout | ia; for ( i; 3 ) sout | &ia[i] | ia[i]; sout | nl;
    20142064\end{cfa}
    2015 \begin{lstlisting}[numbers=left,xleftmargin=2.5\parindentlnth]
     2065\begin{lstlisting}[numbers=left]
    201620665 5 5 5 5
    201720677 7 7 7 7 7 7 7 7 7
     
    20212071Examples 2 to 4 change the array size, alignment and fill for the initial storage of @ia@.
    20222072
    2023 \medskip\noindent
    2024 \lstinline{S_realloc(T) ?`realloc( T * a ))}
     2073\subparagraph{\lstinline{S_realloc(T) ?`realloc( T * a ))}}
    20252074used to resize, realign, and fill, where the old object data is copied to the new object.
    20262075The old object type must be the same as the new object type, since the value is used.
    20272076Note, for @fill@, only the extra space after copying the data from the old object is filled with the given parameter.
    20282077For example:
    2029 \begin{cfa}[numbers=left,xleftmargin=2.5\parindentlnth]
     2078\begin{cfa}[numbers=left]
    20302079int * i = alloc( @5`fill@ );  sout | i | *i;
    20312080i = alloc( @i`realloc@, @256`align@ );  sout | i | *i;
    20322081i = alloc( @i`realloc@, @4096`align@, @13`fill@ );  sout | i | *i;
    20332082\end{cfa}
    2034 \begin{lstlisting}[numbers=left,xleftmargin=2.5\parindentlnth]
     2083\begin{lstlisting}[numbers=left]
    203520840x55555556d5c0 5
    203620850x555555570000 5
     
    20402089The @13`fill@ in example 3 does nothing because no extra space is added.
    20412090
    2042 \begin{cfa}[numbers=left,xleftmargin=2.5\parindentlnth]
     2091\begin{cfa}[numbers=left]
    20432092int * ia = alloc( 5, @5`fill@ );  for ( i; 5 ) sout | ia[i]; sout | nl;
    20442093ia = alloc( 10, @ia`realloc@, @7`fill@ ); for ( i; 10 ) sout | ia[i]; sout | nl;
     
    20462095ia = alloc( 3, @ia`realloc@, @4096`align@, @2`fill@ );  sout | ia; for ( i; 3 ) sout | &ia[i] | ia[i]; sout | nl;
    20472096\end{cfa}
    2048 \begin{lstlisting}[numbers=left,xleftmargin=2.5\parindentlnth]
     2097\begin{lstlisting}[numbers=left]
    204920985 5 5 5 5
    205020995 5 5 5 5 7 7 7 7 7
Note: See TracChangeset for help on using the changeset viewer.