Add malloc probes for sbrk and heap resizing.

for ChangeLog

	* malloc/arena.c (new_heap): New memory_heap_new probe.
	(grow_heap): New memory_heap_more probe.
	(shrink_heap): New memory_heap_less probe.
	(heap_trim): New memory_heap_free probe.
	* malloc/malloc.c (sysmalloc): New memory_sbrk_more probe.
	(systrim): New memory_sbrk_less probe.
	* manual/probes.texi: Document them.
This commit is contained in:
Alexandre Oliva 2013-09-20 11:10:56 -03:00
parent 655673f312
commit 322dea0838
4 changed files with 58 additions and 1 deletions

View file

@ -1,5 +1,13 @@
2013-09-20 Alexandre Oliva <aoliva@redhat.com>
* malloc/arena.c (new_heap): New memory_heap_new probe.
(grow_heap): New memory_heap_more probe.
(shrink_heap): New memory_heap_less probe.
(heap_trim): New memory_heap_free probe.
* malloc/malloc.c (sysmalloc): New memory_sbrk_more probe.
(systrim): New memory_sbrk_less probe.
* manual/probes.texi: Document them.
* malloc/arena.c (arena_get_retry): Add memory_arena_retry probe.
* manual/probes.texi: Document it.

View file

@ -581,6 +581,7 @@ new_heap(size_t size, size_t top_pad)
h->size = size;
h->mprotect_size = size;
THREAD_STAT(stat_n_heaps++);
LIBC_PROBE (memory_heap_new, 2, h, h->size);
return h;
}
@ -606,6 +607,7 @@ grow_heap(heap_info *h, long diff)
}
h->size = new_size;
LIBC_PROBE (memory_heap_more, 2, h, h->size);
return 0;
}
@ -633,6 +635,7 @@ shrink_heap(heap_info *h, long diff)
/*fprintf(stderr, "shrink %p %08lx\n", h, new_size);*/
h->size = new_size;
LIBC_PROBE (memory_heap_less, 2, h, h->size);
return 0;
}
@ -674,6 +677,7 @@ heap_trim(heap_info *heap, size_t pad)
break;
ar_ptr->system_mem -= heap->size;
arena_mem -= heap->size;
LIBC_PROBE (memory_heap_free, 2, heap, heap->size);
delete_heap(heap);
heap = prev_heap;
if(!prev_inuse(p)) { /* consolidate backward */

View file

@ -2448,8 +2448,10 @@ static void* sysmalloc(INTERNAL_SIZE_T nb, mstate av)
below even if we cannot call MORECORE.
*/
if (size > 0)
if (size > 0) {
brk = (char*)(MORECORE(size));
LIBC_PROBE (memory_sbrk_more, 2, brk, size);
}
if (brk != (char*)(MORECORE_FAILURE)) {
/* Call the `morecore' hook if necessary. */
@ -2747,6 +2749,8 @@ static int systrim(size_t pad, mstate av)
(*hook) ();
new_brk = (char*)(MORECORE(0));
LIBC_PROBE (memory_sbrk_less, 2, new_brk, extra);
if (new_brk != (char*)MORECORE_FAILURE) {
released = (long)(current_brk - new_brk);

View file

@ -26,6 +26,47 @@ the virtual memory subsystem of @theglibc{}. The location and the
availability of some probes depend on whether per-thread arenas are
enabled (the default) or disabled at the time @theglibc{} is compiled.
@deftp Probe memory_sbrk_more (void *@var{$arg1}, size_t @var{$arg2})
This probe is triggered after the main arena is extended by calling
@code{sbrk}. Argument @var{$arg1} is the additional size requested to
@code{sbrk}, and @var{$arg2} is the pointer that marks the end of the
@code{sbrk} area, returned in response to the request.
@end deftp
@deftp Probe memory_sbrk_less (void *@var{$arg1}, size_t @var{$arg2})
This probe is triggered after the size of the main arena is decreased by
calling @code{sbrk}. Argument @var{$arg1} is the size released by
@code{sbrk} (the positive value, rather than the negative value passed
to @code{sbrk}), and @var{$arg2} is the pointer that marks the end of
the @code{sbrk} area, returned in response to the request.
@end deftp
@deftp Probe memory_heap_new (void *@var{$arg1}, size_t @var{$arg2})
This probe is triggered after a new heap is @code{mmap}ed. Argument
@var{$arg1} is a pointer to the base of the memory area, where the
@code{heap_info} data structure is held, and @var{$arg2} is the size of
the heap.
@end deftp
@deftp Probe memory_heap_free (void *@var{$arg1}, size_t @var{$arg2})
This probe is triggered @emph{before} (unlike the other sbrk and heap
probes) a heap is completely removed via @code{munmap}. Argument
@var{$arg1} is a pointer to the heap, and @var{$arg2} is the size of the
heap.
@end deftp
@deftp Probe memory_heap_more (void *@var{$arg1}, size_t @var{$arg2})
This probe is triggered after a trailing portion of an @code{mmap}ed
heap is extended. Argument @var{$arg1} is a pointer to the heap, and
@var{$arg2} is the new size of the heap.
@end deftp
@deftp Probe memory_heap_less (void *@var{$arg1}, size_t @var{$arg2})
This probe is triggered after a trailing portion of an @code{mmap}ed
heap is released. Argument @var{$arg1} is a pointer to the heap, and
@var{$arg2} is the new size of the heap.
@end deftp
@deftp Probe memory_malloc_retry (size_t @var{$arg1})
@deftpx Probe memory_realloc_retry (size_t @var{$arg1}, void *@var{$arg2})
@deftpx Probe memory_memalign_retry (size_t @var{$arg1}, size_t @var{$arg2})