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

Commit 3ad26c5

Browse files
committed
Make UD OOB memory registrations a multiple of page size
If ibv_fork_init() has been invoked the pages are marked MADV_DONTFORK. If we only partially use a page, any data allocated on the remainder of the page will be inaccessible to the child process. Fixes open-mpi/ompi#1363
1 parent 88d8a8d commit 3ad26c5

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

orte/mca/oob/ud/oob_ud_component.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
#include "orte_config.h"
2020
#include "orte/types.h"
2121
#include "opal/types.h"
22+
#include "opal/align.h"
23+
#include "opal/util/sys_limits.h"
2224

2325
#include "orte/mca/errmgr/errmgr.h"
2426
#include "orte/runtime/orte_globals.h"
@@ -665,15 +667,21 @@ static inline int mca_oob_ud_port_recv_start (mca_oob_ud_port_t *port)
665667
static inline int mca_oob_ud_alloc_reg_mem (struct ibv_pd *pd, mca_oob_ud_reg_mem_t *reg_mem,
666668
const int buffer_len)
667669
{
670+
size_t buffer_len_aligned, page_size;
668671
reg_mem->len = buffer_len;
669672
reg_mem->ptr = NULL;
670673
reg_mem->mr = NULL;
671-
674+
/* The allocated buffer should be a multiple of page size.
675+
If ibv_fork_init() has been invoked the pages are marked MADV_DONTFORK.
676+
If we only partially use a page, any data allocated on the remainder of
677+
the page will be inaccessible to the child process */
678+
page_size = opal_getpagesize();
679+
buffer_len_aligned = OPAL_ALIGN(buffer_len, page_size, size_t);
672680
opal_output_verbose(5, orte_oob_base_framework.framework_output,
673681
"%s oob:ud:alloc_reg_mem allocing and registering %d bytes of memory with pd %p",
674682
ORTE_NAME_PRINT(ORTE_PROC_MY_NAME), buffer_len, (void *) pd);
675683

676-
posix_memalign ((void **)&reg_mem->ptr, sysconf(_SC_PAGESIZE), buffer_len);
684+
posix_memalign ((void **)&reg_mem->ptr, page_size, buffer_len_aligned);
677685
if (NULL == reg_mem->ptr) {
678686
ORTE_ERROR_LOG(ORTE_ERR_OUT_OF_RESOURCE);
679687
return ORTE_ERR_OUT_OF_RESOURCE;

0 commit comments

Comments
 (0)