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

Commit a2f02bd

Browse files
committed
rcache: fix deadlock in multi-threaded environments
This commit fixes several bugs in the registration cache code: - Fix a programming error in the grdma invalidation function that can cause an infinite loop if more than 100 registrations are associated with a munmapped region. This happens because the mca_rcache_base_vma_find_all function returns the same 100 registrations on each call. This has been fixed by adding an iterate function to the vma tree interface. - Always obtain the vma lock when needed. This is required because there may be other threads in the system even if opal_using_threads() is false. Additionally, since it is safe to do so (the vma lock is recursive) the vma interface has been made thread safe. - Avoid calling free() while holding a lock. This avoids race conditions with locks held outside the Open MPI code. Back-port of open-mpi/ompi@ab8ed17 Fixes open-mpi/ompi#1654. Signed-off-by: Nathan Hjelm <hjelmn@lanl.gov>
1 parent 5065fd0 commit a2f02bd

File tree

8 files changed

+375
-293
lines changed

8 files changed

+375
-293
lines changed

opal/mca/btl/vader/btl_vader_module.c

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* All rights reserved.
1313
* Copyright (c) 2006-2007 Voltaire. All rights reserved.
1414
* Copyright (c) 2009 Cisco Systems, Inc. All rights reserved.
15-
* Copyright (c) 2010-2015 Los Alamos National Security, LLC. All rights
15+
* Copyright (c) 2010-2016 Los Alamos National Security, LLC. All rights
1616
* reserved.
1717
* Copyright (c) 2014-2015 Intel, Inc. All rights reserved.
1818
* Copyright (c) 2014-2015 Research Organization for Information Science
@@ -528,6 +528,17 @@ static void mca_btl_vader_endpoint_constructor (mca_btl_vader_endpoint_t *ep)
528528
ep->fifo = NULL;
529529
}
530530

531+
#if OPAL_BTL_VADER_HAVE_XPMEM
532+
static int mca_btl_vader_endpoint_rcache_cleanup (mca_rcache_base_registration_t *reg, void *ctx)
533+
{
534+
struct mca_rcache_base_module_t *rcache = (struct mca_rcache_base_module_t *) ctx;
535+
/* otherwise dereg will fail on assert */
536+
reg->ref_count = 0;
537+
(void) rcache->rcache_delete (rcache, reg);
538+
return OPAL_SUCCESS;
539+
}
540+
#endif
541+
531542
static void mca_btl_vader_endpoint_destructor (mca_btl_vader_endpoint_t *ep)
532543
{
533544
OBJ_DESTRUCT(&ep->pending_frags);
@@ -537,21 +548,10 @@ static void mca_btl_vader_endpoint_destructor (mca_btl_vader_endpoint_t *ep)
537548
if (MCA_BTL_VADER_XPMEM == mca_btl_vader_component.single_copy_mechanism) {
538549
if (ep->segment_data.xpmem.rcache) {
539550
/* clean out the registration cache */
540-
const int nregs = 100;
541-
mca_mpool_base_registration_t *regs[nregs];
542-
int reg_cnt;
543-
544-
do {
545-
reg_cnt = ep->segment_data.xpmem.rcache->rcache_find_all(ep->segment_data.xpmem.rcache, 0, (size_t)-1,
546-
regs, nregs);
547-
548-
for (int i = 0 ; i < reg_cnt ; ++i) {
549-
/* otherwise dereg will fail on assert */
550-
regs[i]->ref_count = 0;
551-
OBJ_RELEASE(regs[i]);
552-
}
553-
} while (reg_cnt == nregs);
554-
551+
(void) mca_rcache_base_vma_iterate (ep->segment_data.xpmem.rcache,
552+
NULL, (size_t) -1,
553+
mca_btl_vader_endpoint_rcache_cleanup,
554+
(void *) ep->segment_data.xpmem.rcache);
555555
ep->segment_data.xpmem.rcache = NULL;
556556
}
557557

opal/mca/mpool/grdma/mpool_grdma.h

Lines changed: 3 additions & 2 deletions
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) 2006 Voltaire. All rights reserved.
14-
* Copyright (c) 2011-2015 Los Alamos National Security, LLC. All rights
14+
* Copyright (c) 2011-2016 Los Alamos National Security, LLC. All rights
1515
* reserved.
1616
*
1717
* $COPYRIGHT$
@@ -28,6 +28,7 @@
2828

2929
#include "opal_config.h"
3030
#include "opal/class/opal_list.h"
31+
#include "opal/class/opal_lifo.h"
3132
#include "opal/mca/event/event.h"
3233
#include "opal/mca/mpool/mpool.h"
3334
#if HAVE_SYS_MMAN_H
@@ -42,7 +43,7 @@ struct mca_mpool_grdma_pool_t {
4243
opal_list_item_t super;
4344
char *pool_name;
4445
opal_list_t lru_list;
45-
opal_list_t gc_list;
46+
opal_lifo_t gc_lifo;
4647
struct mca_rcache_base_module_t *rcache;
4748
};
4849
typedef struct mca_mpool_grdma_pool_t mca_mpool_grdma_pool_t;

0 commit comments

Comments
 (0)