Changeset 765ee42
- Timestamp:
- Jan 27, 2024, 11:27:34 PM (11 months ago)
- Branches:
- master
- Children:
- baa1d5d
- Parents:
- dd1ebb1
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/papers/llheap/Paper.tex
rdd1ebb1 r765ee42 77 77 \lstset{ 78 78 columns=fullflexible, 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}]{`}{`}, 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}]{@}{@}, 91 92 }% lstset 92 93 … … 1082 1083 1083 1084 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. 1084 (Large allocations requiring initialization, \eg zero fill, and/or copying are not covered by the low-latency objective.) 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. 1085 1086 A direct consequence of this objective is very simple or no storage coalescing; 1086 1087 hence, llheap's design is willing to use more storage to lower latency. 1087 1088 This objective is apropos because systems research and industrial applications are striving for low latency and computers have huge amounts of RAM memory. 1088 Finally, llheap's performance should be comparable with the current best allocators (see performance comparison in Section~\ref{c:Performance}).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}). 1089 1090 1090 1091 % The objective of llheap's new design was to fulfill following requirements: … … 1205 1206 % \label{s:AllocationFastpath} 1206 1207 1207 llheap's design was reviewed and changed multiple times during its development. Only the final design choices are 1208 discussed in this paper. 1208 llheap's design was reviewed and changed multiple times during its development, with the final choices are discussed here. 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 osen 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 chosen 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 deallocation (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 deallocation (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 \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} 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. 1806 1798 It returns the address of the dynamic array or @NULL@ if either @dim@ or @elemSize@ are zero. 1807 1799 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. 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. 1810 1803 @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 \item1816 @oaddr@: address to be resized1817 \item1818 @size@: new allocation size (smaller or larger than previous)1819 \end{itemize}1820 1804 It returns the address of the old or new storage with the specified new size or @NULL@ if @size@ is zero. 1821 1805 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. 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. 1824 1809 Sets sticky alignment property. 1825 1826 \noindent\textbf{Usage}1827 @amemalign@ takes three parameters.1828 \begin{itemize}[topsep=3pt,itemsep=2pt,parsep=0pt]1829 \item1830 @alignment@: alignment requirement1831 \item1832 @dim@: number of array objects1833 \item1834 @elemSize@: size of array object1835 \end{itemize}1836 1810 It returns the address of the aligned dynamic-array or @NULL@ if either @dim@ or @elemSize@ are zero. 1837 1811 1838 \paragraph{\lstinline{void * cmemalign( size_t alignment, size_t dim, size_t elemSize )}} 1812 \medskip\noindent 1813 \lstinline{void * cmemalign( size_t alignment, size_t dim, size_t elemSize )} 1839 1814 extends @amemalign@ with zero fill and has the same usage as @amemalign@. 1840 1815 Sets sticky zero-fill and alignment property. 1841 1816 It returns the address of the aligned, zero-filled dynamic-array or @NULL@ if either @dim@ or @elemSize@ are zero. 1842 1817 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()}} 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()} 1890 1839 \label{p:malloc_expansion} 1891 1840 set the amount (bytes) to extend the heap when there is insufficient free storage to service an allocation request. 1892 1841 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. 1893 1842 1894 \paragraph{\lstinline{size_t malloc_mmap_start()}} 1843 \medskip\noindent 1844 \lstinline{size_t malloc_mmap_start()} 1895 1845 set the crossover between allocations occurring in the @sbrk@ area or separately mapped. 1896 1846 It returns the crossover point used throughout a program, \ie called once at heap initialization. 1897 1847 1898 \paragraph{\lstinline{size_t malloc_unfreed()}} 1848 \medskip\noindent 1849 \lstinline{size_t malloc_unfreed()} 1899 1850 \label{p:malloc_unfreed} 1900 1851 amount subtracted to adjust for unfreed program storage (debug only). 1901 It returns the new subtraction amount and called by @malloc_stats@ .1852 It returns the new subtraction amount and called by @malloc_stats@ (discussed in Section~\ref{}). 1902 1853 1903 1854 … … 1906 1857 The following extensions take advantage of overload polymorphism in the \CC type-system. 1907 1858 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} 1859 \medskip\noindent 1860 \lstinline{void * resize( void * oaddr, size_t nalign, size_t size )} 1861 extends @resize@ with an alignment requirement, @nalign@. 1921 1862 It returns the address of the old or new storage with the specified new size and alignment, or @NULL@ if @size@ is zero. 1922 1863 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@. 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. 1925 1868 1926 1869 … … 1979 1922 object size: like the \CFA's C-interface, programmers do not have to specify object size or cast allocation results. 1980 1923 \end{itemize} 1981 Note, postfix function call is an alternative call syntax, using backtick @`@, wherethe argument appears before the function name, \eg1924 Note, postfix function call is an alternative call syntax, using backtick @`@, so the argument appears before the function name, \eg 1982 1925 \begin{cfa} 1983 1926 duration ?@`@h( int h ); // ? denote the position of the function operand … … 1987 1930 \end{cfa} 1988 1931 1989 \paragraph{\lstinline{T * alloc( ... )} or \lstinline{T * alloc( size_t dim, ... )}} 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, ... )} 1990 1936 is overloaded with a variable number of specific allocation operations, or an integer dimension parameter followed by a variable number of specific allocation operations. 1991 1937 These allocation operations can be passed as named arguments when calling the \lstinline{alloc} routine. … … 1996 1942 1997 1943 The allocation property functions are: 1998 \subparagraph{\lstinline{T_align ?`align( size_t alignment )}} 1944 1945 \medskip\noindent 1946 \lstinline{T_align ?`align( size_t alignment )} 1999 1947 to align the allocation. 2000 The alignment parameter must be $\ge$ the default alignment (@libAlign()@ in \CFA) and a power of two, \eg: 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. 2001 1950 \begin{cfa} 2002 1951 int * i0 = alloc( @4096`align@ ); sout | i0 | nl; … … 2006 1955 0x555555574000 0x555555574000 0x555555574004 0x555555574008 2007 1956 \end{cfa} 2008 returns a dynamic object and object array aligned on a 4096-byte boundary. 2009 2010 \ subparagraph{\lstinline{S_fill(T) ?`fill ( /* various types */ )}}1957 1958 \medskip\noindent 1959 \lstinline{S_fill(T) ?`fill ( /* various types */ )} 2011 1960 to initialize storage. 2012 1961 There are three ways to fill storage: 2013 \begin{enumerate} 1962 \begin{enumerate}[itemsep=0pt,parsep=0pt] 2014 1963 \item 2015 1964 A char fills each byte of each object. … … 2020 1969 \end{enumerate} 2021 1970 For example: 2022 \begin{cfa}[numbers=left ]1971 \begin{cfa}[numbers=left,xleftmargin=2.5\parindentlnth] 2023 1972 int * i0 = alloc( @0n`fill@ ); sout | *i0 | nl; // disambiguate 0 2024 1973 int * i1 = alloc( @5`fill@ ); sout | *i1 | nl; … … 2029 1978 int * i6 = alloc( 5, @[i3, 3]`fill@ ); for ( i; 5 ) sout | i6[i]; sout | nl; 2030 1979 \end{cfa} 2031 \begin{lstlisting}[numbers=left ]1980 \begin{lstlisting}[numbers=left,xleftmargin=2.5\parindentlnth] 2032 1981 0 2033 1982 5 … … 2041 1990 Examples 4 to 7 fill an array of objects with values, another array, or part of an array. 2042 1991 2043 \subparagraph{\lstinline{S_resize(T) ?`resize( void * oaddr )}} 1992 \medskip\noindent 1993 \lstinline{S_resize(T) ?`resize( void * oaddr )} 2044 1994 used to resize, realign, and fill, where the old object data is not copied to the new object. 2045 1995 The old object type may be different from the new object type, since the values are not used. 2046 1996 For example: 2047 \begin{cfa}[numbers=left ]1997 \begin{cfa}[numbers=left,xleftmargin=2.5\parindentlnth] 2048 1998 int * i = alloc( @5`fill@ ); sout | i | *i; 2049 1999 i = alloc( @i`resize@, @256`align@, @7`fill@ ); sout | i | *i; 2050 2000 double * d = alloc( @i`resize@, @4096`align@, @13.5`fill@ ); sout | d | *d; 2051 2001 \end{cfa} 2052 \begin{lstlisting}[numbers=left ]2002 \begin{lstlisting}[numbers=left,xleftmargin=2.5\parindentlnth] 2053 2003 0x55555556d5c0 5 2054 2004 0x555555570000 7 … … 2057 2007 Examples 2 to 3 change the alignment, fill, and size for the initial storage of @i@. 2058 2008 2059 \begin{cfa}[numbers=left ]2009 \begin{cfa}[numbers=left,xleftmargin=2.5\parindentlnth] 2060 2010 int * ia = alloc( 5, @5`fill@ ); for ( i; 5 ) sout | ia[i]; sout | nl; 2061 2011 ia = alloc( 10, @ia`resize@, @7`fill@ ); for ( i; 10 ) sout | ia[i]; sout | nl; … … 2063 2013 ia = alloc( 3, @ia`resize@, @4096`align@, @2`fill@ ); sout | ia; for ( i; 3 ) sout | &ia[i] | ia[i]; sout | nl; 2064 2014 \end{cfa} 2065 \begin{lstlisting}[numbers=left ]2015 \begin{lstlisting}[numbers=left,xleftmargin=2.5\parindentlnth] 2066 2016 5 5 5 5 5 2067 2017 7 7 7 7 7 7 7 7 7 7 … … 2071 2021 Examples 2 to 4 change the array size, alignment and fill for the initial storage of @ia@. 2072 2022 2073 \subparagraph{\lstinline{S_realloc(T) ?`realloc( T * a ))}} 2023 \medskip\noindent 2024 \lstinline{S_realloc(T) ?`realloc( T * a ))} 2074 2025 used to resize, realign, and fill, where the old object data is copied to the new object. 2075 2026 The old object type must be the same as the new object type, since the value is used. 2076 2027 Note, for @fill@, only the extra space after copying the data from the old object is filled with the given parameter. 2077 2028 For example: 2078 \begin{cfa}[numbers=left ]2029 \begin{cfa}[numbers=left,xleftmargin=2.5\parindentlnth] 2079 2030 int * i = alloc( @5`fill@ ); sout | i | *i; 2080 2031 i = alloc( @i`realloc@, @256`align@ ); sout | i | *i; 2081 2032 i = alloc( @i`realloc@, @4096`align@, @13`fill@ ); sout | i | *i; 2082 2033 \end{cfa} 2083 \begin{lstlisting}[numbers=left ]2034 \begin{lstlisting}[numbers=left,xleftmargin=2.5\parindentlnth] 2084 2035 0x55555556d5c0 5 2085 2036 0x555555570000 5 … … 2089 2040 The @13`fill@ in example 3 does nothing because no extra space is added. 2090 2041 2091 \begin{cfa}[numbers=left ]2042 \begin{cfa}[numbers=left,xleftmargin=2.5\parindentlnth] 2092 2043 int * ia = alloc( 5, @5`fill@ ); for ( i; 5 ) sout | ia[i]; sout | nl; 2093 2044 ia = alloc( 10, @ia`realloc@, @7`fill@ ); for ( i; 10 ) sout | ia[i]; sout | nl; … … 2095 2046 ia = alloc( 3, @ia`realloc@, @4096`align@, @2`fill@ ); sout | ia; for ( i; 3 ) sout | &ia[i] | ia[i]; sout | nl; 2096 2047 \end{cfa} 2097 \begin{lstlisting}[numbers=left ]2048 \begin{lstlisting}[numbers=left,xleftmargin=2.5\parindentlnth] 2098 2049 5 5 5 5 5 2099 2050 5 5 5 5 5 7 7 7 7 7
Note: See TracChangeset
for help on using the changeset viewer.