Skip to content

Commit df6a4a3

Browse files
committed
memory: add component init hook function
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]>
1 parent 43fbd46 commit df6a4a3

File tree

5 files changed

+20
-4
lines changed

5 files changed

+20
-4
lines changed

ompi/runtime/ompi_mpi_init.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,15 +98,13 @@
9898
#endif
9999
#include "ompi/runtime/ompi_cr.h"
100100

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

111109
/* This is required for the boundaries of the hash tables used to store
112110
* the F90 types returned by the MPI_Type_create_f90_XXX functions.

opal/mca/memory/base/base.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,7 @@ BEGIN_C_DECLS
3232
*/
3333
OPAL_DECLSPEC extern mca_base_framework_t opal_memory_base_framework;
3434

35+
OPAL_DECLSPEC void opal_memory_base_malloc_init_hook (void);
36+
3537
END_C_DECLS
3638
#endif /* OPAL_BASE_MEMORY_H */

opal/mca/memory/base/memory_base_open.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,12 @@ static opal_memory_base_component_2_0_0_t empty_component = {
7070
opal_memory_base_component_2_0_0_t *opal_memory = &empty_component;
7171

7272

73+
void opal_memory_base_malloc_init_hook (void)
74+
{
75+
if (opal_memory->memoryc_init_hook) {
76+
opal_memory->memoryc_init_hook ();
77+
}
78+
}
7379

7480
/*
7581
* Function for finding and opening either all MCA components, or the one

opal/mca/memory/linux/memory_linux_component.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ opal_memory_linux_component_t mca_memory_linux_component = {
100100
/* Memory framework functions. These function pointer values
101101
are replaced by memory_linux_ummunotify.c at run time if we
102102
end up using ummunotify support. */
103+
.memoryc_init_hook = opal_memory_linux_malloc_init_hook,
103104
.memoryc_query = linux_query,
104105
.memoryc_register = opal_memory_base_component_register_empty,
105106
.memoryc_deregister = opal_memory_base_component_deregister_empty,

opal/mca/memory/memory.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,11 @@ typedef int (*opal_memory_base_component_deregister_fn_t)(void *base,
125125
typedef void (*opal_memory_base_component_set_alignment_fn_t)(int use_memalign,
126126
size_t memalign_threshold);
127127

128+
/**
129+
* Function to be called when initializing malloc hooks
130+
*/
131+
typedef void (*opal_memory_base_component_init_hook_fn_t)(void);
132+
128133
/**
129134
* Structure for memory components.
130135
*/
@@ -136,6 +141,10 @@ typedef struct opal_memory_base_component_2_0_0_t {
136141

137142
opal_memory_base_component_query_fn_t memoryc_query;
138143

144+
/** This function will be called when the malloc hooks are
145+
* initialized. It may be NULL if no hooks are needed. */
146+
opal_memory_base_component_init_hook_fn_t memoryc_init_hook;
147+
139148
/** Function to call when something has changed, as indicated by
140149
opal_memory_changed(). Will be ignored if the component does
141150
not provide an opal_memory_changed() macro that returns

0 commit comments

Comments
 (0)