Skip to content

Commit

Permalink
UCS/MEMTRACK: added public API for memtrach:
Browse files Browse the repository at this point in the history
- routines ucs_memtrack_allocated and ucs_memtrack_releasing moved
  to public header
- added internal memtrack header
- memtrack configure option is removed, memtrack
  now is always built-in
- removed --enable-memtrack params
  • Loading branch information
Sergey Oblomov committed Jul 2, 2021
1 parent 06a9bfe commit 1fd6922
Show file tree
Hide file tree
Showing 71 changed files with 243 additions and 266 deletions.
2 changes: 1 addition & 1 deletion bindings/java/src/main/native/jucx_common_def.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#include <ucp/api/ucp.h>
#include <ucs/debug/log.h>
#include <ucs/debug/memtrack.h>
#include <ucs/debug/memtrack_int.h>
#include <ucs/profile/profile.h>
#include <ucs/type/spinlock.h>

Expand Down
1 change: 0 additions & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,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 @@ -29,7 +29,7 @@
#include <ucp/rma/rma.h>

#include <ucs/datastruct/queue.h>
#include <ucs/debug/memtrack.h>
#include <ucs/debug/memtrack_int.h>
#include <ucs/debug/log.h>
#include <ucs/debug/debug_int.h>
#include <ucs/sys/string.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 @@ -45,6 +45,7 @@ nobase_dist_libucs_la_HEADERS = \
datastruct/string_set.h \
debug/log_def.h \
debug/debug.h \
debug/memtrack.h \
memory/rcache.h \
memory/memory_type.h \
memory/memtype_cache.h \
Expand Down Expand Up @@ -99,7 +100,7 @@ noinst_HEADERS = \
debug/assert.h \
debug/debug_int.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 @@ -219,7 +219,6 @@ static ucs_config_field_t ucs_global_opts_table[] = {
ucs_offsetof(ucs_global_opts_t, vfs_thread_affinity),
UCS_CONFIG_TYPE_BOOL},

#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 @@ -232,7 +231,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
18 changes: 0 additions & 18 deletions src/ucs/configure.m4
Original file line number Diff line number Diff line change
Expand Up @@ -119,24 +119,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
2 changes: 1 addition & 1 deletion src/ucs/datastruct/array.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

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


/* Increase the array buffer length by this factor, whenever it needs to grow */
Expand Down
2 changes: 1 addition & 1 deletion src/ucs/datastruct/conn_match.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

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


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
23 changes: 11 additions & 12 deletions src/ucs/datastruct/ptr_array.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,18 +107,17 @@ static void UCS_F_MAYBE_UNUSED ucs_ptr_array_dump(ucs_ptr_array_t *ptr_array)

static void ucs_ptr_array_clear(ucs_ptr_array_t *ptr_array)
{
ptr_array->start = NULL;
ptr_array->size = 0;
ptr_array->count = 0;
ptr_array->freelist = UCS_PTR_ARRAY_SENTINEL;
ptr_array->start = NULL;
ptr_array->size = 0;
ptr_array->count = 0;
ptr_array->freelist = UCS_PTR_ARRAY_SENTINEL;
ptr_array->name = NULL;
}

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

void ucs_ptr_array_cleanup(ucs_ptr_array_t *ptr_array)
Expand All @@ -139,14 +138,14 @@ 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, unsigned new_size
UCS_MEMTRACK_ARG)
static void ucs_ptr_array_grow(ucs_ptr_array_t *ptr_array, unsigned new_size)
{
ucs_ptr_array_elem_t *new_array;
unsigned curr_size, i, next;

/* 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);
curr_size = ptr_array->size;
memcpy(new_array, ptr_array->start, curr_size * sizeof(ucs_ptr_array_elem_t));
Expand Down Expand Up @@ -185,7 +184,7 @@ unsigned ucs_ptr_array_insert(ucs_ptr_array_t *ptr_array, void *value)

if (ptr_array->freelist == UCS_PTR_ARRAY_SENTINEL) {
new_size = ucs_max(UCS_PTR_ARRAY_INITIAL_SIZE, ptr_array->size * 2);
ucs_ptr_array_grow(ptr_array, new_size UCS_MEMTRACK_NAME(ptr_array->name));
ucs_ptr_array_grow(ptr_array, new_size);
}

/* Get the first item on the free list */
Expand All @@ -211,7 +210,7 @@ void ucs_ptr_array_set(ucs_ptr_array_t *ptr_array, unsigned element_index,

if (ucs_unlikely(element_index >= ptr_array->size)) {
new_size = ucs_max(ptr_array->size * 2, element_index + 1);
ucs_ptr_array_grow(ptr_array, new_size UCS_MEMTRACK_NAME(ptr_array->name));
ucs_ptr_array_grow(ptr_array, new_size);
} else if (!__ucs_ptr_array_is_free(ptr_array->start[element_index])) {
ptr_array->start[element_index] = (uintptr_t)new_val;
return;
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 @@ -9,7 +9,7 @@
#define PTR_ARRAY_H_

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

Expand Down Expand Up @@ -68,9 +68,7 @@ typedef struct ucs_ptr_array {
unsigned freelist; /* Index of first free slot (see above) */
unsigned size; /* Number of allocated array slots */
unsigned count; /* Actual number of occupied slots */
#ifdef ENABLE_MEMTRACK
char name[64]; /* Name of this pointer array */
#endif
const char *name; /* Name of this pointer array */
} 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/string.h>
#include <ucs/sys/math.h>
#include <string.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
6 changes: 2 additions & 4 deletions src/ucs/debug/debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -382,8 +382,7 @@ 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 +588,7 @@ 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 1fd6922

Please sign in to comment.