Skip to content

Commit

Permalink
Merge pull request #158 from hoopoepg/topic/make-memtrack-api-public-…
Browse files Browse the repository at this point in the history
…int3

UCS/MEMTRACK: added public API for memtrack - int3
  • Loading branch information
yosefe authored Jul 13, 2021
2 parents 682048e + de3247c commit d8c5e65
Show file tree
Hide file tree
Showing 64 changed files with 225 additions and 245 deletions.
18 changes: 0 additions & 18 deletions config/m4/ucs.m4
Original file line number Diff line number Diff line change
Expand Up @@ -115,24 +115,6 @@ AS_IF([test "x$enable_tuning" = xyes],
AM_CONDITIONAL([HAVE_TUNING],[test "x$HAVE_TUNING" = "xyes"])


#
# Enable memory tracking
#
AC_ARG_ENABLE([memtrack],
AS_HELP_STRING([--enable-memtrack],
[Enable memory tracking, useful for profiling, default: NO]),
[],
[enable_memtrack=no])

AS_IF([test "x$enable_memtrack" = xyes],
[AS_MESSAGE([enabling memory tracking])
AC_DEFINE([ENABLE_MEMTRACK], [1], [Enable memory tracking])
HAVE_MEMTRACK=yes],
[:]
)
AM_CONDITIONAL([HAVE_MEMTRACK],[test "x$HAVE_MEMTRACK" = "xyes"])


#
# Disable logging levels below INFO
#
Expand Down
1 change: 0 additions & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,6 @@ AS_IF([test "x$with_docs_only" = xyes],
AM_CONDITIONAL([HAVE_GTEST], [false])
AM_CONDITIONAL([HAVE_STATS], [false])
AM_CONDITIONAL([HAVE_TUNING], [false])
AM_CONDITIONAL([HAVE_MEMTRACK], [false])
AM_CONDITIONAL([HAVE_IB], [false])
AM_CONDITIONAL([HAVE_MLX5_HW], [false])
AM_CONDITIONAL([HAVE_MLX5_HW_UD], [false])
Expand Down
1 change: 0 additions & 1 deletion contrib/configure-devel
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ $basedir/../configure \
--enable-profiling \
--enable-frame-pointer \
--enable-stats \
--enable-memtrack \
--enable-fault-injection \
--enable-debug-data \
--enable-mt \
Expand Down
1 change: 0 additions & 1 deletion contrib/configure-prof
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,4 @@ $basedir/../configure \
--enable-profiling \
--enable-frame-pointer \
--enable-stats \
--enable-memtrack \
"$@"
2 changes: 1 addition & 1 deletion src/ucp/core/ucp_ep.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include <ucp/stream/stream.h>
#include <ucp/core/ucp_listener.h>
#include <ucs/datastruct/queue.h>
#include <ucs/debug/memtrack.h>
#include <ucs/debug/memtrack_int.h>
#include <ucs/debug/log.h>
#include <ucs/sys/string.h>
#include <ucs/sys/sock.h>
Expand Down
2 changes: 1 addition & 1 deletion src/ucp/core/ucp_mm.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include "ucp_worker.h"

#include <ucs/debug/log.h>
#include <ucs/debug/memtrack.h>
#include <ucs/debug/memtrack_int.h>
#include <ucs/sys/math.h>
#include <ucs/sys/string.h>
#include <ucs/sys/sys.h>
Expand Down
2 changes: 1 addition & 1 deletion src/ucp/dt/dt_generic.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include "dt_generic.h"

#include <ucs/sys/math.h>
#include <ucs/debug/memtrack.h>
#include <ucs/debug/memtrack_int.h>


ucs_status_t ucp_dt_create_generic(const ucp_generic_dt_ops_t *ops, void *context,
Expand Down
3 changes: 2 additions & 1 deletion src/ucs/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ nobase_dist_libucs_la_HEADERS = \
datastruct/string_buffer.h \
datastruct/string_set.h \
debug/log_def.h \
debug/memtrack.h \
memory/rcache.h \
memory/memory_type.h \
memory/memtype_cache.h \
Expand Down Expand Up @@ -86,7 +87,7 @@ noinst_HEADERS = \
debug/assert.h \
debug/debug.h \
debug/log.h \
debug/memtrack.h \
debug/memtrack_int.h \
memory/numa.h \
memory/rcache_int.h \
profile/profile.h \
Expand Down
2 changes: 0 additions & 2 deletions src/ucs/config/global_opts.c
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,6 @@ static ucs_config_field_t ucs_global_opts_table[] = {

#endif

#ifdef ENABLE_MEMTRACK
{"MEMTRACK_DEST", "",
"Destination to output memory tracking report to. If the value is empty,\n"
"results are not reported. Possible values are:\n"
Expand All @@ -197,7 +196,6 @@ static ucs_config_field_t ucs_global_opts_table[] = {
"Memory limit allocated by memtrack. In case if limit is reached then\n"
"memtrack report is generated and process is terminated.\n",
ucs_offsetof(ucs_global_opts_t, memtrack_limit), UCS_CONFIG_TYPE_MEMUNITS},
#endif

{"PROFILE_MODE", "",
"Profile collection modes. If none is specified, profiling is disabled.\n"
Expand Down
2 changes: 1 addition & 1 deletion src/ucs/datastruct/mpmc.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#include <ucs/arch/atomic.h>
#include <ucs/arch/bitops.h>
#include <ucs/debug/assert.h>
#include <ucs/debug/memtrack.h>
#include <ucs/debug/memtrack_int.h>


ucs_status_t ucs_mpmc_queue_init(ucs_mpmc_queue_t *mpmc, uint32_t length)
Expand Down
2 changes: 1 addition & 1 deletion src/ucs/datastruct/pgtable.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include <ucs/arch/bitops.h>
#include <ucs/debug/assert.h>
#include <ucs/debug/log.h>
#include <ucs/debug/memtrack.h>
#include <ucs/debug/memtrack_int.h>
#include <ucs/sys/math.h>
#include <string.h>

Expand Down
11 changes: 5 additions & 6 deletions src/ucs/datastruct/ptr_array.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,14 @@ static void ucs_ptr_array_clear(ucs_ptr_array_t *ptr_array)
ptr_array->start = NULL;
ptr_array->size = 0;
ptr_array->freelist = UCS_PTR_ARRAY_SENTINEL;
ptr_array->name = NULL;
}

void ucs_ptr_array_init(ucs_ptr_array_t *ptr_array, uint32_t init_placeholder,
const char *name)
{
ptr_array->init_placeholder = init_placeholder;
ucs_ptr_array_clear(ptr_array);
#ifdef ENABLE_MEMTRACK
ucs_snprintf_zero(ptr_array->name, sizeof(ptr_array->name), "%s", name);
#endif
}

void ucs_ptr_array_cleanup(ucs_ptr_array_t *ptr_array)
Expand All @@ -115,7 +113,7 @@ void ucs_ptr_array_cleanup(ucs_ptr_array_t *ptr_array)
ucs_ptr_array_clear(ptr_array);
}

static void ucs_ptr_array_grow(ucs_ptr_array_t *ptr_array UCS_MEMTRACK_ARG)
static void ucs_ptr_array_grow(ucs_ptr_array_t *ptr_array)
{
ucs_ptr_array_elem_t *new_array;
unsigned curr_size, new_size;
Expand All @@ -129,7 +127,8 @@ static void ucs_ptr_array_grow(ucs_ptr_array_t *ptr_array UCS_MEMTRACK_ARG)
}

/* Allocate new array */
new_array = ucs_malloc(new_size * sizeof(ucs_ptr_array_elem_t) UCS_MEMTRACK_VAL);
new_array = ucs_malloc(new_size * sizeof(ucs_ptr_array_elem_t),
ptr_array->name);
ucs_assert_always(new_array != NULL);
memcpy(new_array, ptr_array->start, curr_size * sizeof(ucs_ptr_array_elem_t));

Expand Down Expand Up @@ -168,7 +167,7 @@ unsigned ucs_ptr_array_insert(ucs_ptr_array_t *ptr_array, void *value,
ucs_assert_always(((uintptr_t)value & UCS_PTR_ARRAY_FLAG_FREE) == 0);

if (ptr_array->freelist == UCS_PTR_ARRAY_SENTINEL) {
ucs_ptr_array_grow(ptr_array UCS_MEMTRACK_NAME(ptr_array->name));
ucs_ptr_array_grow(ptr_array);
}

/* Get the first item on the free list */
Expand Down
6 changes: 2 additions & 4 deletions src/ucs/datastruct/ptr_array.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#define PTR_ARRAY_H_

#include <ucs/sys/math.h>
#include <ucs/debug/memtrack.h>
#include <ucs/debug/memtrack_int.h>


/*
Expand All @@ -35,9 +35,7 @@ typedef struct ucs_ptr_array {
ucs_ptr_array_elem_t *start;
unsigned freelist;
unsigned size;
#ifdef ENABLE_MEMTRACK
char name[64];
#endif
const char *name;
} ucs_ptr_array_t;


Expand Down
14 changes: 7 additions & 7 deletions src/ucs/datastruct/strided_alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include "queue.h"

#include <ucs/debug/log.h>
#include <ucs/debug/memtrack.h>
#include <ucs/debug/memtrack_int.h>
#include <ucs/sys/checker.h>
#include <ucs/sys/sys.h>

Expand All @@ -33,16 +33,16 @@ struct ucs_strided_alloc_elem {
};

static ucs_strided_alloc_chunk_t *
ucs_strided_alloc_chunk_alloc(ucs_strided_alloc_t *sa, size_t chunk_size
UCS_MEMTRACK_ARG)
ucs_strided_alloc_chunk_alloc(ucs_strided_alloc_t *sa, size_t chunk_size,
const char* alloc_name)
{
ucs_status_t status;
size_t size;
void *ptr;

size = chunk_size;
ptr = NULL;
status = ucs_mmap_alloc(&size, &ptr, 0 UCS_MEMTRACK_VAL);
status = ucs_mmap_alloc(&size, &ptr, 0, alloc_name);
if (status != UCS_OK) {
ucs_error("failed to allocate a chunk of %zu bytes", chunk_size);
return NULL;
Expand Down Expand Up @@ -76,7 +76,7 @@ static void ucs_strided_alloc_calc(ucs_strided_alloc_t *sa, size_t *chunk_size,
}

static ucs_status_t
ucs_strided_alloc_grow(ucs_strided_alloc_t *sa UCS_MEMTRACK_ARG)
ucs_strided_alloc_grow(ucs_strided_alloc_t *sa, const char* alloc_name)
{
size_t chunk_size, elems_per_chunk;
ucs_strided_alloc_chunk_t *chunk;
Expand All @@ -86,7 +86,7 @@ ucs_strided_alloc_grow(ucs_strided_alloc_t *sa UCS_MEMTRACK_ARG)

ucs_strided_alloc_calc(sa, &chunk_size, &elems_per_chunk);

chunk = ucs_strided_alloc_chunk_alloc(sa, chunk_size UCS_MEMTRACK_VAL);
chunk = ucs_strided_alloc_chunk_alloc(sa, chunk_size, alloc_name);
if (chunk == NULL) {
return UCS_ERR_NO_MEMORY;
}
Expand Down Expand Up @@ -146,7 +146,7 @@ void* ucs_strided_alloc_get(ucs_strided_alloc_t *sa, const char *alloc_name)
unsigned i;

if (sa->freelist == NULL) {
status = ucs_strided_alloc_grow(sa UCS_MEMTRACK_VAL);
status = ucs_strided_alloc_grow(sa, alloc_name);
if (status != UCS_OK) {
return NULL;
}
Expand Down
2 changes: 1 addition & 1 deletion src/ucs/datastruct/string_buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

#include <ucs/debug/assert.h>
#include <ucs/debug/log.h>
#include <ucs/debug/memtrack.h>
#include <ucs/debug/memtrack_int.h>
#include <ucs/sys/math.h>
#include <string.h>
#include <ctype.h>
Expand Down
2 changes: 1 addition & 1 deletion src/ucs/datastruct/string_set.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

#include <ucs/debug/assert.h>
#include <ucs/debug/log.h>
#include <ucs/debug/memtrack.h>
#include <ucs/debug/memtrack_int.h>


#define UCS_STRING_SET_ALLOC_NAME "string_set"
Expand Down
8 changes: 4 additions & 4 deletions src/ucs/debug/debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -382,8 +382,8 @@ ucs_status_t ucs_debug_backtrace_create(backtrace_h *bckt, int strip)
ucs_status_t status;

*bckt = NULL;
status = ucs_mmap_alloc(&size, (void**)bckt, 0
UCS_MEMTRACK_NAME("debug backtrace object"));
status = ucs_mmap_alloc(&size, (void**)bckt, 0,
"debug backtrace object");
if (status != UCS_OK) {
return status;
}
Expand Down Expand Up @@ -589,8 +589,8 @@ ucs_status_t ucs_debug_backtrace_create(backtrace_h *bckt, int strip)
ucs_status_t status;

*bckt = NULL;
status = ucs_mmap_alloc(&size, (void**)bckt, 0
UCS_MEMTRACK_NAME("debug backtrace object"));
status = ucs_mmap_alloc(&size, (void**)bckt, 0,
"debug backtrace object");
if (status != UCS_OK) {
return status;
}
Expand Down
Loading

0 comments on commit d8c5e65

Please sign in to comment.