Changes in doc/papers/llheap/Paper.tex [765ee42:77afbb4]
- File:
-
- 1 edited
-
doc/papers/llheap/Paper.tex (modified) (19 diffs)
Legend:
- Unmodified
- Added
- Removed
-
doc/papers/llheap/Paper.tex
r765ee42 r77afbb4 77 77 \lstset{ 78 78 columns=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}]{@}{@}, 79 basicstyle=\linespread{0.9}\sf, % reduce line spacing and use sanserif font 80 stringstyle=\tt, % use typewriter font 81 tabsize=5, % N space tabbing 82 xleftmargin=\parindentlnth, % indent code to paragraph indentation 83 %mathescape=true, % LaTeX math escape in CFA code $...$ 84 escapechar=\$, % LaTeX 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=3pt, 90 moredelim=**[is][\color{red}]{`}{`}, 92 91 }% lstset 93 92 … … 1083 1082 1084 1083 The 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.) 1086 1085 A direct consequence of this objective is very simple or no storage coalescing; 1087 1086 hence, llheap's design is willing to use more storage to lower latency. 1088 1087 This 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}).1088 Finally, llheap's performance should be comparable with the current best allocators (see performance comparison in Section~\ref{c:Performance}). 1090 1089 1091 1090 % The objective of llheap's new design was to fulfill following requirements: … … 1206 1205 % \label{s:AllocationFastpath} 1207 1206 1208 llheap's design was reviewed and changed multiple times during its development, with the final choices are discussed here. 1207 llheap's design was reviewed and changed multiple times during its development. Only the final design choices are 1208 discussed in this paper. 1209 1209 (See~\cite{Zulfiqar22} for a discussion of alternate choices and reasons for rejecting them.) 1210 1210 All 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 cho sen is 1:1, which is the T:H model with T = H, where there is one thread-local heap for each KT.1211 The 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. 1212 1212 (See Figure~\ref{f:THSharedHeaps} but with a heap bucket per KT and no bucket or local-pool lock.) 1213 1213 Hence, immediately after a KT starts, its heap is created and just before a KT terminates, its heap is (logically) deleted. … … 1426 1426 1427 1427 1428 Algorithm~\ref{alg:heapObjectFreeOwn} shows the de allocation (free) outline for an object at address $A$ with ownership.1428 Algorithm~\ref{alg:heapObjectFreeOwn} shows the de-allocation (free) outline for an object at address $A$ with ownership. 1429 1429 First, the address is divided into small (@sbrk@) or large (@mmap@). 1430 1430 For large allocations, the storage is unmapped back to the OS. … … 1433 1433 If the bucket is not local to the thread, the allocation is pushed onto the owning thread's associated away stack. 1434 1434 1435 Algorithm~\ref{alg:heapObjectFreeNoOwn} shows the de allocation (free) outline for an object at address $A$ without ownership.1435 Algorithm~\ref{alg:heapObjectFreeNoOwn} shows the de-allocation (free) outline for an object at address $A$ without ownership. 1436 1436 The algorithm is the same as for ownership except if the bucket is not local to the thread. 1437 1437 Then the corresponding bucket of the owner thread is computed for the deallocating thread, and the allocation is pushed onto the deallocating thread's bucket. … … 1792 1792 The C dynamic-memory API is extended with the following routines: 1793 1793 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 )}} 1795 extends @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} 1798 1806 It returns the address of the dynamic array or @NULL@ if either @dim@ or @elemSize@ are zero. 1799 1807 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 )}} 1809 extends @realloc@ for resizing an existing allocation \emph{without} copying previous data into the new allocation or preserving sticky properties. 1803 1810 @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} 1804 1820 It returns the address of the old or new storage with the specified new size or @NULL@ if @size@ is zero. 1805 1821 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 )}} 1823 extends @aalloc@ and @memalign@ for allocating an aligned dynamic array of objects. 1809 1824 Sets 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} 1810 1836 It returns the address of the aligned dynamic-array or @NULL@ if either @dim@ or @elemSize@ are zero. 1811 1837 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 )}} 1814 1839 extends @amemalign@ with zero fill and has the same usage as @amemalign@. 1815 1840 Sets sticky zero-fill and alignment property. 1816 1841 It returns the address of the aligned, zero-filled dynamic-array or @NULL@ if either @dim@ or @elemSize@ are zero. 1817 1842 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 )}} 1844 returns 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} 1852 It 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 )}} 1855 returns 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} 1864 It returns true if the zero-fill sticky property is set and false otherwise. 1865 1866 \paragraph{\lstinline{size_t malloc_size( void * addr )}} 1867 returns the request size of the dynamic object (updated when an object is resized) for use in similar allocations. 1868 See 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} 1876 It returns the request size or zero if @addr@ is @NULL@. 1877 1878 \paragraph{\lstinline{int malloc_stats_fd( int fd )}} 1879 changes 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} 1887 It returns the previous file descriptor. 1888 1889 \paragraph{\lstinline{size_t malloc_expansion()}} 1839 1890 \label{p:malloc_expansion} 1840 1891 set the amount (bytes) to extend the heap when there is insufficient free storage to service an allocation request. 1841 1892 It 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. 1842 1893 1843 \medskip\noindent 1844 \lstinline{size_t malloc_mmap_start()} 1894 \paragraph{\lstinline{size_t malloc_mmap_start()}} 1845 1895 set the crossover between allocations occurring in the @sbrk@ area or separately mapped. 1846 1896 It returns the crossover point used throughout a program, \ie called once at heap initialization. 1847 1897 1848 \medskip\noindent 1849 \lstinline{size_t malloc_unfreed()} 1898 \paragraph{\lstinline{size_t malloc_unfreed()}} 1850 1899 \label{p:malloc_unfreed} 1851 1900 amount 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{}).1901 It returns the new subtraction amount and called by @malloc_stats@. 1853 1902 1854 1903 … … 1857 1906 The following extensions take advantage of overload polymorphism in the \CC type-system. 1858 1907 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 )}} 1909 extends @resize@ with an alignment re\-quirement. 1910 1911 \noindent\textbf{Usage} 1912 takes 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} 1862 1921 It returns the address of the old or new storage with the specified new size and alignment, or @NULL@ if @size@ is zero. 1863 1922 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 )}} 1924 extends @realloc@ with an alignment re\-quirement and has the same usage as aligned @resize@. 1868 1925 1869 1926 … … 1922 1979 object size: like the \CFA's C-interface, programmers do not have to specify object size or cast allocation results. 1923 1980 \end{itemize} 1924 Note, postfix function call is an alternative call syntax, using backtick @`@, sothe argument appears before the function name, \eg1981 Note, postfix function call is an alternative call syntax, using backtick @`@, where the argument appears before the function name, \eg 1925 1982 \begin{cfa} 1926 1983 duration ?@`@h( int h ); // ? denote the position of the function operand … … 1930 1987 \end{cfa} 1931 1988 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, ... )}} 1936 1990 is overloaded with a variable number of specific allocation operations, or an integer dimension parameter followed by a variable number of specific allocation operations. 1937 1991 These allocation operations can be passed as named arguments when calling the \lstinline{alloc} routine. … … 1942 1996 1943 1997 The 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 )}} 1947 1999 to 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. 2000 The alignment parameter must be $\ge$ the default alignment (@libAlign()@ in \CFA) and a power of two, \eg: 1950 2001 \begin{cfa} 1951 2002 int * i0 = alloc( @4096`align@ ); sout | i0 | nl; … … 1955 2006 0x555555574000 0x555555574000 0x555555574004 0x555555574008 1956 2007 \end{cfa} 1957 1958 \medskip\noindent 1959 \ lstinline{S_fill(T) ?`fill ( /* various types */ )}2008 returns a dynamic object and object array aligned on a 4096-byte boundary. 2009 2010 \subparagraph{\lstinline{S_fill(T) ?`fill ( /* various types */ )}} 1960 2011 to initialize storage. 1961 2012 There are three ways to fill storage: 1962 \begin{enumerate} [itemsep=0pt,parsep=0pt]2013 \begin{enumerate} 1963 2014 \item 1964 2015 A char fills each byte of each object. … … 1969 2020 \end{enumerate} 1970 2021 For example: 1971 \begin{cfa}[numbers=left ,xleftmargin=2.5\parindentlnth]2022 \begin{cfa}[numbers=left] 1972 2023 int * i0 = alloc( @0n`fill@ ); sout | *i0 | nl; // disambiguate 0 1973 2024 int * i1 = alloc( @5`fill@ ); sout | *i1 | nl; … … 1978 2029 int * i6 = alloc( 5, @[i3, 3]`fill@ ); for ( i; 5 ) sout | i6[i]; sout | nl; 1979 2030 \end{cfa} 1980 \begin{lstlisting}[numbers=left ,xleftmargin=2.5\parindentlnth]2031 \begin{lstlisting}[numbers=left] 1981 2032 0 1982 2033 5 … … 1990 2041 Examples 4 to 7 fill an array of objects with values, another array, or part of an array. 1991 2042 1992 \medskip\noindent 1993 \lstinline{S_resize(T) ?`resize( void * oaddr )} 2043 \subparagraph{\lstinline{S_resize(T) ?`resize( void * oaddr )}} 1994 2044 used to resize, realign, and fill, where the old object data is not copied to the new object. 1995 2045 The old object type may be different from the new object type, since the values are not used. 1996 2046 For example: 1997 \begin{cfa}[numbers=left ,xleftmargin=2.5\parindentlnth]2047 \begin{cfa}[numbers=left] 1998 2048 int * i = alloc( @5`fill@ ); sout | i | *i; 1999 2049 i = alloc( @i`resize@, @256`align@, @7`fill@ ); sout | i | *i; 2000 2050 double * d = alloc( @i`resize@, @4096`align@, @13.5`fill@ ); sout | d | *d; 2001 2051 \end{cfa} 2002 \begin{lstlisting}[numbers=left ,xleftmargin=2.5\parindentlnth]2052 \begin{lstlisting}[numbers=left] 2003 2053 0x55555556d5c0 5 2004 2054 0x555555570000 7 … … 2007 2057 Examples 2 to 3 change the alignment, fill, and size for the initial storage of @i@. 2008 2058 2009 \begin{cfa}[numbers=left ,xleftmargin=2.5\parindentlnth]2059 \begin{cfa}[numbers=left] 2010 2060 int * ia = alloc( 5, @5`fill@ ); for ( i; 5 ) sout | ia[i]; sout | nl; 2011 2061 ia = alloc( 10, @ia`resize@, @7`fill@ ); for ( i; 10 ) sout | ia[i]; sout | nl; … … 2013 2063 ia = alloc( 3, @ia`resize@, @4096`align@, @2`fill@ ); sout | ia; for ( i; 3 ) sout | &ia[i] | ia[i]; sout | nl; 2014 2064 \end{cfa} 2015 \begin{lstlisting}[numbers=left ,xleftmargin=2.5\parindentlnth]2065 \begin{lstlisting}[numbers=left] 2016 2066 5 5 5 5 5 2017 2067 7 7 7 7 7 7 7 7 7 7 … … 2021 2071 Examples 2 to 4 change the array size, alignment and fill for the initial storage of @ia@. 2022 2072 2023 \medskip\noindent 2024 \lstinline{S_realloc(T) ?`realloc( T * a ))} 2073 \subparagraph{\lstinline{S_realloc(T) ?`realloc( T * a ))}} 2025 2074 used to resize, realign, and fill, where the old object data is copied to the new object. 2026 2075 The old object type must be the same as the new object type, since the value is used. 2027 2076 Note, for @fill@, only the extra space after copying the data from the old object is filled with the given parameter. 2028 2077 For example: 2029 \begin{cfa}[numbers=left ,xleftmargin=2.5\parindentlnth]2078 \begin{cfa}[numbers=left] 2030 2079 int * i = alloc( @5`fill@ ); sout | i | *i; 2031 2080 i = alloc( @i`realloc@, @256`align@ ); sout | i | *i; 2032 2081 i = alloc( @i`realloc@, @4096`align@, @13`fill@ ); sout | i | *i; 2033 2082 \end{cfa} 2034 \begin{lstlisting}[numbers=left ,xleftmargin=2.5\parindentlnth]2083 \begin{lstlisting}[numbers=left] 2035 2084 0x55555556d5c0 5 2036 2085 0x555555570000 5 … … 2040 2089 The @13`fill@ in example 3 does nothing because no extra space is added. 2041 2090 2042 \begin{cfa}[numbers=left ,xleftmargin=2.5\parindentlnth]2091 \begin{cfa}[numbers=left] 2043 2092 int * ia = alloc( 5, @5`fill@ ); for ( i; 5 ) sout | ia[i]; sout | nl; 2044 2093 ia = alloc( 10, @ia`realloc@, @7`fill@ ); for ( i; 10 ) sout | ia[i]; sout | nl; … … 2046 2095 ia = alloc( 3, @ia`realloc@, @4096`align@, @2`fill@ ); sout | ia; for ( i; 3 ) sout | &ia[i] | ia[i]; sout | nl; 2047 2096 \end{cfa} 2048 \begin{lstlisting}[numbers=left ,xleftmargin=2.5\parindentlnth]2097 \begin{lstlisting}[numbers=left] 2049 2098 5 5 5 5 5 2050 2099 5 5 5 5 5 7 7 7 7 7
Note:
See TracChangeset
for help on using the changeset viewer.