2 @c @node Tunables, , Internal Probes, Top
3 @c %MENU% Tunable switches to alter libc internal behavior
7 @dfn{Tunables} are a feature in @theglibc{} that allows application authors and
8 distribution maintainers to alter the runtime library behavior to match
9 their workload. These are implemented as a set of switches that may be
10 modified in different ways. The current default method to do this is via
11 the @env{GLIBC_TUNABLES} environment variable by setting it to a string
12 of colon-separated @var{name}=@var{value} pairs. For example, the following
13 example enables malloc checking and sets the malloc trim threshold to 128
17 GLIBC_TUNABLES=glibc.malloc.trim_threshold=128:glibc.malloc.check=3
21 Tunables are not part of the @glibcadj{} stable ABI, and they are
22 subject to change or removal across releases. Additionally, the method to
23 modify tunable values may change between releases and across distributions.
24 It is possible to implement multiple `frontends' for the tunables allowing
25 distributions to choose their preferred method at build time.
27 Finally, the set of tunables available may vary between distributions as
28 the tunables feature allows distributions to add their own tunables under
32 * Tunable names:: The structure of a tunable name
33 * Memory Allocation Tunables:: Tunables in the memory allocation subsystem
34 * Elision Tunables:: Tunables in elision subsystem
35 * Hardware Capability Tunables:: Tunables that modify the hardware
36 capabilities seen by @theglibc{}
40 @section Tunable names
42 @cindex Tunable namespaces
44 A tunable name is split into three components, a top namespace, a tunable
45 namespace and the tunable name. The top namespace for tunables implemented in
46 @theglibc{} is @code{glibc}. Distributions that choose to add custom tunables
47 in their maintained versions of @theglibc{} may choose to do so under their own
50 The tunable namespace is a logical grouping of tunables in a single
51 module. This currently holds no special significance, although that may
54 The tunable name is the actual name of the tunable. It is possible that
55 different tunable namespaces may have tunables within them that have the
56 same name, likewise for top namespaces. Hence, we only support
57 identification of tunables by their full name, i.e. with the top
58 namespace, tunable namespace and tunable name, separated by periods.
60 @node Memory Allocation Tunables
61 @section Memory Allocation Tunables
62 @cindex memory allocation tunables
63 @cindex malloc tunables
64 @cindex tunables, malloc
66 @deftp {Tunable namespace} glibc.malloc
67 Memory allocation behavior can be modified by setting any of the
68 following tunables in the @code{malloc} namespace:
71 @deftp Tunable glibc.malloc.check
72 This tunable supersedes the @env{MALLOC_CHECK_} environment variable and is
73 identical in features.
75 Setting this tunable to a non-zero value enables a special (less
76 efficient) memory allocator for the malloc family of functions that is
77 designed to be tolerant against simple errors such as double calls of
78 free with the same argument, or overruns of a single byte (off-by-one
79 bugs). Not all such errors can be protected against, however, and memory
80 leaks can result. Any detected heap corruption results in immediate
81 termination of the process.
83 Like @env{MALLOC_CHECK_}, @code{glibc.malloc.check} has a problem in that it
84 diverges from normal program behavior by writing to @code{stderr}, which could
85 by exploited in SUID and SGID binaries. Therefore, @code{glibc.malloc.check}
86 is disabled by default for SUID and SGID binaries. This can be enabled again
87 by the system administrator by adding a file @file{/etc/suid-debug}; the
88 content of the file could be anything or even empty.
91 @deftp Tunable glibc.malloc.top_pad
92 This tunable supersedes the @env{MALLOC_TOP_PAD_} environment variable and is
93 identical in features.
95 This tunable determines the amount of extra memory in bytes to obtain from the
96 system when any of the arenas need to be extended. It also specifies the
97 number of bytes to retain when shrinking any of the arenas. This provides the
98 necessary hysteresis in heap size such that excessive amounts of system calls
101 The default value of this tunable is @samp{0}.
104 @deftp Tunable glibc.malloc.perturb
105 This tunable supersedes the @env{MALLOC_PERTURB_} environment variable and is
106 identical in features.
108 If set to a non-zero value, memory blocks are initialized with values depending
109 on some low order bits of this tunable when they are allocated (except when
110 allocated by calloc) and freed. This can be used to debug the use of
111 uninitialized or freed heap memory. Note that this option does not guarantee
112 that the freed block will have any specific values. It only guarantees that the
113 content the block had before it was freed will be overwritten.
115 The default value of this tunable is @samp{0}.
118 @deftp Tunable glibc.malloc.mmap_threshold
119 This tunable supersedes the @env{MALLOC_MMAP_THRESHOLD_} environment variable
120 and is identical in features.
122 When this tunable is set, all chunks larger than this value in bytes are
123 allocated outside the normal heap, using the @code{mmap} system call. This way
124 it is guaranteed that the memory for these chunks can be returned to the system
125 on @code{free}. Note that requests smaller than this threshold might still be
126 allocated via @code{mmap}.
128 If this tunable is not set, the default value is set to @samp{131072} bytes and
129 the threshold is adjusted dynamically to suit the allocation patterns of the
130 program. If the tunable is set, the dynamic adjustment is disabled and the
131 value is set as static.
134 @deftp Tunable glibc.malloc.trim_threshold
135 This tunable supersedes the @env{MALLOC_TRIM_THRESHOLD_} environment variable
136 and is identical in features.
138 The value of this tunable is the minimum size (in bytes) of the top-most,
139 releasable chunk in an arena that will trigger a system call in order to return
140 memory to the system from that arena.
142 If this tunable is not set, the default value is set as 128 KB and the
143 threshold is adjusted dynamically to suit the allocation patterns of the
144 program. If the tunable is set, the dynamic adjustment is disabled and the
145 value is set as static.
148 @deftp Tunable glibc.malloc.mmap_max
149 This tunable supersedes the @env{MALLOC_MMAP_MAX_} environment variable and is
150 identical in features.
152 The value of this tunable is maximum number of chunks to allocate with
153 @code{mmap}. Setting this to zero disables all use of @code{mmap}.
155 The default value of this tunable is @samp{65536}.
158 @deftp Tunable glibc.malloc.arena_test
159 This tunable supersedes the @env{MALLOC_ARENA_TEST} environment variable and is
160 identical in features.
162 The @code{glibc.malloc.arena_test} tunable specifies the number of arenas that
163 can be created before the test on the limit to the number of arenas is
164 conducted. The value is ignored if @code{glibc.malloc.arena_max} is set.
166 The default value of this tunable is 2 for 32-bit systems and 8 for 64-bit
170 @deftp Tunable glibc.malloc.arena_max
171 This tunable supersedes the @env{MALLOC_ARENA_MAX} environment variable and is
172 identical in features.
174 This tunable sets the number of arenas to use in a process regardless of the
175 number of cores in the system.
177 The default value of this tunable is @code{0}, meaning that the limit on the
178 number of arenas is determined by the number of CPU cores online. For 32-bit
179 systems the limit is twice the number of cores online and on 64-bit systems, it
180 is 8 times the number of cores online.
183 @deftp Tunable glibc.malloc.tcache_max
184 The maximum size of a request (in bytes) which may be met via the
185 per-thread cache. The default (and maximum) value is 1032 bytes on
186 64-bit systems and 516 bytes on 32-bit systems.
189 @deftp Tunable glibc.malloc.tcache_count
190 The maximum number of chunks of each size to cache. The default is 7.
191 There is no upper limit, other than available system memory. If set
192 to zero, the per-thread cache is effectively disabled.
194 The approximate maximum overhead of the per-thread cache is thus equal
195 to the number of bins times the chunk count in each bin times the size
196 of each chunk. With defaults, the approximate maximum overhead of the
197 per-thread cache is approximately 236 KB on 64-bit systems and 118 KB
201 @deftp Tunable glibc.malloc.tcache_unsorted_limit
202 When the user requests memory and the request cannot be met via the
203 per-thread cache, the arenas are used to meet the request. At this
204 time, additional chunks will be moved from existing arena lists to
205 pre-fill the corresponding cache. While copies from the fastbins,
206 smallbins, and regular bins are bounded and predictable due to the bin
207 sizes, copies from the unsorted bin are not bounded, and incur
208 additional time penalties as they need to be sorted as they're
209 scanned. To make scanning the unsorted list more predictable and
210 bounded, the user may set this tunable to limit the number of chunks
211 that are scanned from the unsorted list while searching for chunks to
212 pre-fill the per-thread cache with. The default, or when set to zero,
216 @node Elision Tunables
217 @section Elision Tunables
218 @cindex elision tunables
219 @cindex tunables, elision
221 @deftp {Tunable namespace} glibc.elision
222 Contended locks are usually slow and can lead to performance and scalability
223 issues in multithread code. Lock elision will use memory transactions to under
224 certain conditions, to elide locks and improve performance.
225 Elision behavior can be modified by setting the following tunables in
226 the @code{elision} namespace:
229 @deftp Tunable glibc.elision.enable
230 The @code{glibc.elision.enable} tunable enables lock elision if the feature is
231 supported by the hardware. If elision is not supported by the hardware this
232 tunable has no effect.
234 Elision tunables are supported for 64-bit Intel, IBM POWER, and z System
238 @deftp Tunable glibc.elision.skip_lock_busy
239 The @code{glibc.elision.skip_lock_busy} tunable sets how many times to use a
240 non-transactional lock after a transactional failure has occurred because the
241 lock is already acquired. Expressed in number of lock acquisition attempts.
243 The default value of this tunable is @samp{3}.
246 @deftp Tunable glibc.elision.skip_lock_internal_abort
247 The @code{glibc.elision.skip_lock_internal_abort} tunable sets how many times
248 the thread should avoid using elision if a transaction aborted for any reason
249 other than a different thread's memory accesses. Expressed in number of lock
250 acquisition attempts.
252 The default value of this tunable is @samp{3}.
255 @deftp Tunable glibc.elision.skip_lock_after_retries
256 The @code{glibc.elision.skip_lock_after_retries} tunable sets how many times
257 to try to elide a lock with transactions, that only failed due to a different
258 thread's memory accesses, before falling back to regular lock.
259 Expressed in number of lock elision attempts.
261 This tunable is supported only on IBM POWER, and z System architectures.
263 The default value of this tunable is @samp{3}.
266 @deftp Tunable glibc.elision.tries
267 The @code{glibc.elision.tries} sets how many times to retry elision if there is
268 chance for the transaction to finish execution e.g., it wasn't
269 aborted due to the lock being already acquired. If elision is not supported
270 by the hardware this tunable is set to @samp{0} to avoid retries.
272 The default value of this tunable is @samp{3}.
275 @deftp Tunable glibc.elision.skip_trylock_internal_abort
276 The @code{glibc.elision.skip_trylock_internal_abort} tunable sets how many
277 times the thread should avoid trying the lock if a transaction aborted due to
278 reasons other than a different thread's memory accesses. Expressed in number
279 of try lock attempts.
281 The default value of this tunable is @samp{3}.
284 @node Hardware Capability Tunables
285 @section Hardware Capability Tunables
286 @cindex hardware capability tunables
287 @cindex hwcap tunables
288 @cindex tunables, hwcap
289 @cindex hwcaps tunables
290 @cindex tunables, hwcaps
291 @cindex data_cache_size tunables
292 @cindex tunables, data_cache_size
293 @cindex shared_cache_size tunables
294 @cindex tunables, shared_cache_size
295 @cindex non_temporal_threshold tunables
296 @cindex tunables, non_temporal_threshold
298 @deftp {Tunable namespace} glibc.tune
299 Behavior of @theglibc{} can be tuned to assume specific hardware capabilities
300 by setting the following tunables in the @code{tune} namespace:
303 @deftp Tunable glibc.tune.hwcap_mask
304 This tunable supersedes the @env{LD_HWCAP_MASK} environment variable and is
305 identical in features.
307 The @code{AT_HWCAP} key in the Auxiliary Vector specifies instruction set
308 extensions available in the processor at runtime for some architectures. The
309 @code{glibc.tune.hwcap_mask} tunable allows the user to mask out those
310 capabilities at runtime, thus disabling use of those extensions.
313 @deftp Tunable glibc.tune.hwcaps
314 The @code{glibc.tune.hwcaps=-xxx,yyy,-zzz...} tunable allows the user to
315 enable CPU/ARCH feature @code{yyy}, disable CPU/ARCH feature @code{xxx}
316 and @code{zzz} where the feature name is case-sensitive and has to match
317 the ones in @code{sysdeps/x86/cpu-features.h}.
319 This tunable is specific to i386 and x86-64.
322 @deftp Tunable glibc.tune.cached_memopt
323 The @code{glibc.tune.cached_memopt=[0|1]} tunable allows the user to
324 enable optimizations recommended for cacheable memory. If set to
325 @code{1}, @theglibc{} assumes that the process memory image consists
326 of cacheable (non-device) memory only. The default, @code{0},
327 indicates that the process may use device memory.
329 This tunable is specific to powerpc, powerpc64 and powerpc64le.
332 @deftp Tunable glibc.tune.cpu
333 The @code{glibc.tune.cpu=xxx} tunable allows the user to tell @theglibc{} to
334 assume that the CPU is @code{xxx} where xxx may have one of these values:
335 @code{generic}, @code{falkor}, @code{thunderxt88}, @code{thunderx2t99},
336 @code{thunderx2t99p1}.
338 This tunable is specific to aarch64.
341 @deftp Tunable glibc.tune.x86_data_cache_size
342 The @code{glibc.tune.x86_data_cache_size} tunable allows the user to set
343 data cache size in bytes for use in memory and string routines.
345 This tunable is specific to i386 and x86-64.
348 @deftp Tunable glibc.tune.x86_shared_cache_size
349 The @code{glibc.tune.x86_shared_cache_size} tunable allows the user to
350 set shared cache size in bytes for use in memory and string routines.
353 @deftp Tunable glibc.tune.x86_non_temporal_threshold
354 The @code{glibc.tune.x86_non_temporal_threshold} tunable allows the user
355 to set threshold in bytes for non temporal store.
357 This tunable is specific to i386 and x86-64.