Blame manual/tunables.texi

Packit 6c4009
@node Tunables
Packit 6c4009
@c @node Tunables, , Internal Probes, Top
Packit 6c4009
@c %MENU% Tunable switches to alter libc internal behavior
Packit 6c4009
@chapter Tunables
Packit 6c4009
@cindex tunables
Packit 6c4009
Packit 6c4009
@dfn{Tunables} are a feature in @theglibc{} that allows application authors and
Packit 6c4009
distribution maintainers to alter the runtime library behavior to match
Packit 6c4009
their workload. These are implemented as a set of switches that may be
Packit 6c4009
modified in different ways. The current default method to do this is via
Packit 6c4009
the @env{GLIBC_TUNABLES} environment variable by setting it to a string
Packit 6c4009
of colon-separated @var{name}=@var{value} pairs.  For example, the following
Packit 6c4009
example enables malloc checking and sets the malloc trim threshold to 128
Packit 6c4009
bytes:
Packit 6c4009
Packit 6c4009
@example
Packit 6c4009
GLIBC_TUNABLES=glibc.malloc.trim_threshold=128:glibc.malloc.check=3
Packit 6c4009
export GLIBC_TUNABLES
Packit 6c4009
@end example
Packit 6c4009
Packit 6c4009
Tunables are not part of the @glibcadj{} stable ABI, and they are
Packit 6c4009
subject to change or removal across releases.  Additionally, the method to
Packit 6c4009
modify tunable values may change between releases and across distributions.
Packit 6c4009
It is possible to implement multiple `frontends' for the tunables allowing
Packit 6c4009
distributions to choose their preferred method at build time.
Packit 6c4009
Packit 6c4009
Finally, the set of tunables available may vary between distributions as
Packit 6c4009
the tunables feature allows distributions to add their own tunables under
Packit 6c4009
their own namespace.
Packit 6c4009
Packit 6c4009
@menu
Packit 6c4009
* Tunable names::  The structure of a tunable name
Packit 6c4009
* Memory Allocation Tunables::  Tunables in the memory allocation subsystem
Packit 6c4009
* Elision Tunables::  Tunables in elision subsystem
Packit 6c4009
* Hardware Capability Tunables::  Tunables that modify the hardware
Packit 6c4009
				  capabilities seen by @theglibc{}
Packit 6c4009
@end menu
Packit 6c4009
Packit 6c4009
@node Tunable names
Packit 6c4009
@section Tunable names
Packit 6c4009
@cindex Tunable names
Packit 6c4009
@cindex Tunable namespaces
Packit 6c4009
Packit 6c4009
A tunable name is split into three components, a top namespace, a tunable
Packit 6c4009
namespace and the tunable name. The top namespace for tunables implemented in
Packit 6c4009
@theglibc{} is @code{glibc}. Distributions that choose to add custom tunables
Packit 6c4009
in their maintained versions of @theglibc{} may choose to do so under their own
Packit 6c4009
top namespace.
Packit 6c4009
Packit 6c4009
The tunable namespace is a logical grouping of tunables in a single
Packit 6c4009
module. This currently holds no special significance, although that may
Packit 6c4009
change in the future.
Packit 6c4009
Packit 6c4009
The tunable name is the actual name of the tunable. It is possible that
Packit 6c4009
different tunable namespaces may have tunables within them that have the
Packit 6c4009
same name, likewise for top namespaces. Hence, we only support
Packit 6c4009
identification of tunables by their full name, i.e. with the top
Packit 6c4009
namespace, tunable namespace and tunable name, separated by periods.
Packit 6c4009
Packit 6c4009
@node Memory Allocation Tunables
Packit 6c4009
@section Memory Allocation Tunables
Packit 6c4009
@cindex memory allocation tunables
Packit 6c4009
@cindex malloc tunables
Packit 6c4009
@cindex tunables, malloc
Packit 6c4009
Packit 6c4009
@deftp {Tunable namespace} glibc.malloc
Packit 6c4009
Memory allocation behavior can be modified by setting any of the
Packit 6c4009
following tunables in the @code{malloc} namespace:
Packit 6c4009
@end deftp
Packit 6c4009
Packit 6c4009
@deftp Tunable glibc.malloc.check
Packit 6c4009
This tunable supersedes the @env{MALLOC_CHECK_} environment variable and is
Packit 6c4009
identical in features.
Packit 6c4009
Packit 6c4009
Setting this tunable to a non-zero value enables a special (less
Packit 6c4009
efficient) memory allocator for the malloc family of functions that is
Packit 6c4009
designed to be tolerant against simple errors such as double calls of
Packit 6c4009
free with the same argument, or overruns of a single byte (off-by-one
Packit 6c4009
bugs). Not all such errors can be protected against, however, and memory
Packit 6c4009
leaks can result.  Any detected heap corruption results in immediate
Packit 6c4009
termination of the process.
Packit 6c4009
Packit 6c4009
Like @env{MALLOC_CHECK_}, @code{glibc.malloc.check} has a problem in that it
Packit 6c4009
diverges from normal program behavior by writing to @code{stderr}, which could
Packit 6c4009
by exploited in SUID and SGID binaries.  Therefore, @code{glibc.malloc.check}
Packit 6c4009
is disabled by default for SUID and SGID binaries.  This can be enabled again
Packit 6c4009
by the system administrator by adding a file @file{/etc/suid-debug}; the
Packit 6c4009
content of the file could be anything or even empty.
Packit 6c4009
@end deftp
Packit 6c4009
Packit 6c4009
@deftp Tunable glibc.malloc.top_pad
Packit 6c4009
This tunable supersedes the @env{MALLOC_TOP_PAD_} environment variable and is
Packit 6c4009
identical in features.
Packit 6c4009
Packit 6c4009
This tunable determines the amount of extra memory in bytes to obtain from the
Packit 6c4009
system when any of the arenas need to be extended.  It also specifies the
Packit 6c4009
number of bytes to retain when shrinking any of the arenas.  This provides the
Packit 6c4009
necessary hysteresis in heap size such that excessive amounts of system calls
Packit 6c4009
can be avoided.
Packit 6c4009
Packit 6c4009
The default value of this tunable is @samp{0}.
Packit 6c4009
@end deftp
Packit 6c4009
Packit 6c4009
@deftp Tunable glibc.malloc.perturb
Packit 6c4009
This tunable supersedes the @env{MALLOC_PERTURB_} environment variable and is
Packit 6c4009
identical in features.
Packit 6c4009
Packit 6c4009
If set to a non-zero value, memory blocks are initialized with values depending
Packit 6c4009
on some low order bits of this tunable when they are allocated (except when
Packit 6c4009
allocated by calloc) and freed.  This can be used to debug the use of
Packit 6c4009
uninitialized or freed heap memory. Note that this option does not guarantee
Packit 6c4009
that the freed block will have any specific values. It only guarantees that the
Packit 6c4009
content the block had before it was freed will be overwritten.
Packit 6c4009
Packit 6c4009
The default value of this tunable is @samp{0}.
Packit 6c4009
@end deftp
Packit 6c4009
Packit 6c4009
@deftp Tunable glibc.malloc.mmap_threshold
Packit 6c4009
This tunable supersedes the @env{MALLOC_MMAP_THRESHOLD_} environment variable
Packit 6c4009
and is identical in features.
Packit 6c4009
Packit 6c4009
When this tunable is set, all chunks larger than this value in bytes are
Packit 6c4009
allocated outside the normal heap, using the @code{mmap} system call. This way
Packit 6c4009
it is guaranteed that the memory for these chunks can be returned to the system
Packit 6c4009
on @code{free}. Note that requests smaller than this threshold might still be
Packit 6c4009
allocated via @code{mmap}.
Packit 6c4009
Packit 6c4009
If this tunable is not set, the default value is set to @samp{131072} bytes and
Packit 6c4009
the threshold is adjusted dynamically to suit the allocation patterns of the
Packit 6c4009
program.  If the tunable is set, the dynamic adjustment is disabled and the
Packit 6c4009
value is set as static.
Packit 6c4009
@end deftp
Packit 6c4009
Packit 6c4009
@deftp Tunable glibc.malloc.trim_threshold
Packit 6c4009
This tunable supersedes the @env{MALLOC_TRIM_THRESHOLD_} environment variable
Packit 6c4009
and is identical in features.
Packit 6c4009
Packit 6c4009
The value of this tunable is the minimum size (in bytes) of the top-most,
Packit 6c4009
releasable chunk in an arena that will trigger a system call in order to return
Packit 6c4009
memory to the system from that arena.
Packit 6c4009
Packit 6c4009
If this tunable is not set, the default value is set as 128 KB and the
Packit 6c4009
threshold is adjusted dynamically to suit the allocation patterns of the
Packit 6c4009
program.  If the tunable is set, the dynamic adjustment is disabled and the
Packit 6c4009
value is set as static.
Packit 6c4009
@end deftp
Packit 6c4009
Packit 6c4009
@deftp Tunable glibc.malloc.mmap_max
Packit 6c4009
This tunable supersedes the @env{MALLOC_MMAP_MAX_} environment variable and is
Packit 6c4009
identical in features.
Packit 6c4009
Packit 6c4009
The value of this tunable is maximum number of chunks to allocate with
Packit 6c4009
@code{mmap}.  Setting this to zero disables all use of @code{mmap}.
Packit 6c4009
Packit 6c4009
The default value of this tunable is @samp{65536}.
Packit 6c4009
@end deftp
Packit 6c4009
Packit 6c4009
@deftp Tunable glibc.malloc.arena_test
Packit 6c4009
This tunable supersedes the @env{MALLOC_ARENA_TEST} environment variable and is
Packit 6c4009
identical in features.
Packit 6c4009
Packit 6c4009
The @code{glibc.malloc.arena_test} tunable specifies the number of arenas that
Packit 6c4009
can be created before the test on the limit to the number of arenas is
Packit 6c4009
conducted.  The value is ignored if @code{glibc.malloc.arena_max} is set.
Packit 6c4009
Packit 6c4009
The default value of this tunable is 2 for 32-bit systems and 8 for 64-bit
Packit 6c4009
systems.
Packit 6c4009
@end deftp
Packit 6c4009
Packit 6c4009
@deftp Tunable glibc.malloc.arena_max
Packit 6c4009
This tunable supersedes the @env{MALLOC_ARENA_MAX} environment variable and is
Packit 6c4009
identical in features.
Packit 6c4009
Packit 6c4009
This tunable sets the number of arenas to use in a process regardless of the
Packit 6c4009
number of cores in the system.
Packit 6c4009
Packit 6c4009
The default value of this tunable is @code{0}, meaning that the limit on the
Packit 6c4009
number of arenas is determined by the number of CPU cores online.  For 32-bit
Packit 6c4009
systems the limit is twice the number of cores online and on 64-bit systems, it
Packit 6c4009
is 8 times the number of cores online.
Packit 6c4009
@end deftp
Packit 6c4009
Packit 6c4009
@deftp Tunable glibc.malloc.tcache_max
Packit 6c4009
The maximum size of a request (in bytes) which may be met via the
Packit 6c4009
per-thread cache.  The default (and maximum) value is 1032 bytes on
Packit 6c4009
64-bit systems and 516 bytes on 32-bit systems.
Packit 6c4009
@end deftp
Packit 6c4009
Packit 6c4009
@deftp Tunable glibc.malloc.tcache_count
Packit 6c4009
The maximum number of chunks of each size to cache. The default is 7.
Packit Bot 0c2104
There is no upper limit, other than available system memory.  If set
Packit Bot 0c2104
to zero, the per-thread cache is effectively disabled.
Packit 6c4009
Packit 6c4009
The approximate maximum overhead of the per-thread cache is thus equal
Packit 6c4009
to the number of bins times the chunk count in each bin times the size
Packit 6c4009
of each chunk.  With defaults, the approximate maximum overhead of the
Packit 6c4009
per-thread cache is approximately 236 KB on 64-bit systems and 118 KB
Packit 6c4009
on 32-bit systems.
Packit 6c4009
@end deftp
Packit 6c4009
Packit 6c4009
@deftp Tunable glibc.malloc.tcache_unsorted_limit
Packit 6c4009
When the user requests memory and the request cannot be met via the
Packit 6c4009
per-thread cache, the arenas are used to meet the request.  At this
Packit 6c4009
time, additional chunks will be moved from existing arena lists to
Packit 6c4009
pre-fill the corresponding cache.  While copies from the fastbins,
Packit 6c4009
smallbins, and regular bins are bounded and predictable due to the bin
Packit 6c4009
sizes, copies from the unsorted bin are not bounded, and incur
Packit 6c4009
additional time penalties as they need to be sorted as they're
Packit 6c4009
scanned.  To make scanning the unsorted list more predictable and
Packit 6c4009
bounded, the user may set this tunable to limit the number of chunks
Packit 6c4009
that are scanned from the unsorted list while searching for chunks to
Packit 6c4009
pre-fill the per-thread cache with.  The default, or when set to zero,
Packit 6c4009
is no limit.
Packit 6c4009
@end deftp
Packit 6c4009
Packit 6c4009
@node Elision Tunables
Packit 6c4009
@section Elision Tunables
Packit 6c4009
@cindex elision tunables
Packit 6c4009
@cindex tunables, elision
Packit 6c4009
Packit 6c4009
@deftp {Tunable namespace} glibc.elision
Packit 6c4009
Contended locks are usually slow and can lead to performance and scalability
Packit 6c4009
issues in multithread code. Lock elision will use memory transactions to under
Packit 6c4009
certain conditions, to elide locks and improve performance.
Packit 6c4009
Elision behavior can be modified by setting the following tunables in
Packit 6c4009
the @code{elision} namespace:
Packit 6c4009
@end deftp
Packit 6c4009
Packit 6c4009
@deftp Tunable glibc.elision.enable
Packit 6c4009
The @code{glibc.elision.enable} tunable enables lock elision if the feature is
Packit 6c4009
supported by the hardware.  If elision is not supported by the hardware this
Packit 6c4009
tunable has no effect.
Packit 6c4009
Packit 6c4009
Elision tunables are supported for 64-bit Intel, IBM POWER, and z System
Packit 6c4009
architectures.
Packit 6c4009
@end deftp
Packit 6c4009
Packit 6c4009
@deftp Tunable glibc.elision.skip_lock_busy
Packit 6c4009
The @code{glibc.elision.skip_lock_busy} tunable sets how many times to use a
Packit 6c4009
non-transactional lock after a transactional failure has occurred because the
Packit 6c4009
lock is already acquired.  Expressed in number of lock acquisition attempts.
Packit 6c4009
Packit 6c4009
The default value of this tunable is @samp{3}.
Packit 6c4009
@end deftp
Packit 6c4009
Packit 6c4009
@deftp Tunable glibc.elision.skip_lock_internal_abort
Packit 6c4009
The @code{glibc.elision.skip_lock_internal_abort} tunable sets how many times
Packit 6c4009
the thread should avoid using elision if a transaction aborted for any reason
Packit 6c4009
other than a different thread's memory accesses.  Expressed in number of lock
Packit 6c4009
acquisition attempts.
Packit 6c4009
Packit 6c4009
The default value of this tunable is @samp{3}.
Packit 6c4009
@end deftp
Packit 6c4009
Packit 6c4009
@deftp Tunable glibc.elision.skip_lock_after_retries
Packit 6c4009
The @code{glibc.elision.skip_lock_after_retries} tunable sets how many times
Packit 6c4009
to try to elide a lock with transactions, that only failed due to a different
Packit 6c4009
thread's memory accesses, before falling back to regular lock.
Packit 6c4009
Expressed in number of lock elision attempts.
Packit 6c4009
Packit 6c4009
This tunable is supported only on IBM POWER, and z System architectures.
Packit 6c4009
Packit 6c4009
The default value of this tunable is @samp{3}.
Packit 6c4009
@end deftp
Packit 6c4009
Packit 6c4009
@deftp Tunable glibc.elision.tries
Packit 6c4009
The @code{glibc.elision.tries} sets how many times to retry elision if there is
Packit 6c4009
chance for the transaction to finish execution e.g., it wasn't
Packit 6c4009
aborted due to the lock being already acquired.  If elision is not supported
Packit 6c4009
by the hardware this tunable is set to @samp{0} to avoid retries.
Packit 6c4009
Packit 6c4009
The default value of this tunable is @samp{3}.
Packit 6c4009
@end deftp
Packit 6c4009
Packit 6c4009
@deftp Tunable glibc.elision.skip_trylock_internal_abort
Packit 6c4009
The @code{glibc.elision.skip_trylock_internal_abort} tunable sets how many
Packit 6c4009
times the thread should avoid trying the lock if a transaction aborted due to
Packit 6c4009
reasons other than a different thread's memory accesses.  Expressed in number
Packit 6c4009
of try lock attempts.
Packit 6c4009
Packit 6c4009
The default value of this tunable is @samp{3}.
Packit 6c4009
@end deftp
Packit 6c4009
Packit 6c4009
@node Hardware Capability Tunables
Packit 6c4009
@section Hardware Capability Tunables
Packit 6c4009
@cindex hardware capability tunables
Packit 6c4009
@cindex hwcap tunables
Packit 6c4009
@cindex tunables, hwcap
Packit 6c4009
@cindex hwcaps tunables
Packit 6c4009
@cindex tunables, hwcaps
Packit 6c4009
@cindex data_cache_size tunables
Packit 6c4009
@cindex tunables, data_cache_size
Packit 6c4009
@cindex shared_cache_size tunables
Packit 6c4009
@cindex tunables, shared_cache_size
Packit 6c4009
@cindex non_temporal_threshold tunables
Packit 6c4009
@cindex tunables, non_temporal_threshold
Packit 6c4009
Packit Bot 0c2104
@deftp {Tunable namespace} glibc.tune
Packit 6c4009
Behavior of @theglibc{} can be tuned to assume specific hardware capabilities
Packit Bot 0c2104
by setting the following tunables in the @code{tune} namespace:
Packit 6c4009
@end deftp
Packit 6c4009
Packit Bot 0c2104
@deftp Tunable glibc.tune.hwcap_mask
Packit 6c4009
This tunable supersedes the @env{LD_HWCAP_MASK} environment variable and is
Packit 6c4009
identical in features.
Packit 6c4009
Packit 6c4009
The @code{AT_HWCAP} key in the Auxiliary Vector specifies instruction set
Packit 6c4009
extensions available in the processor at runtime for some architectures.  The
Packit Bot 0c2104
@code{glibc.tune.hwcap_mask} tunable allows the user to mask out those
Packit 6c4009
capabilities at runtime, thus disabling use of those extensions.
Packit 6c4009
@end deftp
Packit 6c4009
Packit Bot 0c2104
@deftp Tunable glibc.tune.hwcaps
Packit Bot 0c2104
The @code{glibc.tune.hwcaps=-xxx,yyy,-zzz...} tunable allows the user to
Packit 6c4009
enable CPU/ARCH feature @code{yyy}, disable CPU/ARCH feature @code{xxx}
Packit 6c4009
and @code{zzz} where the feature name is case-sensitive and has to match
Packit 6c4009
the ones in @code{sysdeps/x86/cpu-features.h}.
Packit 6c4009
Packit 6c4009
This tunable is specific to i386 and x86-64.
Packit 6c4009
@end deftp
Packit 6c4009
Packit Bot 0c2104
@deftp Tunable glibc.tune.cached_memopt
Packit Bot 0c2104
The @code{glibc.tune.cached_memopt=[0|1]} tunable allows the user to
Packit 6c4009
enable optimizations recommended for cacheable memory.  If set to
Packit 6c4009
@code{1}, @theglibc{} assumes that the process memory image consists
Packit 6c4009
of cacheable (non-device) memory only.  The default, @code{0},
Packit 6c4009
indicates that the process may use device memory.
Packit 6c4009
Packit 6c4009
This tunable is specific to powerpc, powerpc64 and powerpc64le.
Packit 6c4009
@end deftp
Packit 6c4009
Packit Bot 0c2104
@deftp Tunable glibc.tune.cpu
Packit Bot 0c2104
The @code{glibc.tune.cpu=xxx} tunable allows the user to tell @theglibc{} to
Packit 6c4009
assume that the CPU is @code{xxx} where xxx may have one of these values:
Packit 6c4009
@code{generic}, @code{falkor}, @code{thunderxt88}, @code{thunderx2t99},
Packit 6c4009
@code{thunderx2t99p1}.
Packit 6c4009
Packit 6c4009
This tunable is specific to aarch64.
Packit 6c4009
@end deftp
Packit 6c4009
Packit Bot 0c2104
@deftp Tunable glibc.tune.x86_data_cache_size
Packit Bot 0c2104
The @code{glibc.tune.x86_data_cache_size} tunable allows the user to set
Packit 6c4009
data cache size in bytes for use in memory and string routines.
Packit 6c4009
Packit 6c4009
This tunable is specific to i386 and x86-64.
Packit 6c4009
@end deftp
Packit 6c4009
Packit Bot 0c2104
@deftp Tunable glibc.tune.x86_shared_cache_size
Packit Bot 0c2104
The @code{glibc.tune.x86_shared_cache_size} tunable allows the user to
Packit 6c4009
set shared cache size in bytes for use in memory and string routines.
Packit 6c4009
@end deftp
Packit 6c4009
Packit Bot 0c2104
@deftp Tunable glibc.tune.x86_non_temporal_threshold
Packit Bot 0c2104
The @code{glibc.tune.x86_non_temporal_threshold} tunable allows the user
Packit Bot 0c2104
to set threshold in bytes for non temporal store.
Packit Service 83a272
Packit Service 83a272
This tunable is specific to i386 and x86-64.
Packit Service 83a272
@end deftp
Packit Service 83a272
Packit Bot 0c2104
@deftp Tunable glibc.tune.x86_ibt
Packit Bot 0c2104
The @code{glibc.tune.x86_ibt} tunable allows the user to control how
Packit 6c4009
indirect branch tracking (IBT) should be enabled.  Accepted values are
Packit 6c4009
@code{on}, @code{off}, and @code{permissive}.  @code{on} always turns
Packit 6c4009
on IBT regardless of whether IBT is enabled in the executable and its
Packit 6c4009
dependent shared libraries.  @code{off} always turns off IBT regardless
Packit 6c4009
of whether IBT is enabled in the executable and its dependent shared
Packit 6c4009
libraries.  @code{permissive} is the same as the default which disables
Packit 6c4009
IBT on non-CET executables and shared libraries.
Packit 6c4009
Packit 6c4009
This tunable is specific to i386 and x86-64.
Packit 6c4009
@end deftp
Packit 6c4009
Packit Bot 0c2104
@deftp Tunable glibc.tune.x86_shstk
Packit Bot 0c2104
The @code{glibc.tune.x86_shstk} tunable allows the user to control how
Packit 6c4009
the shadow stack (SHSTK) should be enabled.  Accepted values are
Packit 6c4009
@code{on}, @code{off}, and @code{permissive}.  @code{on} always turns on
Packit 6c4009
SHSTK regardless of whether SHSTK is enabled in the executable and its
Packit 6c4009
dependent shared libraries.  @code{off} always turns off SHSTK regardless
Packit 6c4009
of whether SHSTK is enabled in the executable and its dependent shared
Packit 6c4009
libraries.  @code{permissive} changes how dlopen works on non-CET shared
Packit 6c4009
libraries.  By default, when SHSTK is enabled, dlopening a non-CET shared
Packit 6c4009
library returns an error.  With @code{permissive}, it turns off SHSTK
Packit 6c4009
instead.
Packit 6c4009
Packit 6c4009
This tunable is specific to i386 and x86-64.
Packit 6c4009
@end deftp