Skip to content

Commit 0d5dabc

Browse files
committed
btl/sm: avoid using xpmem for fast boxes
xpmem has different behvior than other shared memory support mechanisms. in particular, any xpmem-attached regions in a process will become invalid once the exporting process exits. Under certain circumstances, this behavior can result in SIGBUS errors during mpi finalize. Related to open-mpi#9868 Signed-off-by: Howard Pritchard <[email protected]>
1 parent 9605bed commit 0d5dabc

File tree

2 files changed

+35
-74
lines changed

2 files changed

+35
-74
lines changed

opal/mca/btl/sm/btl_sm_component.c

Lines changed: 21 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -254,11 +254,6 @@ static int mca_btl_sm_component_close(void)
254254
OBJ_DESTRUCT(&mca_btl_sm_component.pending_endpoints);
255255
OBJ_DESTRUCT(&mca_btl_sm_component.pending_fragments);
256256

257-
if (mca_smsc_base_has_feature(MCA_SMSC_FEATURE_CAN_MAP)
258-
&& NULL != mca_btl_sm_component.my_segment) {
259-
munmap(mca_btl_sm_component.my_segment, mca_btl_sm_component.segment_size);
260-
}
261-
262257
mca_btl_sm_component.my_segment = NULL;
263258

264259
if (mca_btl_sm_component.mpool) {
@@ -276,14 +271,9 @@ static int mca_btl_base_sm_modex_send(void)
276271

277272
modex_size = sizeof(modex) - sizeof(modex.seg_ds);
278273

279-
if (!mca_smsc_base_has_feature(MCA_SMSC_FEATURE_CAN_MAP)) {
280274
modex.seg_ds_size = opal_shmem_sizeof_shmem_ds(&mca_btl_sm_component.seg_ds);
281275
memmove(&modex.seg_ds, &mca_btl_sm_component.seg_ds, modex.seg_ds_size);
282276
modex_size += modex.seg_ds_size;
283-
} else {
284-
modex.segment_base = (uintptr_t) mca_btl_sm_component.my_segment;
285-
modex.seg_ds_size = 0;
286-
}
287277

288278
int rc;
289279
OPAL_MODEX_SEND(rc, PMIX_LOCAL, &mca_btl_sm_component.super.btl_version, &modex, modex_size);
@@ -376,41 +366,29 @@ mca_btl_sm_component_init(int *num_btls, bool enable_progress_threads, bool enab
376366
mca_btl_sm.super.btl_put = NULL;
377367
}
378368

379-
if (!mca_smsc_base_has_feature(MCA_SMSC_FEATURE_CAN_MAP)) {
380-
char *sm_file;
369+
char *sm_file;
381370

382-
rc = opal_asprintf(&sm_file, "%s" OPAL_PATH_SEP "sm_segment.%s.%u.%x.%d",
383-
mca_btl_sm_component.backing_directory, opal_process_info.nodename,
371+
rc = opal_asprintf(&sm_file, "%s" OPAL_PATH_SEP "sm_segment.%s.%u.%x.%d",
372+
mca_btl_sm_component.backing_directory, opal_process_info.nodename,
384373
geteuid(), OPAL_PROC_MY_NAME.jobid, MCA_BTL_SM_LOCAL_RANK);
385-
if (0 > rc) {
386-
free(btls);
387-
return NULL;
388-
}
389-
opal_pmix_register_cleanup(sm_file, false, false, false);
390-
391-
rc = opal_shmem_segment_create(&component->seg_ds, sm_file, component->segment_size);
392-
free(sm_file);
393-
if (OPAL_SUCCESS != rc) {
394-
BTL_VERBOSE(("Could not create shared memory segment"));
395-
free(btls);
396-
return NULL;
397-
}
374+
if (0 > rc) {
375+
free(btls);
376+
return NULL;
377+
}
378+
opal_pmix_register_cleanup(sm_file, false, false, false);
398379

399-
component->my_segment = opal_shmem_segment_attach(&component->seg_ds);
400-
if (NULL == component->my_segment) {
401-
BTL_VERBOSE(("Could not attach to just created shared memory segment"));
402-
goto failed;
403-
}
404-
} else {
405-
/* if the shared-memory single-copy component can map memory (XPMEM) an anonymous segment
406-
* can be used instead */
407-
component->my_segment = mmap(NULL, component->segment_size, PROT_READ | PROT_WRITE,
408-
MAP_ANONYMOUS | MAP_SHARED, -1, 0);
409-
if ((void *) -1 == component->my_segment) {
410-
BTL_VERBOSE(("Could not create anonymous memory segment"));
411-
free(btls);
412-
return NULL;
413-
}
380+
rc = opal_shmem_segment_create(&component->seg_ds, sm_file, component->segment_size);
381+
free(sm_file);
382+
if (OPAL_SUCCESS != rc) {
383+
BTL_VERBOSE(("Could not create shared memory segment"));
384+
free(btls);
385+
return NULL;
386+
}
387+
388+
component->my_segment = opal_shmem_segment_attach(&component->seg_ds);
389+
if (NULL == component->my_segment) {
390+
BTL_VERBOSE(("Could not attach to just created shared memory segment"));
391+
goto failed;
414392
}
415393

416394
/* initialize my fifo */
@@ -432,11 +410,7 @@ mca_btl_sm_component_init(int *num_btls, bool enable_progress_threads, bool enab
432410

433411
return btls;
434412
failed:
435-
if (mca_smsc_base_has_feature(MCA_SMSC_FEATURE_CAN_MAP)) {
436-
munmap(component->my_segment, component->segment_size);
437-
} else {
438-
opal_shmem_unlink(&component->seg_ds);
439-
}
413+
opal_shmem_unlink(&component->seg_ds);
440414

441415
if (btls) {
442416
free(btls);

opal/mca/btl/sm/btl_sm_module.c

Lines changed: 14 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -186,12 +186,6 @@ static int init_sm_endpoint(struct mca_btl_base_endpoint_t **ep_out, struct opal
186186
mca_btl_sm.super.btl_put = NULL;
187187
mca_btl_sm.super.btl_flags &= ~MCA_BTL_FLAGS_RDMA;
188188
}
189-
if (mca_smsc_base_has_feature(MCA_SMSC_FEATURE_CAN_MAP)) {
190-
ep->smsc_map_context = MCA_SMSC_CALL(map_peer_region, ep->smsc_endpoint, /*flag=*/0,
191-
(void *) (uintptr_t) modex->segment_base,
192-
mca_btl_sm_component.segment_size,
193-
(void **) &ep->segment_base);
194-
} else {
195189
/* store a copy of the segment information for detach */
196190
ep->seg_ds = malloc(modex->seg_ds_size);
197191
if (NULL == ep->seg_ds) {
@@ -204,7 +198,6 @@ static int init_sm_endpoint(struct mca_btl_base_endpoint_t **ep_out, struct opal
204198
if (NULL == ep->segment_base) {
205199
return OPAL_ERROR;
206200
}
207-
}
208201

209202
OBJ_CONSTRUCT(&ep->lock, opal_mutex_t);
210203

@@ -354,10 +347,8 @@ static int sm_finalize(struct mca_btl_base_module_t *btl)
354347
free(component->fbox_in_endpoints);
355348
component->fbox_in_endpoints = NULL;
356349

357-
if (!mca_smsc_base_has_feature(MCA_SMSC_FEATURE_CAN_MAP)) {
358-
opal_shmem_unlink(&mca_btl_sm_component.seg_ds);
359-
opal_shmem_segment_detach(&mca_btl_sm_component.seg_ds);
360-
}
350+
opal_shmem_unlink(&mca_btl_sm_component.seg_ds);
351+
opal_shmem_segment_detach(&mca_btl_sm_component.seg_ds);
361352

362353
return OPAL_SUCCESS;
363354
}
@@ -522,22 +513,18 @@ static void mca_btl_sm_endpoint_destructor(mca_btl_sm_endpoint_t *ep)
522513
OBJ_DESTRUCT(&ep->pending_frags);
523514
OBJ_DESTRUCT(&ep->pending_frags_lock);
524515

525-
if (!mca_smsc_base_has_feature(MCA_SMSC_FEATURE_CAN_MAP)) {
526-
if (ep->seg_ds) {
527-
opal_shmem_ds_t seg_ds;
528-
529-
/* opal_shmem_segment_detach expects a opal_shmem_ds_t and will
530-
* stomp past the end of the seg_ds if it is too small (which
531-
* ep->seg_ds probably is) */
532-
memcpy(&seg_ds, ep->seg_ds, opal_shmem_sizeof_shmem_ds(ep->seg_ds));
533-
free(ep->seg_ds);
534-
ep->seg_ds = NULL;
535-
536-
/* disconnect from the peer's segment */
537-
opal_shmem_segment_detach(&seg_ds);
538-
}
539-
} else if (NULL != ep->smsc_map_context) {
540-
MCA_SMSC_CALL(unmap_peer_region, ep->smsc_map_context);
516+
if (ep->seg_ds) {
517+
opal_shmem_ds_t seg_ds;
518+
519+
/* opal_shmem_segment_detach expects a opal_shmem_ds_t and will
520+
* stomp past the end of the seg_ds if it is too small (which
521+
* ep->seg_ds probably is) */
522+
memcpy(&seg_ds, ep->seg_ds, opal_shmem_sizeof_shmem_ds(ep->seg_ds));
523+
free(ep->seg_ds);
524+
ep->seg_ds = NULL;
525+
526+
/* disconnect from the peer's segment */
527+
opal_shmem_segment_detach(&seg_ds);
541528
}
542529

543530
if (ep->fbox_out.fbox) {

0 commit comments

Comments
 (0)