99
1010#include "pml_ucx.h"
1111
12+ #include "opal/memoryhooks/memory.h"
13+ #include "opal/mca/memory/base/base.h"
14+
15+ #include <ucm/api/ucm.h>
16+
1217
1318static int mca_pml_ucx_component_register (void );
1419static int mca_pml_ucx_component_open (void );
@@ -70,13 +75,39 @@ static int mca_pml_ucx_component_register(void)
7075 OPAL_INFO_LVL_3 ,
7176 MCA_BASE_VAR_SCOPE_LOCAL ,
7277 & 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 );
7386 return 0 ;
7487}
7588
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+
7695static int mca_pml_ucx_component_open (void )
7796{
7897 ompi_pml_ucx .output = opal_output_open (NULL );
7998 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+
80111 return mca_pml_ucx_open ();
81112}
82113
@@ -89,6 +120,7 @@ static int mca_pml_ucx_component_close(void)
89120 return rc ;
90121 }
91122
123+ opal_mem_hooks_unregister_release (mca_pml_ucx_mem_release_cb );
92124 opal_output_close (ompi_pml_ucx .output );
93125 return 0 ;
94126}
0 commit comments