probes.texi 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. @node Internal Probes
  2. @c @node Internal Probes, Tunables, Dynamic Linker, Top
  3. @c %MENU% Probes to monitor libc internal behavior
  4. @chapter Internal probes
  5. In order to aid in debugging and monitoring internal behavior,
  6. @theglibc{} exposes nearly-zero-overhead SystemTap probes marked with
  7. the @code{libc} provider.
  8. These probes are not part of the @glibcadj{} stable ABI, and they are
  9. subject to change or removal across releases. Our only promise with
  10. regard to them is that, if we find a need to remove or modify the
  11. arguments of a probe, the modified probe will have a different name, so
  12. that program monitors relying on the old probe will not get unexpected
  13. arguments.
  14. @menu
  15. * Memory Allocation Probes:: Probes in the memory allocation subsystem
  16. * Non-local Goto Probes:: Probes in setjmp and longjmp
  17. @end menu
  18. @node Memory Allocation Probes
  19. @section Memory Allocation Probes
  20. These probes are designed to signal relatively unusual situations within
  21. the virtual memory subsystem of @theglibc{}.
  22. @deftp Probe memory_sbrk_more (void *@var{$arg1}, size_t @var{$arg2})
  23. This probe is triggered after the main arena is extended by calling
  24. @code{sbrk}. Argument @var{$arg1} is the additional size requested to
  25. @code{sbrk}, and @var{$arg2} is the pointer that marks the end of the
  26. @code{sbrk} area, returned in response to the request.
  27. @end deftp
  28. @deftp Probe memory_sbrk_less (void *@var{$arg1}, size_t @var{$arg2})
  29. This probe is triggered after the size of the main arena is decreased by
  30. calling @code{sbrk}. Argument @var{$arg1} is the size released by
  31. @code{sbrk} (the positive value, rather than the negative value passed
  32. to @code{sbrk}), and @var{$arg2} is the pointer that marks the end of
  33. the @code{sbrk} area, returned in response to the request.
  34. @end deftp
  35. @deftp Probe memory_heap_new (void *@var{$arg1}, size_t @var{$arg2})
  36. This probe is triggered after a new heap is @code{mmap}ed. Argument
  37. @var{$arg1} is a pointer to the base of the memory area, where the
  38. @code{heap_info} data structure is held, and @var{$arg2} is the size of
  39. the heap.
  40. @end deftp
  41. @deftp Probe memory_heap_free (void *@var{$arg1}, size_t @var{$arg2})
  42. This probe is triggered @emph{before} (unlike the other sbrk and heap
  43. probes) a heap is completely removed via @code{munmap}. Argument
  44. @var{$arg1} is a pointer to the heap, and @var{$arg2} is the size of the
  45. heap.
  46. @end deftp
  47. @deftp Probe memory_heap_more (void *@var{$arg1}, size_t @var{$arg2})
  48. This probe is triggered after a trailing portion of an @code{mmap}ed
  49. heap is extended. Argument @var{$arg1} is a pointer to the heap, and
  50. @var{$arg2} is the new size of the heap.
  51. @end deftp
  52. @deftp Probe memory_heap_less (void *@var{$arg1}, size_t @var{$arg2})
  53. This probe is triggered after a trailing portion of an @code{mmap}ed
  54. heap is released. Argument @var{$arg1} is a pointer to the heap, and
  55. @var{$arg2} is the new size of the heap.
  56. @end deftp
  57. @deftp Probe memory_malloc_retry (size_t @var{$arg1})
  58. @deftpx Probe memory_realloc_retry (size_t @var{$arg1}, void *@var{$arg2})
  59. @deftpx Probe memory_memalign_retry (size_t @var{$arg1}, size_t @var{$arg2})
  60. @deftpx Probe memory_calloc_retry (size_t @var{$arg1})
  61. These probes are triggered when the corresponding functions fail to
  62. obtain the requested amount of memory from the arena in use, before they
  63. call @code{arena_get_retry} to select an alternate arena in which to
  64. retry the allocation. Argument @var{$arg1} is the amount of memory
  65. requested by the user; in the @code{calloc} case, that is the total size
  66. computed from both function arguments. In the @code{realloc} case,
  67. @var{$arg2} is the pointer to the memory area being resized. In the
  68. @code{memalign} case, @var{$arg2} is the alignment to be used for the
  69. request, which may be stricter than the value passed to the
  70. @code{memalign} function. A @code{memalign} probe is also used by functions
  71. @code{posix_memalign, valloc} and @code{pvalloc}.
  72. Note that the argument order does @emph{not} match that of the
  73. corresponding two-argument functions, so that in all of these probes the
  74. user-requested allocation size is in @var{$arg1}.
  75. @end deftp
  76. @deftp Probe memory_arena_retry (size_t @var{$arg1}, void *@var{$arg2})
  77. This probe is triggered within @code{arena_get_retry} (the function
  78. called to select the alternate arena in which to retry an allocation
  79. that failed on the first attempt), before the selection of an alternate
  80. arena. This probe is redundant, but much easier to use when it's not
  81. important to determine which of the various memory allocation functions
  82. is failing to allocate on the first try. Argument @var{$arg1} is the
  83. same as in the function-specific probes, except for extra room for
  84. padding introduced by functions that have to ensure stricter alignment.
  85. Argument @var{$arg2} is the arena in which allocation failed.
  86. @end deftp
  87. @deftp Probe memory_arena_new (void *@var{$arg1}, size_t @var{$arg2})
  88. This probe is triggered when @code{malloc} allocates and initializes an
  89. additional arena (not the main arena), but before the arena is assigned
  90. to the running thread or inserted into the internal linked list of
  91. arenas. The arena's @code{malloc_state} internal data structure is
  92. located at @var{$arg1}, within a newly-allocated heap big enough to hold
  93. at least @var{$arg2} bytes.
  94. @end deftp
  95. @deftp Probe memory_arena_reuse (void *@var{$arg1}, void *@var{$arg2})
  96. This probe is triggered when @code{malloc} has just selected an existing
  97. arena to reuse, and (temporarily) reserved it for exclusive use.
  98. Argument @var{$arg1} is a pointer to the newly-selected arena, and
  99. @var{$arg2} is a pointer to the arena previously used by that thread.
  100. This occurs within
  101. @code{reused_arena}, right after the mutex mentioned in probe
  102. @code{memory_arena_reuse_wait} is acquired; argument @var{$arg1} will
  103. point to the same arena. In this configuration, this will usually only
  104. occur once per thread. The exception is when a thread first selected
  105. the main arena, but a subsequent allocation from it fails: then, and
  106. only then, may we switch to another arena to retry that allocation, and
  107. for further allocations within that thread.
  108. @end deftp
  109. @deftp Probe memory_arena_reuse_wait (void *@var{$arg1}, void *@var{$arg2}, void *@var{$arg3})
  110. This probe is triggered when @code{malloc} is about to wait for an arena
  111. to become available for reuse. Argument @var{$arg1} holds a pointer to
  112. the mutex the thread is going to wait on, @var{$arg2} is a pointer to a
  113. newly-chosen arena to be reused, and @var{$arg3} is a pointer to the
  114. arena previously used by that thread.
  115. This occurs within
  116. @code{reused_arena}, when a thread first tries to allocate memory or
  117. needs a retry after a failure to allocate from the main arena, there
  118. isn't any free arena, the maximum number of arenas has been reached, and
  119. an existing arena was chosen for reuse, but its mutex could not be
  120. immediately acquired. The mutex in @var{$arg1} is the mutex of the
  121. selected arena.
  122. @end deftp
  123. @deftp Probe memory_arena_reuse_free_list (void *@var{$arg1})
  124. This probe is triggered when @code{malloc} has chosen an arena that is
  125. in the free list for use by a thread, within the @code{get_free_list}
  126. function. The argument @var{$arg1} holds a pointer to the selected arena.
  127. @end deftp
  128. @deftp Probe memory_mallopt (int @var{$arg1}, int @var{$arg2})
  129. This probe is triggered when function @code{mallopt} is called to change
  130. @code{malloc} internal configuration parameters, before any change to
  131. the parameters is made. The arguments @var{$arg1} and @var{$arg2} are
  132. the ones passed to the @code{mallopt} function.
  133. @end deftp
  134. @deftp Probe memory_mallopt_mxfast (int @var{$arg1}, int @var{$arg2})
  135. This probe is triggered shortly after the @code{memory_mallopt} probe,
  136. when the parameter to be changed is @code{M_MXFAST}, and the requested
  137. value is in an acceptable range. Argument @var{$arg1} is the requested
  138. value, and @var{$arg2} is the previous value of this @code{malloc}
  139. parameter.
  140. @end deftp
  141. @deftp Probe memory_mallopt_trim_threshold (int @var{$arg1}, int @var{$arg2}, int @var{$arg3})
  142. This probe is triggered shortly after the @code{memory_mallopt} probe,
  143. when the parameter to be changed is @code{M_TRIM_THRESHOLD}. Argument
  144. @var{$arg1} is the requested value, @var{$arg2} is the previous value of
  145. this @code{malloc} parameter, and @var{$arg3} is nonzero if dynamic
  146. threshold adjustment was already disabled.
  147. @end deftp
  148. @deftp Probe memory_mallopt_top_pad (int @var{$arg1}, int @var{$arg2}, int @var{$arg3})
  149. This probe is triggered shortly after the @code{memory_mallopt} probe,
  150. when the parameter to be changed is @code{M_TOP_PAD}. Argument
  151. @var{$arg1} is the requested value, @var{$arg2} is the previous value of
  152. this @code{malloc} parameter, and @var{$arg3} is nonzero if dynamic
  153. threshold adjustment was already disabled.
  154. @end deftp
  155. @deftp Probe memory_mallopt_mmap_threshold (int @var{$arg1}, int @var{$arg2}, int @var{$arg3})
  156. This probe is triggered shortly after the @code{memory_mallopt} probe,
  157. when the parameter to be changed is @code{M_MMAP_THRESHOLD}, and the
  158. requested value is in an acceptable range. Argument @var{$arg1} is the
  159. requested value, @var{$arg2} is the previous value of this @code{malloc}
  160. parameter, and @var{$arg3} is nonzero if dynamic threshold adjustment
  161. was already disabled.
  162. @end deftp
  163. @deftp Probe memory_mallopt_mmap_max (int @var{$arg1}, int @var{$arg2}, int @var{$arg3})
  164. This probe is triggered shortly after the @code{memory_mallopt} probe,
  165. when the parameter to be changed is @code{M_MMAP_MAX}. Argument
  166. @var{$arg1} is the requested value, @var{$arg2} is the previous value of
  167. this @code{malloc} parameter, and @var{$arg3} is nonzero if dynamic
  168. threshold adjustment was already disabled.
  169. @end deftp
  170. @deftp Probe memory_mallopt_perturb (int @var{$arg1}, int @var{$arg2})
  171. This probe is triggered shortly after the @code{memory_mallopt} probe,
  172. when the parameter to be changed is @code{M_PERTURB}. Argument
  173. @var{$arg1} is the requested value, and @var{$arg2} is the previous
  174. value of this @code{malloc} parameter.
  175. @end deftp
  176. @deftp Probe memory_mallopt_arena_test (int @var{$arg1}, int @var{$arg2})
  177. This probe is triggered shortly after the @code{memory_mallopt} probe,
  178. when the parameter to be changed is @code{M_ARENA_TEST}, and the
  179. requested value is in an acceptable range. Argument @var{$arg1} is the
  180. requested value, and @var{$arg2} is the previous value of this
  181. @code{malloc} parameter.
  182. @end deftp
  183. @deftp Probe memory_mallopt_arena_max (int @var{$arg1}, int @var{$arg2})
  184. This probe is triggered shortly after the @code{memory_mallopt} probe,
  185. when the parameter to be changed is @code{M_ARENA_MAX}, and the
  186. requested value is in an acceptable range. Argument @var{$arg1} is the
  187. requested value, and @var{$arg2} is the previous value of this
  188. @code{malloc} parameter.
  189. @end deftp
  190. @deftp Probe memory_mallopt_free_dyn_thresholds (int @var{$arg1}, int @var{$arg2})
  191. This probe is triggered when function @code{free} decides to adjust the
  192. dynamic brk/mmap thresholds. Argument @var{$arg1} and @var{$arg2} are
  193. the adjusted mmap and trim thresholds, respectively.
  194. @end deftp
  195. @deftp Probe memory_tunable_tcache_max_bytes (int @var{$arg1}, int @var{$arg2})
  196. This probe is triggered when the @code{glibc.malloc.tcache_max}
  197. tunable is set. Argument @var{$arg1} is the requested value, and
  198. @var{$arg2} is the previous value of this tunable.
  199. @end deftp
  200. @deftp Probe memory_tunable_tcache_count (int @var{$arg1}, int @var{$arg2})
  201. This probe is triggered when the @code{glibc.malloc.tcache_count}
  202. tunable is set. Argument @var{$arg1} is the requested value, and
  203. @var{$arg2} is the previous value of this tunable.
  204. @end deftp
  205. @deftp Probe memory_tunable_tcache_unsorted_limit (int @var{$arg1}, int @var{$arg2})
  206. This probe is triggered when the
  207. @code{glibc.malloc.tcache_unsorted_limit} tunable is set. Argument
  208. @var{$arg1} is the requested value, and @var{$arg2} is the previous
  209. value of this tunable.
  210. @end deftp
  211. @deftp Probe memory_tcache_double_free (void *@var{$arg1}, int @var{$arg2})
  212. This probe is triggered when @code{free} determines that the memory
  213. being freed has probably already been freed, and resides in the
  214. per-thread cache. Note that there is an extremely unlikely chance
  215. that this probe will trigger due to random payload data remaining in
  216. the allocated memory matching the key used to detect double frees.
  217. This probe actually indicates that an expensive linear search of the
  218. tcache, looking for a double free, has happened. Argument @var{$arg1}
  219. is the memory location as passed to @code{free}, Argument @var{$arg2}
  220. is the tcache bin it resides in.
  221. @end deftp
  222. @node Non-local Goto Probes
  223. @section Non-local Goto Probes
  224. These probes are used to signal calls to @code{setjmp}, @code{sigsetjmp},
  225. @code{longjmp} or @code{siglongjmp}.
  226. @deftp Probe setjmp (void *@var{$arg1}, int @var{$arg2}, void *@var{$arg3})
  227. This probe is triggered whenever @code{setjmp} or @code{sigsetjmp} is
  228. called. Argument @var{$arg1} is a pointer to the @code{jmp_buf}
  229. passed as the first argument of @code{setjmp} or @code{sigsetjmp},
  230. @var{$arg2} is the second argument of @code{sigsetjmp} or zero if this
  231. is a call to @code{setjmp} and @var{$arg3} is a pointer to the return
  232. address that will be stored in the @code{jmp_buf}.
  233. @end deftp
  234. @deftp Probe longjmp (void *@var{$arg1}, int @var{$arg2}, void *@var{$arg3})
  235. This probe is triggered whenever @code{longjmp} or @code{siglongjmp}
  236. is called. Argument @var{$arg1} is a pointer to the @code{jmp_buf}
  237. passed as the first argument of @code{longjmp} or @code{siglongjmp},
  238. @var{$arg2} is the return value passed as the second argument of
  239. @code{longjmp} or @code{siglongjmp} and @var{$arg3} is a pointer to
  240. the return address @code{longjmp} or @code{siglongjmp} will return to.
  241. The @code{longjmp} probe is triggered at a point where the registers
  242. have not yet been restored to the values in the @code{jmp_buf} and
  243. unwinding will show a call stack including the caller of
  244. @code{longjmp} or @code{siglongjmp}.
  245. @end deftp
  246. @deftp Probe longjmp_target (void *@var{$arg1}, int @var{$arg2}, void *@var{$arg3})
  247. This probe is triggered under the same conditions and with the same
  248. arguments as the @code{longjmp} probe.
  249. The @code{longjmp_target} probe is triggered at a point where the
  250. registers have been restored to the values in the @code{jmp_buf} and
  251. unwinding will show a call stack including the caller of @code{setjmp}
  252. or @code{sigsetjmp}.
  253. @end deftp