Skip to content

Commit c2b6fbb

Browse files
committed
opal/memory: move initialization to first rcache creation
Because of the removal of the linux memory component it is no longer necessary to initialize the memory component in opal_init(). This commit moves the initialization to the creation of the first rcache component. Signed-off-by: Nathan Hjelm <hjelmn@lanl.gov>
1 parent 80ec79c commit c2b6fbb

File tree

8 files changed

+57
-100
lines changed

8 files changed

+57
-100
lines changed

opal/mca/btl/openib/btl_openib_component.c

Lines changed: 16 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2557,39 +2557,6 @@ btl_openib_component_init(int *num_btl_modules,
25572557
goto no_btls;
25582558
}
25592559

2560-
/* If we are using ptmalloc2 and there are no posix threads
2561-
available, this will cause memory corruption. Refuse to run.
2562-
Right now, ptmalloc2 is the only memory manager that we have on
2563-
OS's that support OpenFabrics that provide both FREE and MUNMAP
2564-
support, so the following test is [currently] good enough... */
2565-
value = opal_mem_hooks_support_level();
2566-
2567-
/* If we have a memory manager available, and
2568-
opal_leave_pinned==-1, then unless the user explicitly set
2569-
opal_leave_pinned_pipeline==0, then set opal_leave_pinned to 1.
2570-
2571-
We have a memory manager if we have both FREE and MUNMAP
2572-
support */
2573-
if ((OPAL_MEMORY_FREE_SUPPORT | OPAL_MEMORY_MUNMAP_SUPPORT) ==
2574-
((OPAL_MEMORY_FREE_SUPPORT | OPAL_MEMORY_MUNMAP_SUPPORT) & value)) {
2575-
if (0 == opal_leave_pinned_pipeline &&
2576-
-1 == opal_leave_pinned) {
2577-
opal_leave_pinned = 1;
2578-
}
2579-
} else {
2580-
opal_leave_pinned = 0;
2581-
opal_leave_pinned_pipeline = 0;
2582-
}
2583-
2584-
#if OPAL_CUDA_SUPPORT
2585-
if (mca_btl_openib_component.cuda_want_gdr && (0 == opal_leave_pinned)) {
2586-
opal_show_help("help-mpi-btl-openib.txt",
2587-
"CUDA_gdr_and_nopinned", true,
2588-
opal_process_info.nodename);
2589-
goto no_btls;
2590-
}
2591-
#endif /* OPAL_CUDA_SUPPORT */
2592-
25932560
index = mca_base_var_find("ompi", "btl", "openib", "max_inline_data");
25942561
if (index >= 0) {
25952562
if (OPAL_SUCCESS == mca_base_var_get_value(index, NULL, &source, NULL)) {
@@ -2926,6 +2893,22 @@ btl_openib_component_init(int *num_btl_modules,
29262893
mca_btl_openib_component.if_exclude_list = NULL;
29272894
}
29282895

2896+
/* If we are using ptmalloc2 and there are no posix threads
2897+
available, this will cause memory corruption. Refuse to run.
2898+
Right now, ptmalloc2 is the only memory manager that we have on
2899+
OS's that support OpenFabrics that provide both FREE and MUNMAP
2900+
support, so the following test is [currently] good enough... */
2901+
value = opal_mem_hooks_support_level();
2902+
2903+
#if OPAL_CUDA_SUPPORT
2904+
if (mca_btl_openib_component.cuda_want_gdr && (0 == opal_leave_pinned)) {
2905+
opal_show_help("help-mpi-btl-openib.txt",
2906+
"CUDA_gdr_and_nopinned", true,
2907+
opal_process_info.nodename);
2908+
goto no_btls;
2909+
}
2910+
#endif /* OPAL_CUDA_SUPPORT */
2911+
29292912
mca_btl_openib_component.memory_registration_verbose = opal_output_open(NULL);
29302913
opal_output_set_verbosity (mca_btl_openib_component.memory_registration_verbose,
29312914
mca_btl_openib_component.memory_registration_verbose_level);

opal/mca/btl/ugni/btl_ugni_component.c

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -331,26 +331,6 @@ btl_ugni_component_close(void)
331331
return OPAL_SUCCESS;
332332
}
333333

334-
static void mca_btl_ugni_autoset_leave_pinned (void) {
335-
if (MCA_BTL_UGNI_RCACHE_UDREG != mca_btl_ugni_component.rcache_type) {
336-
int value = opal_mem_hooks_support_level();
337-
if ((OPAL_MEMORY_FREE_SUPPORT | OPAL_MEMORY_MUNMAP_SUPPORT) ==
338-
((OPAL_MEMORY_FREE_SUPPORT | OPAL_MEMORY_MUNMAP_SUPPORT) & value)) {
339-
/* Set leave pinned to 1 if leave pinned pipeline is not set */
340-
if (-1 == opal_leave_pinned) {
341-
opal_leave_pinned = !opal_leave_pinned_pipeline;
342-
}
343-
} else {
344-
opal_leave_pinned = 0;
345-
opal_leave_pinned_pipeline = 0;
346-
}
347-
} else if (-1 == opal_leave_pinned) {
348-
/* if udreg is in use we can set leave pinned without checking for the
349-
* memory hooks. */
350-
opal_leave_pinned = !opal_leave_pinned_pipeline;
351-
}
352-
}
353-
354334
static mca_btl_base_module_t **
355335
mca_btl_ugni_component_init (int *num_btl_modules,
356336
bool enable_progress_threads,
@@ -409,8 +389,6 @@ mca_btl_ugni_component_init (int *num_btl_modules,
409389
}
410390
}
411391

412-
mca_btl_ugni_autoset_leave_pinned ();
413-
414392
mca_btl_ugni_module.super.btl_rdma_pipeline_send_length = mca_btl_ugni_module.super.btl_eager_limit;
415393

416394
for (i = 0 ; i < mca_btl_ugni_component.ugni_num_btls ; ++i) {

opal/mca/rcache/base/base.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "opal/class/opal_list.h"
3030
#include "opal/mca/mca.h"
3131
#include "opal/mca/rcache/rcache.h"
32+
#include "opal/mca/memory/base/base.h"
3233

3334
BEGIN_C_DECLS
3435

opal/mca/rcache/base/rcache_base_create.c

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -43,24 +43,6 @@ mca_rcache_base_module_t* mca_rcache_base_module_create (const char* name, void
4343
mca_base_component_list_item_t *cli;
4444
mca_rcache_base_selected_module_t *sm;
4545

46-
OPAL_LIST_FOREACH(cli, &opal_rcache_base_framework.framework_components, mca_base_component_list_item_t) {
47-
component = (mca_rcache_base_component_t *) cli->cli_component;
48-
if(0 == strcmp(component->rcache_version.mca_component_name, name)) {
49-
module = component->rcache_init (resources);
50-
break;
51-
}
52-
}
53-
54-
if ( NULL == module ) {
55-
return NULL;
56-
}
57-
58-
sm = OBJ_NEW(mca_rcache_base_selected_module_t);
59-
sm->rcache_component = component;
60-
sm->rcache_module = module;
61-
sm->user_data = user_data;
62-
opal_list_append(&mca_rcache_base_modules, (opal_list_item_t*) sm);
63-
6446
/* on the very first creation of a module we init the memory
6547
callback */
6648
if (!mca_rcache_base_used_mem_hooks) {
@@ -71,11 +53,21 @@ mca_rcache_base_module_t* mca_rcache_base_module_create (const char* name, void
7153
* coded this more succinctly, but this is more clear. Do not
7254
* check memory hooks if the rcache does not provide an
7355
* range invalidation function.. */
74-
if ((opal_leave_pinned > 0 || opal_leave_pinned_pipeline) &&
75-
module->rcache_invalidate_range) {
56+
if (opal_leave_pinned != 0 || opal_leave_pinned_pipeline) {
57+
/* open the memory manager components. Memory hooks may be
58+
triggered before this (any time after mem_free_init(),
59+
actually). This is a hook available for memory manager hooks
60+
without good initialization routine support */
61+
(void) mca_base_framework_open (&opal_memory_base_framework, 0);
62+
}
63+
64+
if (opal_leave_pinned != 0 || opal_leave_pinned_pipeline) {
7665
if ((OPAL_MEMORY_FREE_SUPPORT | OPAL_MEMORY_MUNMAP_SUPPORT) ==
7766
((OPAL_MEMORY_FREE_SUPPORT | OPAL_MEMORY_MUNMAP_SUPPORT) &
7867
opal_mem_hooks_support_level())) {
68+
if (-1 == opal_leave_pinned) {
69+
opal_leave_pinned = !opal_leave_pinned_pipeline;
70+
}
7971
opal_mem_hooks_register_release(mca_rcache_base_mem_cb, NULL);
8072
} else {
8173
opal_show_help("help-rcache-base.txt", "leave pinned failed",
@@ -90,6 +82,24 @@ mca_rcache_base_module_t* mca_rcache_base_module_create (const char* name, void
9082
}
9183
}
9284

85+
OPAL_LIST_FOREACH(cli, &opal_rcache_base_framework.framework_components, mca_base_component_list_item_t) {
86+
component = (mca_rcache_base_component_t *) cli->cli_component;
87+
if(0 == strcmp(component->rcache_version.mca_component_name, name)) {
88+
module = component->rcache_init (resources);
89+
break;
90+
}
91+
}
92+
93+
if ( NULL == module ) {
94+
return NULL;
95+
}
96+
97+
sm = OBJ_NEW(mca_rcache_base_selected_module_t);
98+
sm->rcache_component = component;
99+
sm->rcache_module = module;
100+
sm->user_data = user_data;
101+
opal_list_append(&mca_rcache_base_modules, (opal_list_item_t*) sm);
102+
93103
return module;
94104
}
95105

opal/mca/rcache/base/rcache_base_frame.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* University of Stuttgart. All rights reserved.
1111
* Copyright (c) 2004-2005 The Regents of the University of California.
1212
* All rights reserved.
13-
* Copyright (c) 2012-2013 Los Alamos National Security, LLC.
13+
* Copyright (c) 2012-2016 Los Alamos National Security, LLC.
1414
* All rights reserved
1515
* Copyright (c) 2015-2016 Research Organization for Information Science
1616
* and Technology (RIST). All rights reserved.
@@ -92,6 +92,13 @@ static int mca_rcache_base_close(void)
9292
/* deregister memory free callback */
9393
if (mca_rcache_base_used_mem_hooks) {
9494
opal_mem_hooks_unregister_release(mca_rcache_base_mem_cb);
95+
96+
/* close the memory manager components. Registered hooks can
97+
still be fired any time between now and the call to
98+
opal_mem_free_finalize(), and callbacks from the memory manager
99+
hooks to the bowels of the mem_free code can still occur any
100+
time between now and end of application (even post main()!) */
101+
(void) mca_base_framework_close (&opal_memory_base_framework);
95102
}
96103
/* All done */
97104

opal/memoryhooks/memory.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ opal_mem_hooks_set_support(int support)
106106
void
107107
opal_mem_hooks_release_hook(void *buf, size_t length, bool from_alloc)
108108
{
109-
opal_list_item_t *item;
109+
callback_list_item_t *cbitem, *next;
110110

111111
if (!release_run_callbacks) return;
112112

@@ -121,12 +121,7 @@ opal_mem_hooks_release_hook(void *buf, size_t length, bool from_alloc)
121121
*/
122122

123123
opal_atomic_lock(&release_lock);
124-
item = opal_list_get_first(&release_cb_list);
125-
while(item != opal_list_get_end(&release_cb_list)) {
126-
opal_list_item_t* next = opal_list_get_next(item);
127-
callback_list_item_t *cbitem = (callback_list_item_t*) item;
128-
item = next;
129-
124+
OPAL_LIST_FOREACH_SAFE(cbitem, next, &release_cb_list, callback_list_item_t) {
130125
opal_atomic_unlock(&release_lock);
131126
cbitem->cbfunc(buf, length, cbitem->cbdata, (bool) from_alloc);
132127
opal_atomic_lock(&release_lock);

opal/runtime/opal_finalize.c

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
#include "opal/mca/installdirs/base/base.h"
4141
#include "opal/mca/memchecker/base/base.h"
4242
#include "opal/mca/memcpy/base/base.h"
43-
#include "opal/mca/memory/base/base.h"
4443
#include "opal/mca/patcher/base/base.h"
4544
#include "opal/mca/backtrace/base/base.h"
4645
#include "opal/mca/sec/base/base.h"
@@ -154,13 +153,6 @@ opal_finalize(void)
154153

155154
(void) mca_base_framework_close(&opal_backtrace_base_framework);
156155
(void) mca_base_framework_close(&opal_memchecker_base_framework);
157-
158-
/* close the memory manager components. Registered hooks can
159-
still be fired any time between now and the call to
160-
opal_mem_free_finalize(), and callbacks from the memory manager
161-
hooks to the bowels of the mem_free code can still occur any
162-
time between now and end of application (even post main()!) */
163-
(void) mca_base_framework_close(&opal_memory_base_framework);
164156
(void) mca_base_framework_close(&opal_patcher_base_framework);
165157

166158
/* close the memcpy framework */

opal/runtime/opal_init.c

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -439,15 +439,6 @@ opal_init(int* pargc, char*** pargv)
439439
/* select a patcher module. if a patcher module can not be found it is not an error. */
440440
(void) opal_patcher_base_select ();
441441

442-
/* open the memory manager components. Memory hooks may be
443-
triggered before this (any time after mem_free_init(),
444-
actually). This is a hook available for memory manager hooks
445-
without good initialization routine support */
446-
if (OPAL_SUCCESS != (ret = mca_base_framework_open(&opal_memory_base_framework, 0))) {
447-
error = "opal_memory_base_open";
448-
goto return_error;
449-
}
450-
451442
/* initialize the memory manager / tracker */
452443
if (OPAL_SUCCESS != (ret = opal_mem_hooks_init())) {
453444
error = "opal_mem_hooks_init";

0 commit comments

Comments
 (0)