9
9
10
10
#include "pml_ucx.h"
11
11
12
+ #include "opal/memoryhooks/memory.h"
13
+ #include "opal/mca/memory/base/base.h"
14
+
15
+ #include <ucm/api/ucm.h>
16
+
12
17
13
18
static int mca_pml_ucx_component_register (void );
14
19
static int mca_pml_ucx_component_open (void );
@@ -70,13 +75,39 @@ static int mca_pml_ucx_component_register(void)
70
75
OPAL_INFO_LVL_3 ,
71
76
MCA_BASE_VAR_SCOPE_LOCAL ,
72
77
& ompi_pml_ucx .num_disconnect );
78
+
79
+ ompi_pml_ucx .opal_mem_hooks = 0 ;
80
+ (void ) mca_base_component_var_register (& mca_pml_ucx_component .pmlm_version , "opal_mem_hooks" ,
81
+ "Use OPAL memory hooks, instead of UCX internal memory hooks" ,
82
+ MCA_BASE_VAR_TYPE_BOOL , NULL , 0 , 0 ,
83
+ OPAL_INFO_LVL_3 ,
84
+ MCA_BASE_VAR_SCOPE_LOCAL ,
85
+ & ompi_pml_ucx .opal_mem_hooks );
73
86
return 0 ;
74
87
}
75
88
89
+ static void mca_pml_ucx_mem_release_cb (void * buf , size_t length ,
90
+ void * cbdata , bool from_alloc )
91
+ {
92
+ ucm_vm_munmap (buf , length );
93
+ }
94
+
76
95
static int mca_pml_ucx_component_open (void )
77
96
{
78
97
ompi_pml_ucx .output = opal_output_open (NULL );
79
98
opal_output_set_verbosity (ompi_pml_ucx .output , ompi_pml_ucx .verbose );
99
+
100
+ /* Set memory hooks */
101
+ if (ompi_pml_ucx .opal_mem_hooks &&
102
+ (OPAL_MEMORY_FREE_SUPPORT | OPAL_MEMORY_MUNMAP_SUPPORT ) ==
103
+ ((OPAL_MEMORY_FREE_SUPPORT | OPAL_MEMORY_MUNMAP_SUPPORT ) &
104
+ opal_mem_hooks_support_level ()))
105
+ {
106
+ PML_UCX_VERBOSE (1 , "%s" , "using OPAL memory hooks as external events" );
107
+ ucm_set_external_event (UCM_EVENT_VM_UNMAPPED );
108
+ opal_mem_hooks_register_release (mca_pml_ucx_mem_release_cb , NULL );
109
+ }
110
+
80
111
return mca_pml_ucx_open ();
81
112
}
82
113
@@ -89,6 +120,7 @@ static int mca_pml_ucx_component_close(void)
89
120
return rc ;
90
121
}
91
122
123
+ opal_mem_hooks_unregister_release (mca_pml_ucx_mem_release_cb );
92
124
opal_output_close (ompi_pml_ucx .output );
93
125
return 0 ;
94
126
}
0 commit comments