Skip to content
This repository was archived by the owner on Sep 30, 2022. It is now read-only.

v2.x mem hook update #1079

Merged
merged 20 commits into from
Apr 26, 2016
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
8279755
opal/fifo: use atomics to set fifo head in opal_fifo_push
hjelmn Mar 17, 2016
5703574
opal/memory: add support for patch based memory hooks
hjelmn Mar 22, 2016
4b7cd1c
opal/memory: update component structure
hjelmn Mar 25, 2016
9abddc4
opal/patch: add call to check if binary patching is supported
hjelmn Mar 25, 2016
f307571
contrib/platform: don't disable dlopen
hjelmn Mar 28, 2016
78ddde2
opal: add code patcher framework
hjelmn Mar 29, 2016
75e6a25
memory/patcher: updates to memory hooks
hjelmn Apr 9, 2016
afd2dd4
memory/linux: force ptmalloc usage iff the linux mm is requested
hjelmn Apr 14, 2016
e2042d8
Trivial change to silence warning
Apr 14, 2016
37249cc
memory/patcher: fix coverity warning
hjelmn Apr 18, 2016
2bae7f0
memory/patcher: munmap hook could be called from within a malloc() im…
hjelmn Apr 18, 2016
72a9d51
patcher/linux: ensure component is only enabled on Linux
hjelmn Apr 19, 2016
9a8f1e0
patcher/linux: fix compiler warnings
hjelmn Apr 19, 2016
35d9105
patcher/overwrite: fix compile error on x86
hjelmn Apr 19, 2016
6c55bae
memory/patcher: do not hook madvise if the syscall doesn't exist
hjelmn Apr 20, 2016
19c1627
memory patcher: add some clarifying comments
jsquyres Apr 25, 2016
c407bb1
memory base: add comments explaining abstraction violations
jsquyres Apr 25, 2016
e1d70aa
Merge pull request #1 from jsquyres/hjelmn-v2.x_mem_hooks
hjelmn Apr 25, 2016
0292a87
Updated IBM Copyright message for contributions in memory patcher com…
gpaulsen Apr 25, 2016
bac3362
Missed one IBM Copyright message for contributions in memory patcher …
gpaulsen Apr 25, 2016
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
3 changes: 2 additions & 1 deletion config/opal_configure_options.m4
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,8 @@ else
OPAL_ENABLE_DLOPEN_SUPPORT=1
AC_MSG_RESULT([yes])
fi

AC_DEFINE_UNQUOTED(OPAL_ENABLE_DLOPEN_SUPPORT, $OPAL_ENABLE_DLOPEN_SUPPORT,
[Whether we want to enable dlopen support])

#
# Heterogeneous support
Expand Down
4 changes: 0 additions & 4 deletions contrib/platform/lanl/cray_xe6/debug-common
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
enable_dlopen=no
enable_mem_profile=no
enable_binaries=yes
enable_heterogeneous=no
Expand Down Expand Up @@ -33,8 +32,5 @@ enable_mca_direct=pml-ob1
# enable development headers
with_devel_headers=yes

# enable ptmalloc (enables lazy deregistration)
with_memory_manager=linux

# disable valgrind
with_valgrind=no
5 changes: 0 additions & 5 deletions contrib/platform/lanl/cray_xe6/optimized-common
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
enable_dlopen=no

enable_mem_profile=no
enable_binaries=yes

Expand Down Expand Up @@ -40,8 +38,5 @@ enable_mca_direct=pml-ob1
# enable development headers
with_devel_headers=yes

# enable ptmalloc (enables lazy deregistration)
with_memory_manager=linux

# disable valgrind
with_valgrind=no
1 change: 0 additions & 1 deletion contrib/platform/lanl/toss/toss-common
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# (c) 2013 Los Alamos National Security, LLC. All rights reserved.
# Open MPI common configuration for TOSS/TOSS2 v1.7.x/1.8.x

enable_dlopen=no
enable_binaries=yes
enable_heterogeneous=no
enable_shared=yes
Expand Down
6 changes: 2 additions & 4 deletions ompi/runtime/ompi_mpi_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,13 @@
#include "ompi/dpm/dpm.h"
#include "ompi/mpiext/mpiext.h"

#if defined(MEMORY_LINUX_PTMALLOC2) && MEMORY_LINUX_PTMALLOC2
#include "opal/mca/memory/linux/memory_linux.h"
#include "opal/mca/memory/base/base.h"
/* So this sucks, but with OPAL in its own library that is brought in
implicity from libmpi, there are times when the malloc initialize
hook in the memory component doesn't work. So we have to do it
from here, since any MPI code is going to call MPI_Init... */
OPAL_DECLSPEC void (*__malloc_initialize_hook) (void) =
opal_memory_linux_malloc_init_hook;
#endif /* defined(MEMORY_LINUX_PTMALLOC2) && MEMORY_LINUX_PTMALLOC2 */
opal_memory_base_malloc_init_hook;

/* This is required for the boundaries of the hash tables used to store
* the F90 types returned by the MPI_Type_create_f90_XXX functions.
Expand Down
5 changes: 3 additions & 2 deletions opal/class/opal_fifo.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* All rights reserved.
* Copyright (c) 2007 Voltaire All rights reserved.
* Copyright (c) 2010 IBM Corporation. All rights reserved.
* Copyright (c) 2014-2015 Los Alamos National Security, LLC. All rights
* Copyright (c) 2014-2016 Los Alamos National Security, LLC. All rights
* reseved.
* $COPYRIGHT$
*
Expand Down Expand Up @@ -101,7 +101,8 @@ static inline opal_list_item_t *opal_fifo_push_atomic (opal_fifo_t *fifo,

if (&fifo->opal_fifo_ghost == tail.data.item) {
/* update the head */
fifo->opal_fifo_head.data.item = item;
opal_counted_pointer_t head = {.value = fifo->opal_fifo_head.value};
opal_update_counted_pointer (&fifo->opal_fifo_head, head, item);
} else {
/* update previous item */
tail.data.item->opal_list_next = item;
Expand Down
2 changes: 2 additions & 0 deletions opal/mca/memory/base/base.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,7 @@ BEGIN_C_DECLS
*/
OPAL_DECLSPEC extern mca_base_framework_t opal_memory_base_framework;

OPAL_DECLSPEC void opal_memory_base_malloc_init_hook (void);

END_C_DECLS
#endif /* OPAL_BASE_MEMORY_H */
73 changes: 55 additions & 18 deletions opal/mca/memory/base/memory_base_open.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
* Copyright (c) 2009 Cisco Systems, Inc. All rights reserved.
* Copyright (c) 2016 Research Organization for Information Science
* and Technology (RIST). All rights reserved.
* Copyright (c) 2016 Los Alamos National Security, LLC. All rights
* reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
Expand Down Expand Up @@ -43,20 +45,22 @@ static int empty_process(void)
return OPAL_SUCCESS;
}

static int empty_query (int *priority)
{
*priority = 0;
return OPAL_SUCCESS;
}

/*
* Local variables
*/
static opal_memory_base_component_2_0_0_t empty_component = {
/* Don't care about the version info */
{ 0, },
/* Don't care about the data */
{ 0, },
/* Empty / safe functions to call if no memory componet is selected */
empty_process,
opal_memory_base_component_register_empty,
opal_memory_base_component_deregister_empty,
opal_memory_base_component_set_alignment_empty,
.memoryc_query = empty_query,
.memoryc_process = empty_process,
.memoryc_register = opal_memory_base_component_register_empty,
.memoryc_deregister = opal_memory_base_component_deregister_empty,
.memoryc_set_alignment = opal_memory_base_component_set_alignment_empty,
};


Expand All @@ -65,31 +69,64 @@ static opal_memory_base_component_2_0_0_t empty_component = {
*/
opal_memory_base_component_2_0_0_t *opal_memory = &empty_component;

#if MEMORY_LINUX_PTMALLOC2
#include "opal/mca/memory/linux/memory_linux.h"
#endif

void opal_memory_base_malloc_init_hook (void)
{
#if MEMORY_LINUX_PTMALLOC2
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find it a bit weird to have #if's for specific components in the base... is this really necessary?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better than the #if being in ompi_mpi_init.c ;)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess I don't understand why they are needed at all...? Can't these callbacks be done in a way that doesn't break abstractions?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hjelmn Tells me that there's no component selected at this point. Grumble. Well, it's not a regression, so I guess we'll let this go for v2.0.0...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would call it a partial fix for the abstraction break. Now there is no check for ptmalloc2 in ompi_mpi_init.c.

opal_memory->memoryc_init_hook = opal_memory_linux_malloc_init_hook;
#endif

if (opal_memory->memoryc_init_hook) {
opal_memory->memoryc_init_hook ();
}
}

/*
* Function for finding and opening either all MCA components, or the one
* that was specifically requested via a MCA parameter.
*/
static int opal_memory_base_open(mca_base_open_flag_t flags)
{
mca_base_component_list_item_t *item, *next;
opal_memory_base_component_2_0_0_t *tmp;
int priority, highest_priority = 0;
int ret;

/* Open up all available components */
/* can only be zero or one */
OPAL_LIST_FOREACH(item, &opal_memory_base_framework.framework_components, mca_base_component_list_item_t) {
tmp = (opal_memory_base_component_2_0_0_t *) item->cli_component;

ret = tmp->memoryc_query (&priority);
#if MEMORY_LINUX_PTMALLOC2
if (0 == strcmp (tmp->mca_component_name, "linux")) {
/* if ptmalloc is enabled always use it */
priority = 1000000;
}
#endif
if (OPAL_SUCCESS != ret || priority < highest_priority) {
continue;
}

highest_priority = priority;
opal_memory = tmp;
}

OPAL_LIST_FOREACH_SAFE(item, next, &opal_memory_base_framework.framework_components, mca_base_component_list_item_t) {
if ((void *) opal_memory != (void *) item->cli_component) {
mca_base_component_unload (item->cli_component, opal_memory_base_framework.framework_output);
opal_list_remove_item (&opal_memory_base_framework.framework_components, &item->super);
}
}

/* open remaining component */
ret = mca_base_framework_components_open (&opal_memory_base_framework, flags);
if (ret != OPAL_SUCCESS) {
return ret;
}

/* can only be zero or one */
if (opal_list_get_size(&opal_memory_base_framework.framework_components) == 1) {
mca_base_component_list_item_t *item;
item = (mca_base_component_list_item_t*)
opal_list_get_first(&opal_memory_base_framework.framework_components);
opal_memory = (opal_memory_base_component_2_0_0_t*)
item->cli_component;
}

/* All done */
return OPAL_SUCCESS;
}
Expand Down
9 changes: 3 additions & 6 deletions opal/mca/memory/linux/configure.m4
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,14 @@ AC_DEFUN([MCA_opal_memory_linux_CONFIG],[
;;
esac

# Must specifically request this component
AS_IF([test "$with_memory_manager" = "linux"],
[memory_linux_ptmalloc2_happy=yes
memory_linux_ummu_happy=yes
memory_linux_requested=1],
[memory_linux_requested=0
AS_IF([test -z "$with_memory_manager" || test "$with_memory_manager" = "yes"],
[memory_linux_ptmalloc2_happy=yes
memory_linux_ummu_happy=yes],
[memory_linux_ptmalloc2_happy=no
memory_linux_ummu_happy=no])])

memory_linux_ptmalloc2_happy=no
memory_linux_ummu_happy=no])

######################################################################
# if memory hook available
Expand Down
4 changes: 4 additions & 0 deletions opal/mca/memory/linux/hooks.c
Original file line number Diff line number Diff line change
Expand Up @@ -744,6 +744,10 @@ void opal_memory_linux_malloc_init_hook(void)
check_result_t r1, lp, lpp;
bool want_rcache = false, found_driver = false;

if (!opal_memory_linux_opened) {
return;
}

/* First, check for a FAKEROOT environment. If we're in a
fakeroot, then access() (and likely others) have been replaced
and are not safe to call here in this pre-main environment. So
Expand Down
2 changes: 2 additions & 0 deletions opal/mca/memory/linux/memory_linux.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ OPAL_DECLSPEC void opal_memory_linux_malloc_init_hook(void);
OPAL_DECLSPEC void opal_memory_linux_malloc_set_alignment(int use_memalign, size_t memalign_threshold);
#endif /* MEMORY_LINUX_MALLOC_ALIGN_ENABLED */

extern bool opal_memory_linux_opened;

END_C_DECLS

#endif
23 changes: 22 additions & 1 deletion opal/mca/memory/linux/memory_linux_component.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* Copyright (c) 2004-2005 The Regents of the University of California.
* All rights reserved.
* Copyright (c) 2009-2014 Cisco Systems, Inc. All rights reserved.
* Copyright (c) 2013-2015 Los Alamos National Security, LLC. All rights
* Copyright (c) 2013-2016 Los Alamos National Security, LLC. All rights
* reserved.
* Copyright (c) 2016 Research Organization for Information Science
* and Technology (RIST). All rights reserved.
Expand Down Expand Up @@ -60,6 +60,7 @@
static int linux_open(void);
static int linux_close(void);
static int linux_register(void);
static int linux_query(int *);

#if MEMORY_LINUX_UMMUNOTIFY
static bool ummunotify_opened = false;
Expand All @@ -69,6 +70,9 @@ static bool ptmalloc2_opened = false;
#endif

bool opal_memory_linux_disable = false;
static int mca_memory_linux_priority;

bool opal_memory_linux_opened = false;

opal_memory_linux_component_t mca_memory_linux_component = {
/* First, the opal_memory_base_component_2_0_0_t */
Expand Down Expand Up @@ -96,6 +100,8 @@ opal_memory_linux_component_t mca_memory_linux_component = {
/* Memory framework functions. These function pointer values
are replaced by memory_linux_ummunotify.c at run time if we
end up using ummunotify support. */
.memoryc_init_hook = opal_memory_linux_malloc_init_hook,
.memoryc_query = linux_query,
.memoryc_register = opal_memory_base_component_register_empty,
.memoryc_deregister = opal_memory_base_component_deregister_empty,
#if MEMORY_LINUX_MALLOC_ALIGN_ENABLED
Expand Down Expand Up @@ -243,11 +249,25 @@ static int linux_register(void)
if (0 > ret) {
return ret;
}

mca_memory_linux_priority = 50;
ret = mca_base_component_var_register (&mca_memory_linux_component.super.memoryc_version,
"priority", "Priority of the linux memory hook component",
MCA_BASE_VAR_TYPE_INT, NULL, 0, 0, OPAL_INFO_LVL_5,
MCA_BASE_VAR_SCOPE_CONSTANT, &mca_memory_linux_priority);
if (0 > ret) {
return ret;
}
#endif /* MEMORY_LINUX_MALLOC_ALIGN_ENABLED */

return (0 > ret) ? ret : OPAL_SUCCESS;
}

static int linux_query (int *priority)
{
*priority = mca_memory_linux_priority;
return OPAL_SUCCESS;
}

static int linux_open(void)
{
Expand Down Expand Up @@ -318,6 +338,7 @@ static int linux_open(void)
__malloc_hook = _opal_memory_linux_malloc_align_hook;
}
#endif /* MEMORY_LINUX_MALLOC_ALIGN_ENABLED */
opal_memory_linux_opened = true;

return OPAL_SUCCESS;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* All rights reserved.
* Copyright (c) 2007-2011 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2009-2011 Cisco Systems, Inc. All rights reserved.
* Copyright (c) 2015 Los Alamos National Security, LLC. All rights
* Copyright (c) 2015-2016 Los Alamos National Security, LLC. All rights
* reserved.
* Copyright (c) 2016 Research Organization for Information Science
* and Technology (RIST). All rights reserved.
Expand Down Expand Up @@ -46,6 +46,7 @@ int __munmap(caddr_t addr, size_t len);
#endif

static int opal_memory_malloc_open(void);
static int opal_memory_malloc_query(int *);

const opal_memory_base_component_2_0_0_t mca_memory_malloc_solaris_component = {
/* First, the mca_component_t struct containing meta information
Expand All @@ -68,6 +69,7 @@ const opal_memory_base_component_2_0_0_t mca_memory_malloc_solaris_component = {

/* This component doesn't need these functions, but need to
provide safe/empty register/deregister functions to call */
.memoryc_query = opal_memory_malloc_query,
.memoryc_register = opal_memory_base_component_register_empty,
.memoryc_deregister = opal_memory_base_component_deregister_empty,
.memoryc_set_alignment = opal_memory_base_component_set_alignment_empty,
Expand All @@ -93,6 +95,11 @@ opal_memory_malloc_open(void)
return OPAL_SUCCESS;
}

static int opal_memory_malloc_query (int *priority)
{
*priority = 79;
return OPAL_SUCCESS;
}

/*
* Three ways to call munmap. Prefered is to call __munmap, which
Expand Down
Loading