Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ Peter Rudenko <peterr@mellanox.com>
Peter-Jan Gootzen <pgootzen@nvidia.com>
Qiang Yu <Qiang.Yu@amd.com>
Raul Akhmetshin <rakhmetshin@nvidia.com>
Rikka Göring <rikka.goering@outlook.de>
Robert Dietrich <rdietrich@nvidia.com>
Rohit Zambre <rzambre@uci.edu>
Roie Danino <rdanino@nvidia.com>
Expand Down
9 changes: 8 additions & 1 deletion config/m4/ucm.m4
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#
# Memory allocator selection
#
AC_CHECK_FUNCS([brk sbrk])

AC_ARG_WITH([allocator],
[AS_HELP_STRING([--with-allocator=NAME],
[Build UCX with predefined memory allocator. The supported values are:
Expand All @@ -18,13 +20,18 @@ AC_ARG_WITH([allocator],
case ${with_allocator} in
ptmalloc286)
AC_MSG_NOTICE(Memory allocator is ptmalloc-2.8.6 version)
AC_DEFINE([HAVE_UCM_PTMALLOC286], 1, [Use ptmalloc-2.8.6 version])
AC_DEFINE([HAVE_UCM_PTMALLOC286], [1], [Use ptmalloc-2.8.6 version])
HAVE_UCM_PTMALLOC286=yes
AS_IF([test "x$ac_cv_func_sbrk" != xyes], [
AC_DEFINE([HAVE_MORECORE], [0],
[Disable MORECORE in ptmalloc (no sbrk available)])
])
;;
*)
AC_MSG_ERROR(Cannot continue. Unsupported memory allocator name
in --with-allocator=[$with_allocator])
;;

esac

AM_CONDITIONAL([HAVE_UCM_PTMALLOC286],[test "x$HAVE_UCM_PTMALLOC286" = "xyes"])
Expand Down
18 changes: 18 additions & 0 deletions src/ucm/malloc/malloc_hook.c
Original file line number Diff line number Diff line change
Expand Up @@ -836,11 +836,29 @@ ucs_status_t ucm_malloc_install(int events)
#endif
}

#if !HAVE_BRK
if (events & UCM_EVENT_BRK) {
ucm_debug("brk event requested, but brk() is not available");
events &= ~UCM_EVENT_BRK;
}
#endif

#if !HAVE_SBRK
if (events & UCM_EVENT_SBRK) {
ucm_debug("sbrk event requested, but sbrk() is not available");
events &= ~UCM_EVENT_SBRK;
}
#endif

#if HAVE_SBRK
if (!(ucm_malloc_hook_state.install_state & UCM_MALLOC_INSTALLED_SBRK_EVH)) {
ucm_debug("installing malloc-sbrk event handler");
ucm_event_handler_add(&sbrk_handler);
ucm_malloc_hook_state.install_state |= UCM_MALLOC_INSTALLED_SBRK_EVH;
}
#else
(void)sbrk_handler;
#endif

/* When running on valgrind, don't even try malloc hooks.
* We want to release original blocks to silence the leak check, so we must
Expand Down
8 changes: 8 additions & 0 deletions src/ucm/mmap/install.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,12 @@ static ucm_mmap_func_t ucm_mmap_funcs[] = {
#endif
{ UCM_MMAP_RELOC_ENTRY(shmat), UCM_EVENT_SHMAT, UCM_EVENT_NONE},
{ UCM_MMAP_RELOC_ENTRY(shmdt), UCM_EVENT_SHMDT, UCM_EVENT_SHMAT},
#if HAVE_SBRK
{ UCM_MMAP_RELOC_ENTRY(sbrk), UCM_EVENT_SBRK, UCM_EVENT_NONE},
#endif
#if HAVE_BRK
{ UCM_MMAP_RELOC_ENTRY(brk), UCM_EVENT_BRK, UCM_EVENT_NONE},
#endif
{ UCM_MMAP_RELOC_ENTRY(madvise), UCM_EVENT_MADVISE, UCM_EVENT_NONE},
{ {NULL, NULL, NULL}, UCM_EVENT_NONE}
};
Expand Down Expand Up @@ -138,10 +142,12 @@ static void ucm_mmap_event_test_callback(ucm_event_type_t event_type,
/* Call brk() and check return value, to avoid compile error of unused result */
static void ucm_brk_checked(void *addr)
{
#if HAVE_BRK
int ret = brk(addr);
if ((ret != 0) && (addr != NULL)) {
ucm_diag("brk(addr=%p) failed: %m", addr);
}
#endif
}

/* Fire events with pre/post action. The problem is in call sequence: we
Expand Down Expand Up @@ -199,6 +205,7 @@ ucm_fire_mmap_events_internal(int events, ucm_mmap_test_events_data_t *data,
}

if (exclusive && !RUNNING_ON_VALGRIND) {
#if HAVE_SBRK
sbrk_size = ucm_get_page_size();
if (events & (UCM_EVENT_BRK|UCM_EVENT_VM_MAPPED|UCM_EVENT_VM_UNMAPPED)) {
p = ucm_get_current_brk();
Expand All @@ -213,6 +220,7 @@ ucm_fire_mmap_events_internal(int events, ucm_mmap_test_events_data_t *data,
UCM_FIRE_EVENT(events, UCM_EVENT_SBRK|UCM_EVENT_VM_UNMAPPED,
data, (void)sbrk(-sbrk_size));
}
#endif
} else {
/* To avoid side effects on other threads and valgrind heap corruption,
* pass invalid parameters. We assume that if the natives events are
Expand Down
8 changes: 8 additions & 0 deletions src/ucm/util/replace.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,12 @@ UCM_DEFINE_REPLACE_FUNC(mremap, void*, MAP_FAILED, void*, size_t, size_t, int,
#endif
UCM_DEFINE_REPLACE_FUNC(shmat, void*, MAP_FAILED, int, const void*, int)
UCM_DEFINE_REPLACE_FUNC(shmdt, int, -1, const void*)
#if HAVE_SBRK
UCM_DEFINE_REPLACE_FUNC(sbrk, void*, MAP_FAILED, intptr_t)
#endif
#if HAVE_BRK
UCM_DEFINE_REPLACE_FUNC(brk, int, -1, void*)
#endif
UCM_DEFINE_REPLACE_FUNC(madvise, int, -1, void*, size_t, int)

UCM_DEFINE_SELECT_FUNC(mmap, void*, SYS_mmap, void*, size_t, int, int, int,
Expand Down Expand Up @@ -122,7 +126,9 @@ int ucm_orig_shmdt(const void *shmaddr)

#endif

#if HAVE_BRK
_UCM_DEFINE_DLSYM_FUNC(brk, ucm_orig_dlsym_brk, ucm_override_brk, int, void*)
#endif

int ucm_orig_brk(void *addr)
{
Expand All @@ -141,8 +147,10 @@ int ucm_orig_brk(void *addr)
}
}

#if HAVE_SBRK
_UCM_DEFINE_DLSYM_FUNC(sbrk, ucm_orig_dlsym_sbrk, ucm_override_sbrk, void*,
intptr_t)
#endif

void *ucm_orig_sbrk(intptr_t increment)
{
Expand Down
6 changes: 6 additions & 0 deletions src/ucm/util/sys.c
Original file line number Diff line number Diff line change
Expand Up @@ -377,10 +377,16 @@ char *ucm_concat_path(char *buffer, size_t max, const char *dir, const char *fil

void *ucm_brk_syscall(void *addr)
{
#if HAVE_DECL_SYS_BRK
/* Return type is equivalent to full pointer size */
UCS_STATIC_ASSERT(sizeof(syscall(0)) == sizeof(void*));

return (void*)syscall(SYS_brk, addr);
#else
(void)addr;
errno = ENOSYS;
return NULL;
#endif
}

pid_t ucm_get_tid()
Expand Down
Loading