Makeconfig: sandwich gnulib-tests between libc/ld linking of tests
[glibc.git] / manual / tunables.texi
blobec18b1083412f33154e2c4b258567139f4b4c134
1 @node Tunables
2 @c @node Tunables, , Internal Probes, Top
3 @c %MENU% Tunable switches to alter libc internal behavior
4 @chapter Tunables
5 @cindex tunables
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
14 bytes:
16 @example
17 GLIBC_TUNABLES=glibc.malloc.trim_threshold=128:glibc.malloc.check=3
18 export GLIBC_TUNABLES
19 @end example
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
29 their own namespace.
31 @menu
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 * POSIX Thread Tunables:: Tunables in the POSIX thread subsystem
36 * Hardware Capability Tunables::  Tunables that modify the hardware
37                                   capabilities seen by @theglibc{}
38 @end menu
40 @node Tunable names
41 @section Tunable names
42 @cindex Tunable names
43 @cindex Tunable namespaces
45 A tunable name is split into three components, a top namespace, a tunable
46 namespace and the tunable name. The top namespace for tunables implemented in
47 @theglibc{} is @code{glibc}. Distributions that choose to add custom tunables
48 in their maintained versions of @theglibc{} may choose to do so under their own
49 top namespace.
51 The tunable namespace is a logical grouping of tunables in a single
52 module. This currently holds no special significance, although that may
53 change in the future.
55 The tunable name is the actual name of the tunable. It is possible that
56 different tunable namespaces may have tunables within them that have the
57 same name, likewise for top namespaces. Hence, we only support
58 identification of tunables by their full name, i.e. with the top
59 namespace, tunable namespace and tunable name, separated by periods.
61 @node Memory Allocation Tunables
62 @section Memory Allocation Tunables
63 @cindex memory allocation tunables
64 @cindex malloc tunables
65 @cindex tunables, malloc
67 @deftp {Tunable namespace} glibc.malloc
68 Memory allocation behavior can be modified by setting any of the
69 following tunables in the @code{malloc} namespace:
70 @end deftp
72 @deftp Tunable glibc.malloc.check
73 This tunable supersedes the @env{MALLOC_CHECK_} environment variable and is
74 identical in features.
76 Setting this tunable to a non-zero value enables a special (less
77 efficient) memory allocator for the malloc family of functions that is
78 designed to be tolerant against simple errors such as double calls of
79 free with the same argument, or overruns of a single byte (off-by-one
80 bugs). Not all such errors can be protected against, however, and memory
81 leaks can result.  Any detected heap corruption results in immediate
82 termination of the process.
84 Like @env{MALLOC_CHECK_}, @code{glibc.malloc.check} has a problem in that it
85 diverges from normal program behavior by writing to @code{stderr}, which could
86 by exploited in SUID and SGID binaries.  Therefore, @code{glibc.malloc.check}
87 is disabled by default for SUID and SGID binaries.  This can be enabled again
88 by the system administrator by adding a file @file{/etc/suid-debug}; the
89 content of the file could be anything or even empty.
90 @end deftp
92 @deftp Tunable glibc.malloc.top_pad
93 This tunable supersedes the @env{MALLOC_TOP_PAD_} environment variable and is
94 identical in features.
96 This tunable determines the amount of extra memory in bytes to obtain from the
97 system when any of the arenas need to be extended.  It also specifies the
98 number of bytes to retain when shrinking any of the arenas.  This provides the
99 necessary hysteresis in heap size such that excessive amounts of system calls
100 can be avoided.
102 The default value of this tunable is @samp{0}.
103 @end deftp
105 @deftp Tunable glibc.malloc.perturb
106 This tunable supersedes the @env{MALLOC_PERTURB_} environment variable and is
107 identical in features.
109 If set to a non-zero value, memory blocks are initialized with values depending
110 on some low order bits of this tunable when they are allocated (except when
111 allocated by calloc) and freed.  This can be used to debug the use of
112 uninitialized or freed heap memory. Note that this option does not guarantee
113 that the freed block will have any specific values. It only guarantees that the
114 content the block had before it was freed will be overwritten.
116 The default value of this tunable is @samp{0}.
117 @end deftp
119 @deftp Tunable glibc.malloc.mmap_threshold
120 This tunable supersedes the @env{MALLOC_MMAP_THRESHOLD_} environment variable
121 and is identical in features.
123 When this tunable is set, all chunks larger than this value in bytes are
124 allocated outside the normal heap, using the @code{mmap} system call. This way
125 it is guaranteed that the memory for these chunks can be returned to the system
126 on @code{free}. Note that requests smaller than this threshold might still be
127 allocated via @code{mmap}.
129 If this tunable is not set, the default value is set to @samp{131072} bytes and
130 the threshold is adjusted dynamically to suit the allocation patterns of the
131 program.  If the tunable is set, the dynamic adjustment is disabled and the
132 value is set as static.
133 @end deftp
135 @deftp Tunable glibc.malloc.trim_threshold
136 This tunable supersedes the @env{MALLOC_TRIM_THRESHOLD_} environment variable
137 and is identical in features.
139 The value of this tunable is the minimum size (in bytes) of the top-most,
140 releasable chunk in an arena that will trigger a system call in order to return
141 memory to the system from that arena.
143 If this tunable is not set, the default value is set as 128 KB and the
144 threshold is adjusted dynamically to suit the allocation patterns of the
145 program.  If the tunable is set, the dynamic adjustment is disabled and the
146 value is set as static.
147 @end deftp
149 @deftp Tunable glibc.malloc.mmap_max
150 This tunable supersedes the @env{MALLOC_MMAP_MAX_} environment variable and is
151 identical in features.
153 The value of this tunable is maximum number of chunks to allocate with
154 @code{mmap}.  Setting this to zero disables all use of @code{mmap}.
156 The default value of this tunable is @samp{65536}.
157 @end deftp
159 @deftp Tunable glibc.malloc.arena_test
160 This tunable supersedes the @env{MALLOC_ARENA_TEST} environment variable and is
161 identical in features.
163 The @code{glibc.malloc.arena_test} tunable specifies the number of arenas that
164 can be created before the test on the limit to the number of arenas is
165 conducted.  The value is ignored if @code{glibc.malloc.arena_max} is set.
167 The default value of this tunable is 2 for 32-bit systems and 8 for 64-bit
168 systems.
169 @end deftp
171 @deftp Tunable glibc.malloc.arena_max
172 This tunable supersedes the @env{MALLOC_ARENA_MAX} environment variable and is
173 identical in features.
175 This tunable sets the number of arenas to use in a process regardless of the
176 number of cores in the system.
178 The default value of this tunable is @code{0}, meaning that the limit on the
179 number of arenas is determined by the number of CPU cores online.  For 32-bit
180 systems the limit is twice the number of cores online and on 64-bit systems, it
181 is 8 times the number of cores online.
182 @end deftp
184 @deftp Tunable glibc.malloc.tcache_max
185 The maximum size of a request (in bytes) which may be met via the
186 per-thread cache.  The default (and maximum) value is 1032 bytes on
187 64-bit systems and 516 bytes on 32-bit systems.
188 @end deftp
190 @deftp Tunable glibc.malloc.tcache_count
191 The maximum number of chunks of each size to cache. The default is 7.
192 The upper limit is 65535.  If set to zero, the per-thread cache is effectively
193 disabled.
195 The approximate maximum overhead of the per-thread cache is thus equal
196 to the number of bins times the chunk count in each bin times the size
197 of each chunk.  With defaults, the approximate maximum overhead of the
198 per-thread cache is approximately 236 KB on 64-bit systems and 118 KB
199 on 32-bit systems.
200 @end deftp
202 @deftp Tunable glibc.malloc.tcache_unsorted_limit
203 When the user requests memory and the request cannot be met via the
204 per-thread cache, the arenas are used to meet the request.  At this
205 time, additional chunks will be moved from existing arena lists to
206 pre-fill the corresponding cache.  While copies from the fastbins,
207 smallbins, and regular bins are bounded and predictable due to the bin
208 sizes, copies from the unsorted bin are not bounded, and incur
209 additional time penalties as they need to be sorted as they're
210 scanned.  To make scanning the unsorted list more predictable and
211 bounded, the user may set this tunable to limit the number of chunks
212 that are scanned from the unsorted list while searching for chunks to
213 pre-fill the per-thread cache with.  The default, or when set to zero,
214 is no limit.
215 @end deftp
217 @deftp Tunable glibc.malloc.mxfast
218 One of the optimizations malloc uses is to maintain a series of ``fast
219 bins'' that hold chunks up to a specific size.  The default and
220 maximum size which may be held this way is 80 bytes on 32-bit systems
221 or 160 bytes on 64-bit systems.  Applications which value size over
222 speed may choose to reduce the size of requests which are serviced
223 from fast bins with this tunable.  Note that the value specified
224 includes malloc's internal overhead, which is normally the size of one
225 pointer, so add 4 on 32-bit systems or 8 on 64-bit systems to the size
226 passed to @code{malloc} for the largest bin size to enable.
227 @end deftp
229 @node Elision Tunables
230 @section Elision Tunables
231 @cindex elision tunables
232 @cindex tunables, elision
234 @deftp {Tunable namespace} glibc.elision
235 Contended locks are usually slow and can lead to performance and scalability
236 issues in multithread code. Lock elision will use memory transactions to under
237 certain conditions, to elide locks and improve performance.
238 Elision behavior can be modified by setting the following tunables in
239 the @code{elision} namespace:
240 @end deftp
242 @deftp Tunable glibc.elision.enable
243 The @code{glibc.elision.enable} tunable enables lock elision if the feature is
244 supported by the hardware.  If elision is not supported by the hardware this
245 tunable has no effect.
247 Elision tunables are supported for 64-bit Intel, IBM POWER, and z System
248 architectures.
249 @end deftp
251 @deftp Tunable glibc.elision.skip_lock_busy
252 The @code{glibc.elision.skip_lock_busy} tunable sets how many times to use a
253 non-transactional lock after a transactional failure has occurred because the
254 lock is already acquired.  Expressed in number of lock acquisition attempts.
256 The default value of this tunable is @samp{3}.
257 @end deftp
259 @deftp Tunable glibc.elision.skip_lock_internal_abort
260 The @code{glibc.elision.skip_lock_internal_abort} tunable sets how many times
261 the thread should avoid using elision if a transaction aborted for any reason
262 other than a different thread's memory accesses.  Expressed in number of lock
263 acquisition attempts.
265 The default value of this tunable is @samp{3}.
266 @end deftp
268 @deftp Tunable glibc.elision.skip_lock_after_retries
269 The @code{glibc.elision.skip_lock_after_retries} tunable sets how many times
270 to try to elide a lock with transactions, that only failed due to a different
271 thread's memory accesses, before falling back to regular lock.
272 Expressed in number of lock elision attempts.
274 This tunable is supported only on IBM POWER, and z System architectures.
276 The default value of this tunable is @samp{3}.
277 @end deftp
279 @deftp Tunable glibc.elision.tries
280 The @code{glibc.elision.tries} sets how many times to retry elision if there is
281 chance for the transaction to finish execution e.g., it wasn't
282 aborted due to the lock being already acquired.  If elision is not supported
283 by the hardware this tunable is set to @samp{0} to avoid retries.
285 The default value of this tunable is @samp{3}.
286 @end deftp
288 @deftp Tunable glibc.elision.skip_trylock_internal_abort
289 The @code{glibc.elision.skip_trylock_internal_abort} tunable sets how many
290 times the thread should avoid trying the lock if a transaction aborted due to
291 reasons other than a different thread's memory accesses.  Expressed in number
292 of try lock attempts.
294 The default value of this tunable is @samp{3}.
295 @end deftp
297 @node POSIX Thread Tunables
298 @section POSIX Thread Tunables
299 @cindex pthread mutex tunables
300 @cindex thread mutex tunables
301 @cindex mutex tunables
302 @cindex tunables thread mutex
304 @deftp {Tunable namespace} glibc.pthread
305 The behavior of POSIX threads can be tuned to gain performance improvements
306 according to specific hardware capabilities and workload characteristics by
307 setting the following tunables in the @code{pthread} namespace:
308 @end deftp
310 @deftp Tunable glibc.pthread.mutex_spin_count
311 The @code{glibc.pthread.mutex_spin_count} tunable sets the maximum number of times
312 a thread should spin on the lock before calling into the kernel to block.
313 Adaptive spin is used for mutexes initialized with the
314 @code{PTHREAD_MUTEX_ADAPTIVE_NP} GNU extension.  It affects both
315 @code{pthread_mutex_lock} and @code{pthread_mutex_timedlock}.
317 The thread spins until either the maximum spin count is reached or the lock
318 is acquired.
320 The default value of this tunable is @samp{100}.
321 @end deftp
323 @node Hardware Capability Tunables
324 @section Hardware Capability Tunables
325 @cindex hardware capability tunables
326 @cindex hwcap tunables
327 @cindex tunables, hwcap
328 @cindex hwcaps tunables
329 @cindex tunables, hwcaps
330 @cindex data_cache_size tunables
331 @cindex tunables, data_cache_size
332 @cindex shared_cache_size tunables
333 @cindex tunables, shared_cache_size
334 @cindex non_temporal_threshold tunables
335 @cindex tunables, non_temporal_threshold
337 @deftp {Tunable namespace} glibc.cpu
338 Behavior of @theglibc{} can be tuned to assume specific hardware capabilities
339 by setting the following tunables in the @code{cpu} namespace:
340 @end deftp
342 @deftp Tunable glibc.cpu.hwcap_mask
343 This tunable supersedes the @env{LD_HWCAP_MASK} environment variable and is
344 identical in features.
346 The @code{AT_HWCAP} key in the Auxiliary Vector specifies instruction set
347 extensions available in the processor at runtime for some architectures.  The
348 @code{glibc.cpu.hwcap_mask} tunable allows the user to mask out those
349 capabilities at runtime, thus disabling use of those extensions.
350 @end deftp
352 @deftp Tunable glibc.cpu.hwcaps
353 The @code{glibc.cpu.hwcaps=-xxx,yyy,-zzz...} tunable allows the user to
354 enable CPU/ARCH feature @code{yyy}, disable CPU/ARCH feature @code{xxx}
355 and @code{zzz} where the feature name is case-sensitive and has to match
356 the ones in @code{sysdeps/x86/cpu-features.h}.
358 This tunable is specific to i386 and x86-64.
359 @end deftp
361 @deftp Tunable glibc.cpu.cached_memopt
362 The @code{glibc.cpu.cached_memopt=[0|1]} tunable allows the user to
363 enable optimizations recommended for cacheable memory.  If set to
364 @code{1}, @theglibc{} assumes that the process memory image consists
365 of cacheable (non-device) memory only.  The default, @code{0},
366 indicates that the process may use device memory.
368 This tunable is specific to powerpc, powerpc64 and powerpc64le.
369 @end deftp
371 @deftp Tunable glibc.cpu.name
372 The @code{glibc.cpu.name=xxx} tunable allows the user to tell @theglibc{} to
373 assume that the CPU is @code{xxx} where xxx may have one of these values:
374 @code{generic}, @code{falkor}, @code{thunderxt88}, @code{thunderx2t99},
375 @code{thunderx2t99p1}, @code{ares}, @code{emag}, @code{kunpeng}.
377 This tunable is specific to aarch64.
378 @end deftp
380 @deftp Tunable glibc.cpu.x86_data_cache_size
381 The @code{glibc.cpu.x86_data_cache_size} tunable allows the user to set
382 data cache size in bytes for use in memory and string routines.
384 This tunable is specific to i386 and x86-64.
385 @end deftp
387 @deftp Tunable glibc.cpu.x86_shared_cache_size
388 The @code{glibc.cpu.x86_shared_cache_size} tunable allows the user to
389 set shared cache size in bytes for use in memory and string routines.
390 @end deftp
392 @deftp Tunable glibc.cpu.x86_non_temporal_threshold
393 The @code{glibc.cpu.x86_non_temporal_threshold} tunable allows the user
394 to set threshold in bytes for non temporal store.
396 This tunable is specific to i386 and x86-64.
397 @end deftp
399 @deftp Tunable glibc.cpu.x86_ibt
400 The @code{glibc.cpu.x86_ibt} tunable allows the user to control how
401 indirect branch tracking (IBT) should be enabled.  Accepted values are
402 @code{on}, @code{off}, and @code{permissive}.  @code{on} always turns
403 on IBT regardless of whether IBT is enabled in the executable and its
404 dependent shared libraries.  @code{off} always turns off IBT regardless
405 of whether IBT is enabled in the executable and its dependent shared
406 libraries.  @code{permissive} is the same as the default which disables
407 IBT on non-CET executables and shared libraries.
409 This tunable is specific to i386 and x86-64.
410 @end deftp
412 @deftp Tunable glibc.cpu.x86_shstk
413 The @code{glibc.cpu.x86_shstk} tunable allows the user to control how
414 the shadow stack (SHSTK) should be enabled.  Accepted values are
415 @code{on}, @code{off}, and @code{permissive}.  @code{on} always turns on
416 SHSTK regardless of whether SHSTK is enabled in the executable and its
417 dependent shared libraries.  @code{off} always turns off SHSTK regardless
418 of whether SHSTK is enabled in the executable and its dependent shared
419 libraries.  @code{permissive} changes how dlopen works on non-CET shared
420 libraries.  By default, when SHSTK is enabled, dlopening a non-CET shared
421 library returns an error.  With @code{permissive}, it turns off SHSTK
422 instead.
424 This tunable is specific to i386 and x86-64.
425 @end deftp