tunables.texi 17 KB

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