Skip to content

Commit

Permalink
memory: add component init hook function
Browse files Browse the repository at this point in the history
This commit fixes a long-standing break in the abstration of the
memory components. ompi_mpi_init.c was referencing the linux malloc
hook initilize function to ensure the hooks are initialized for
libmpi.so. The abstraction break has been fixed by adding a memory
base function that calls the open memory component's malloc hook init
function if it has one.

Signed-off-by: Nathan Hjelm <[email protected]>
  • Loading branch information
hjelmn committed Mar 28, 2016
1 parent bac1548 commit d6f45ab
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 4 deletions.
6 changes: 2 additions & 4 deletions ompi/runtime/ompi_mpi_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,13 @@
#endif
#include "ompi/runtime/ompi_cr.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
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 */
6 changes: 6 additions & 0 deletions opal/mca/memory/base/memory_base_open.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ static opal_memory_base_component_2_0_0_t empty_component = {
opal_memory_base_component_2_0_0_t *opal_memory = &empty_component;


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

/*
* Function for finding and opening either all MCA components, or the one
Expand Down
1 change: 1 addition & 0 deletions opal/mca/memory/linux/memory_linux_component.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ 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,
Expand Down
9 changes: 9 additions & 0 deletions opal/mca/memory/memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,11 @@ typedef int (*opal_memory_base_component_deregister_fn_t)(void *base,
typedef void (*opal_memory_base_component_set_alignment_fn_t)(int use_memalign,
size_t memalign_threshold);

/**
* Function to be called when initializing malloc hooks
*/
typedef void (*opal_memory_base_component_init_hook_fn_t)(void);

/**
* Structure for memory components.
*/
Expand All @@ -136,6 +141,10 @@ typedef struct opal_memory_base_component_2_0_0_t {

opal_memory_base_component_query_fn_t memoryc_query;

/** This function will be called when the malloc hooks are
* initialized. It may be NULL if no hooks are needed. */
opal_memory_base_component_init_hook_fn_t memoryc_init_hook;

/** Function to call when something has changed, as indicated by
opal_memory_changed(). Will be ignored if the component does
not provide an opal_memory_changed() macro that returns
Expand Down

0 comments on commit d6f45ab

Please sign in to comment.