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