Skip to content

Commit ade280e

Browse files
authored
Merge pull request #3292 from markalle/pr/ibv_reg_mr__fork
IB fork
2 parents 85ce76f + 655a06f commit ade280e

File tree

3 files changed

+38
-7
lines changed

3 files changed

+38
-7
lines changed

opal/mca/btl/openib/connect/btl_openib_connect_base.c

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@
3232
#include "opal/util/proc.h"
3333
#include "opal/util/show_help.h"
3434

35+
#include "opal/util/sys_limits.h"
36+
#include "opal/align.h"
37+
3538
/*
3639
* Array of all possible connection functions
3740
*/
@@ -421,10 +424,27 @@ int opal_btl_openib_connect_base_alloc_cts(mca_btl_base_endpoint_t *endpoint)
421424
sizeof(mca_btl_openib_footer_t) +
422425
mca_btl_openib_component.qp_infos[mca_btl_openib_component.credits_qp].size;
423426

427+
int align_it = 0;
428+
int page_size;
429+
430+
page_size = opal_getpagesize();
431+
if (length >= page_size / 2) { align_it = 1; }
432+
if (align_it) {
433+
// I think this is only active for ~64k+ buffers anyway, but I'm not
434+
// positive, so I'm only increasing the buffer size and alignment if
435+
// it's not too small. That way we'd avoid wasting excessive memory
436+
// in case this code was active for tiny buffers.
437+
length = OPAL_ALIGN(length, page_size, int);
438+
}
439+
424440
/* Explicitly don't use the mpool registration */
425441
fli = &(endpoint->endpoint_cts_frag.super.super.base.super);
426442
fli->registration = NULL;
427-
fli->ptr = malloc(length);
443+
if (!align_it) {
444+
fli->ptr = malloc(length);
445+
} else {
446+
posix_memalign((void**)&(fli->ptr), page_size, length);
447+
}
428448
if (NULL == fli->ptr) {
429449
BTL_ERROR(("malloc failed"));
430450
return OPAL_ERR_OUT_OF_RESOURCE;

opal/mca/btl/openib/connect/btl_openib_connect_udcm.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
#include "connect/connect.h"
7676

7777
#include "opal/util/sys_limits.h"
78+
#include "opal/align.h"
7879

7980
#if (ENABLE_DYNAMIC_SL)
8081
#include "connect/btl_openib_connect_sl.h"
@@ -1040,16 +1041,19 @@ static void udcm_module_destroy_listen_qp (udcm_module_t *m)
10401041

10411042
static int udcm_module_allocate_buffers (udcm_module_t *m)
10421043
{
1043-
size_t total_size;
1044+
size_t total_size, page_size;
10441045

10451046
m->msg_length = sizeof (udcm_msg_hdr_t) +
10461047
mca_btl_openib_component.num_qps * sizeof (udcm_qp_t);
10471048

10481049
total_size = (udcm_recv_count + 1) * (m->msg_length +
10491050
UDCM_GRH_SIZE);
10501051

1052+
page_size = opal_getpagesize();
1053+
total_size = OPAL_ALIGN(total_size, page_size, size_t);
1054+
10511055
m->cm_buffer = NULL;
1052-
posix_memalign ((void **)&m->cm_buffer, (size_t)opal_getpagesize(),
1056+
posix_memalign ((void **)&m->cm_buffer, (size_t)page_size,
10531057
total_size);
10541058
if (NULL == m->cm_buffer) {
10551059
BTL_ERROR(("malloc failed! errno = %d", errno));

opal/util/sys_limits.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -235,13 +235,20 @@ int opal_util_init_sys_limits(char **errmsg)
235235

236236
int opal_getpagesize(void)
237237
{
238+
static int page_size = -1;
239+
240+
if (page_size != -1) {
241+
// testing in a loop showed sysconf() took ~5 usec vs ~0.3 usec with it cached
242+
return page_size;
243+
}
244+
238245
#ifdef HAVE_GETPAGESIZE
239-
return getpagesize();
246+
return page_size = getpagesize();
240247
#elif defined(_SC_PAGESIZE )
241-
return sysconf(_SC_PAGESIZE);
248+
return page_size = sysconf(_SC_PAGESIZE);
242249
#elif defined(_SC_PAGE_SIZE)
243-
return sysconf(_SC_PAGE_SIZE);
250+
return page_size = sysconf(_SC_PAGE_SIZE);
244251
#else
245-
return 65536; /* safer to overestimate than under */
252+
return page_size = 65536; /* safer to overestimate than under */
246253
#endif
247254
}

0 commit comments

Comments
 (0)