Skip to content

Commit

Permalink
ch4/posix: use static shm_limit_counter
Browse files Browse the repository at this point in the history
current main branch sets MPIDI_POSIX_shm_limit_counter as MPIDI_POSIX_global.shm_ptr,
which is to record total amount of shm mem used in coll calls. However, during
finalize stage, MPIDI_POSIX_global will be freed first and the following operations
on MPIDI_POSIX_shm_limit_counter will be invalid and cause memory segmentation fault.
This commit makes MPIDI_POSIX_shm_limit_counter point to global variable and avoid
considering the finalize sequence.
  • Loading branch information
Kaiming Ouyang committed Nov 6, 2020
1 parent 9d2b8b1 commit 64908b7
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 14 deletions.
1 change: 1 addition & 0 deletions src/mpid/ch4/shm/posix/globals.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ MPIDI_POSIX_global_t MPIDI_POSIX_global = { 0 };
MPIDI_POSIX_eager_funcs_t *MPIDI_POSIX_eager_func = NULL;

MPL_atomic_uint64_t *MPIDI_POSIX_shm_limit_counter = NULL;
MPL_atomic_uint64_t MPIDI_POSIX_global_shm_ptr;
14 changes: 2 additions & 12 deletions src/mpid/ch4/shm/posix/posix_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include "mpidu_genq.h"

extern MPL_atomic_uint64_t *MPIDI_POSIX_shm_limit_counter;
extern MPL_atomic_uint64_t MPIDI_POSIX_global_shm_ptr;

static int choose_posix_eager(void);
static void *host_alloc(uintptr_t size);
Expand Down Expand Up @@ -235,14 +236,7 @@ int MPIDI_POSIX_coll_init(int rank, int size)
}
MPIR_ERR_CHECK(mpi_errno);

/* Actually allocate the segment and assign regions to the pointers */
mpi_errno = MPIDU_Init_shm_alloc(sizeof(int), &MPIDI_POSIX_global.shm_ptr);
MPIR_ERR_CHECK(mpi_errno);

MPIDI_POSIX_shm_limit_counter = (MPL_atomic_uint64_t *) MPIDI_POSIX_global.shm_ptr;

mpi_errno = MPIDU_Init_shm_barrier();
MPIR_ERR_CHECK(mpi_errno);
MPIDI_POSIX_shm_limit_counter = &MPIDI_POSIX_global_shm_ptr;

/* Set the counter to 0 */
MPL_atomic_relaxed_store_uint64(MPIDI_POSIX_shm_limit_counter, 0);
Expand All @@ -261,10 +255,6 @@ int MPIDI_POSIX_coll_finalize(void)
MPIR_FUNC_VERBOSE_STATE_DECL(MPID_STATE_MPIDI_POSIX_COLL_FINALIZE);
MPIR_FUNC_VERBOSE_ENTER(MPID_STATE_MPIDI_POSIX_COLL_FINALIZE);

/* Destroy the shared counter which was used to track the amount of shared memory created
* per node for intra-node collectives */
mpi_errno = MPIDU_Init_shm_free(MPIDI_POSIX_global.shm_ptr);

if (MPIDI_global.shm.posix.csel_root) {
mpi_errno = MPIR_Csel_free(MPIDI_global.shm.posix.csel_root);
MPIR_ERR_CHECK(mpi_errno);
Expand Down
2 changes: 0 additions & 2 deletions src/mpid/ch4/shm/posix/posix_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ typedef struct {
/* Active recv requests array */
MPIR_Request **active_rreq;

void *shm_ptr;

/* Keep track of all of the local processes in MPI_COMM_WORLD and what their original rank was
* in that communicator. */
int num_local;
Expand Down

0 comments on commit 64908b7

Please sign in to comment.