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

Commit 8e9647f

Browse files
committed
Merge pull request #1079 from hjelmn/v2.x_mem_hooks
v2.x mem hook update
2 parents 1005306 + bac3362 commit 8e9647f

37 files changed

+2385
-42
lines changed

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ [email protected] Graham Fagg UTK
4343
[email protected] Gilles Gouaillardet RIST
4444
[email protected] Ginger Young LANL
4545
[email protected] Gleb Natapov Voltaire
46+
[email protected] Geoffrey Paulsen IBM
4647
[email protected] Galen Shipman LANL
4748
[email protected] Greg Watson LANL
4849
[email protected] Thomas Herault INRIA

config/opal_configure_options.m4

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,8 @@ else
302302
OPAL_ENABLE_DLOPEN_SUPPORT=1
303303
AC_MSG_RESULT([yes])
304304
fi
305-
305+
AC_DEFINE_UNQUOTED(OPAL_ENABLE_DLOPEN_SUPPORT, $OPAL_ENABLE_DLOPEN_SUPPORT,
306+
[Whether we want to enable dlopen support])
306307

307308
#
308309
# Heterogeneous support

contrib/platform/lanl/cray_xe6/debug-common

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
enable_dlopen=no
21
enable_mem_profile=no
32
enable_binaries=yes
43
enable_heterogeneous=no
@@ -33,8 +32,5 @@ enable_mca_direct=pml-ob1
3332
# enable development headers
3433
with_devel_headers=yes
3534

36-
# enable ptmalloc (enables lazy deregistration)
37-
with_memory_manager=linux
38-
3935
# disable valgrind
4036
with_valgrind=no

contrib/platform/lanl/cray_xe6/optimized-common

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
enable_dlopen=no
2-
31
enable_mem_profile=no
42
enable_binaries=yes
53

@@ -40,8 +38,5 @@ enable_mca_direct=pml-ob1
4038
# enable development headers
4139
with_devel_headers=yes
4240

43-
# enable ptmalloc (enables lazy deregistration)
44-
with_memory_manager=linux
45-
4641
# disable valgrind
4742
with_valgrind=no

contrib/platform/lanl/toss/toss-common

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# (c) 2013 Los Alamos National Security, LLC. All rights reserved.
22
# Open MPI common configuration for TOSS/TOSS2 v1.7.x/1.8.x
33

4-
enable_dlopen=no
54
enable_binaries=yes
65
enable_heterogeneous=no
76
enable_shared=yes

ompi/runtime/ompi_mpi_init.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,15 +93,13 @@
9393
#include "ompi/dpm/dpm.h"
9494
#include "ompi/mpiext/mpiext.h"
9595

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

106104
/* This is required for the boundaries of the hash tables used to store
107105
* 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: 67 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
* Copyright (c) 2009 Cisco Systems, Inc. All rights reserved.
1414
* Copyright (c) 2016 Research Organization for Information Science
1515
* and Technology (RIST). All rights reserved.
16+
* Copyright (c) 2016 Los Alamos National Security, LLC. All rights
17+
* reserved.
1618
* $COPYRIGHT$
1719
*
1820
* Additional copyrights may follow
@@ -43,20 +45,22 @@ static int empty_process(void)
4345
return OPAL_SUCCESS;
4446
}
4547

48+
static int empty_query (int *priority)
49+
{
50+
*priority = 0;
51+
return OPAL_SUCCESS;
52+
}
4653

4754
/*
4855
* Local variables
4956
*/
5057
static opal_memory_base_component_2_0_0_t empty_component = {
51-
/* Don't care about the version info */
52-
{ 0, },
53-
/* Don't care about the data */
54-
{ 0, },
5558
/* Empty / safe functions to call if no memory componet is selected */
56-
empty_process,
57-
opal_memory_base_component_register_empty,
58-
opal_memory_base_component_deregister_empty,
59-
opal_memory_base_component_set_alignment_empty,
59+
.memoryc_query = empty_query,
60+
.memoryc_process = empty_process,
61+
.memoryc_register = opal_memory_base_component_register_empty,
62+
.memoryc_deregister = opal_memory_base_component_deregister_empty,
63+
.memoryc_set_alignment = opal_memory_base_component_set_alignment_empty,
6064
};
6165

6266

@@ -65,31 +69,76 @@ static opal_memory_base_component_2_0_0_t empty_component = {
6569
*/
6670
opal_memory_base_component_2_0_0_t *opal_memory = &empty_component;
6771

72+
#if MEMORY_LINUX_PTMALLOC2
73+
/*
74+
* Note that this is a minor abstraction violation (that has actually
75+
* existed for quite a long time -- it used to be up in
76+
* ompi_mpi_init(); yoinks!): we're including a component's header
77+
* file here. This is an unfortunate necessity: the linux/ptmallox
78+
* system hooks in pre-main, and has to be initialized before any
79+
* component or module has even been created. Sad panda.
80+
*/
81+
#include "opal/mca/memory/linux/memory_linux.h"
82+
#endif
6883

84+
void opal_memory_base_malloc_init_hook (void)
85+
{
86+
#if MEMORY_LINUX_PTMALLOC2
87+
/* See above comment about linux/ptmalloc2 about why this
88+
abstraction violation is here. */
89+
opal_memory->memoryc_init_hook = opal_memory_linux_malloc_init_hook;
90+
#endif
91+
92+
if (opal_memory->memoryc_init_hook) {
93+
opal_memory->memoryc_init_hook ();
94+
}
95+
}
6996

7097
/*
7198
* Function for finding and opening either all MCA components, or the one
7299
* that was specifically requested via a MCA parameter.
73100
*/
74101
static int opal_memory_base_open(mca_base_open_flag_t flags)
75102
{
103+
mca_base_component_list_item_t *item, *next;
104+
opal_memory_base_component_2_0_0_t *tmp;
105+
int priority, highest_priority = 0;
76106
int ret;
77107

78-
/* Open up all available components */
108+
/* can only be zero or one */
109+
OPAL_LIST_FOREACH(item, &opal_memory_base_framework.framework_components, mca_base_component_list_item_t) {
110+
tmp = (opal_memory_base_component_2_0_0_t *) item->cli_component;
111+
112+
ret = tmp->memoryc_query (&priority);
113+
#if MEMORY_LINUX_PTMALLOC2
114+
/* See above comment about linux/ptmalloc2 about why this
115+
abstraction violation is here. */
116+
if (0 == strcmp (tmp->mca_component_name, "linux")) {
117+
/* if ptmalloc is enabled always use it */
118+
priority = 1000000;
119+
}
120+
#endif
121+
if (OPAL_SUCCESS != ret || priority < highest_priority) {
122+
continue;
123+
}
124+
125+
highest_priority = priority;
126+
opal_memory = tmp;
127+
}
128+
129+
OPAL_LIST_FOREACH_SAFE(item, next, &opal_memory_base_framework.framework_components, mca_base_component_list_item_t) {
130+
if ((void *) opal_memory != (void *) item->cli_component) {
131+
mca_base_component_unload (item->cli_component, opal_memory_base_framework.framework_output);
132+
opal_list_remove_item (&opal_memory_base_framework.framework_components, &item->super);
133+
}
134+
}
135+
136+
/* open remaining component */
79137
ret = mca_base_framework_components_open (&opal_memory_base_framework, flags);
80138
if (ret != OPAL_SUCCESS) {
81139
return ret;
82140
}
83141

84-
/* can only be zero or one */
85-
if (opal_list_get_size(&opal_memory_base_framework.framework_components) == 1) {
86-
mca_base_component_list_item_t *item;
87-
item = (mca_base_component_list_item_t*)
88-
opal_list_get_first(&opal_memory_base_framework.framework_components);
89-
opal_memory = (opal_memory_base_component_2_0_0_t*)
90-
item->cli_component;
91-
}
92-
93142
/* All done */
94143
return OPAL_SUCCESS;
95144
}

opal/mca/memory/linux/configure.m4

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,14 @@ AC_DEFUN([MCA_opal_memory_linux_CONFIG],[
5252
;;
5353
esac
5454

55+
# Must specifically request this component
5556
AS_IF([test "$with_memory_manager" = "linux"],
5657
[memory_linux_ptmalloc2_happy=yes
5758
memory_linux_ummu_happy=yes
5859
memory_linux_requested=1],
5960
[memory_linux_requested=0
60-
AS_IF([test -z "$with_memory_manager" || test "$with_memory_manager" = "yes"],
61-
[memory_linux_ptmalloc2_happy=yes
62-
memory_linux_ummu_happy=yes],
63-
[memory_linux_ptmalloc2_happy=no
64-
memory_linux_ummu_happy=no])])
65-
61+
memory_linux_ptmalloc2_happy=no
62+
memory_linux_ummu_happy=no])
6663

6764
######################################################################
6865
# if memory hook available

opal/mca/memory/linux/hooks.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -744,6 +744,10 @@ void opal_memory_linux_malloc_init_hook(void)
744744
check_result_t r1, lp, lpp;
745745
bool want_rcache = false, found_driver = false;
746746

747+
if (!opal_memory_linux_opened) {
748+
return;
749+
}
750+
747751
/* First, check for a FAKEROOT environment. If we're in a
748752
fakeroot, then access() (and likely others) have been replaced
749753
and are not safe to call here in this pre-main environment. So

opal/mca/memory/linux/memory_linux.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ OPAL_DECLSPEC void opal_memory_linux_malloc_init_hook(void);
8383
OPAL_DECLSPEC void opal_memory_linux_malloc_set_alignment(int use_memalign, size_t memalign_threshold);
8484
#endif /* MEMORY_LINUX_MALLOC_ALIGN_ENABLED */
8585

86+
extern bool opal_memory_linux_opened;
87+
8688
END_C_DECLS
8789

8890
#endif

opal/mca/memory/linux/memory_linux_component.c

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* Copyright (c) 2004-2005 The Regents of the University of California.
1212
* All rights reserved.
1313
* Copyright (c) 2009-2014 Cisco Systems, Inc. All rights reserved.
14-
* Copyright (c) 2013-2015 Los Alamos National Security, LLC. All rights
14+
* Copyright (c) 2013-2016 Los Alamos National Security, LLC. All rights
1515
* reserved.
1616
* Copyright (c) 2016 Research Organization for Information Science
1717
* and Technology (RIST). All rights reserved.
@@ -60,6 +60,7 @@
6060
static int linux_open(void);
6161
static int linux_close(void);
6262
static int linux_register(void);
63+
static int linux_query(int *);
6364

6465
#if MEMORY_LINUX_UMMUNOTIFY
6566
static bool ummunotify_opened = false;
@@ -69,6 +70,9 @@ static bool ptmalloc2_opened = false;
6970
#endif
7071

7172
bool opal_memory_linux_disable = false;
73+
static int mca_memory_linux_priority;
74+
75+
bool opal_memory_linux_opened = false;
7276

7377
opal_memory_linux_component_t mca_memory_linux_component = {
7478
/* First, the opal_memory_base_component_2_0_0_t */
@@ -96,6 +100,8 @@ opal_memory_linux_component_t mca_memory_linux_component = {
96100
/* Memory framework functions. These function pointer values
97101
are replaced by memory_linux_ummunotify.c at run time if we
98102
end up using ummunotify support. */
103+
.memoryc_init_hook = opal_memory_linux_malloc_init_hook,
104+
.memoryc_query = linux_query,
99105
.memoryc_register = opal_memory_base_component_register_empty,
100106
.memoryc_deregister = opal_memory_base_component_deregister_empty,
101107
#if MEMORY_LINUX_MALLOC_ALIGN_ENABLED
@@ -243,11 +249,25 @@ static int linux_register(void)
243249
if (0 > ret) {
244250
return ret;
245251
}
252+
253+
mca_memory_linux_priority = 50;
254+
ret = mca_base_component_var_register (&mca_memory_linux_component.super.memoryc_version,
255+
"priority", "Priority of the linux memory hook component",
256+
MCA_BASE_VAR_TYPE_INT, NULL, 0, 0, OPAL_INFO_LVL_5,
257+
MCA_BASE_VAR_SCOPE_CONSTANT, &mca_memory_linux_priority);
258+
if (0 > ret) {
259+
return ret;
260+
}
246261
#endif /* MEMORY_LINUX_MALLOC_ALIGN_ENABLED */
247262

248263
return (0 > ret) ? ret : OPAL_SUCCESS;
249264
}
250265

266+
static int linux_query (int *priority)
267+
{
268+
*priority = mca_memory_linux_priority;
269+
return OPAL_SUCCESS;
270+
}
251271

252272
static int linux_open(void)
253273
{
@@ -318,6 +338,7 @@ static int linux_open(void)
318338
__malloc_hook = _opal_memory_linux_malloc_align_hook;
319339
}
320340
#endif /* MEMORY_LINUX_MALLOC_ALIGN_ENABLED */
341+
opal_memory_linux_opened = true;
321342

322343
return OPAL_SUCCESS;
323344
}

opal/mca/memory/malloc_solaris/memory_malloc_solaris_component.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* All rights reserved.
1313
* Copyright (c) 2007-2011 Oracle and/or its affiliates. All rights reserved.
1414
* Copyright (c) 2009-2011 Cisco Systems, Inc. All rights reserved.
15-
* Copyright (c) 2015 Los Alamos National Security, LLC. All rights
15+
* Copyright (c) 2015-2016 Los Alamos National Security, LLC. All rights
1616
* reserved.
1717
* Copyright (c) 2016 Research Organization for Information Science
1818
* and Technology (RIST). All rights reserved.
@@ -46,6 +46,7 @@ int __munmap(caddr_t addr, size_t len);
4646
#endif
4747

4848
static int opal_memory_malloc_open(void);
49+
static int opal_memory_malloc_query(int *);
4950

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

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

98+
static int opal_memory_malloc_query (int *priority)
99+
{
100+
*priority = 79;
101+
return OPAL_SUCCESS;
102+
}
96103

97104
/*
98105
* Three ways to call munmap. Prefered is to call __munmap, which

0 commit comments

Comments
 (0)