Skip to content

Commit 7064237

Browse files
authored
Merge pull request #5230 from hjelmn/v3.1.x_dev_shm
Preferentially use /dev/shm on Linux
2 parents 9df0e66 + 1d5c887 commit 7064237

File tree

4 files changed

+62
-11
lines changed

4 files changed

+62
-11
lines changed

ompi/mca/osc/rdma/osc_rdma.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@ struct ompi_osc_rdma_component_t {
106106

107107
/** aggregation free list */
108108
opal_free_list_t aggregate;
109+
110+
/** directory where to place backing files */
111+
char *backing_directory;
109112
};
110113
typedef struct ompi_osc_rdma_component_t ompi_osc_rdma_component_t;
111114

ompi/mca/osc/rdma/osc_rdma_component.c

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,18 @@ static int ompi_osc_rdma_component_register (void)
268268
MCA_BASE_VAR_SCOPE_GROUP, &ompi_osc_rdma_mtl_names);
269269
free(description_str);
270270

271+
if (0 == access ("/dev/shm", W_OK)) {
272+
mca_osc_rdma_component.backing_directory = "/dev/shm";
273+
} else {
274+
mca_osc_rdma_component.backing_directory = ompi_process_info.proc_session_dir;
275+
}
276+
277+
(void) mca_base_component_var_register (&mca_osc_rdma_component.super.osc_version, "backing_directory",
278+
"Directory to place backing files for memory windows. "
279+
"This directory should be on a local filesystem such as /tmp or "
280+
"/dev/shm (default: (linux) /dev/shm, (others) session directory)",
281+
MCA_BASE_VAR_TYPE_STRING, NULL, 0, 0, OPAL_INFO_LVL_3,
282+
MCA_BASE_VAR_SCOPE_READONLY, &mca_osc_rdma_component.backing_directory);
271283

272284
/* register performance variables */
273285

@@ -602,9 +614,9 @@ static int allocate_state_shared (ompi_osc_rdma_module_t *module, void **base, s
602614
}
603615

604616
/* allocate the shared memory segment */
605-
ret = asprintf (&data_file, "%s"OPAL_PATH_SEP"window_%d.%s",
606-
ompi_process_info.job_session_dir, ompi_comm_get_cid (module->comm),
607-
ompi_process_info.nodename);
617+
ret = asprintf (&data_file, "%s" OPAL_PATH_SEP "osc_rdma.%s.%x.%d",
618+
mca_osc_rdma_component.backing_directory, ompi_process_info.nodename,
619+
OMPI_PROC_MY_NAME->jobid, ompi_comm_get_cid(module->comm));
608620
if (0 > ret) {
609621
ret = OMPI_ERR_OUT_OF_RESOURCE;
610622
break;

ompi/mca/osc/sm/osc_sm.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ typedef struct ompi_osc_sm_node_state_t ompi_osc_sm_node_state_t;
6161

6262
struct ompi_osc_sm_component_t {
6363
ompi_osc_base_component_t super;
64+
65+
char *backing_directory;
6466
};
6567
typedef struct ompi_osc_sm_component_t ompi_osc_sm_component_t;
6668
OMPI_DECLSPEC extern ompi_osc_sm_component_t mca_osc_sm_component;

ompi/mca/osc/sm/osc_sm_component.c

Lines changed: 42 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ static int component_finalize(void);
3636
static int component_query(struct ompi_win_t *win, void **base, size_t size, int disp_unit,
3737
struct ompi_communicator_t *comm, struct opal_info_t *info,
3838
int flavor);
39+
static int component_register (void);
3940
static int component_select(struct ompi_win_t *win, void **base, size_t size, int disp_unit,
4041
struct ompi_communicator_t *comm, struct opal_info_t *info,
4142
int flavor, int *model);
@@ -51,6 +52,7 @@ ompi_osc_sm_component_t mca_osc_sm_component = {
5152
MCA_BASE_MAKE_VERSION(component, OMPI_MAJOR_VERSION, OMPI_MINOR_VERSION,
5253
OMPI_RELEASE_VERSION),
5354
.mca_open_component = component_open,
55+
.mca_register_component_params = component_register,
5456
},
5557
.osc_data = { /* mca_base_component_data */
5658
/* The component is not checkpoint ready */
@@ -105,6 +107,23 @@ ompi_osc_sm_module_t ompi_osc_sm_module_template = {
105107
}
106108
};
107109

110+
static int component_register (void)
111+
{
112+
if (0 == access ("/dev/shm", W_OK)) {
113+
mca_osc_sm_component.backing_directory = "/dev/shm";
114+
} else {
115+
mca_osc_sm_component.backing_directory = ompi_process_info.proc_session_dir;
116+
}
117+
118+
(void) mca_base_component_var_register (&mca_osc_sm_component.super.osc_version, "backing_directory",
119+
"Directory to place backing files for shared memory windows. "
120+
"This directory should be on a local filesystem such as /tmp or "
121+
"/dev/shm (default: (linux) /dev/shm, (others) session directory)",
122+
MCA_BASE_VAR_TYPE_STRING, NULL, 0, 0, OPAL_INFO_LVL_3,
123+
MCA_BASE_VAR_SCOPE_READONLY, &mca_osc_sm_component.backing_directory);
124+
125+
return OPAL_SUCCESS;
126+
}
108127

109128
static int
110129
component_open(void)
@@ -169,6 +188,7 @@ component_select(struct ompi_win_t *win, void **base, size_t size, int disp_unit
169188
{
170189
ompi_osc_sm_module_t *module = NULL;
171190
int comm_size = ompi_comm_size (comm);
191+
bool unlink_needed = false;
172192
int ret = OMPI_ERROR;
173193

174194
if (OMPI_SUCCESS != (ret = check_win_ok(comm, flavor))) {
@@ -262,10 +282,10 @@ component_select(struct ompi_win_t *win, void **base, size_t size, int disp_unit
262282
posts_size += OPAL_ALIGN_PAD_AMOUNT(posts_size, 64);
263283
if (0 == ompi_comm_rank (module->comm)) {
264284
char *data_file;
265-
if (asprintf(&data_file, "%s"OPAL_PATH_SEP"shared_window_%d.%s",
266-
ompi_process_info.proc_session_dir,
267-
ompi_comm_get_cid(module->comm),
268-
ompi_process_info.nodename) < 0) {
285+
ret = asprintf (&data_file, "%s" OPAL_PATH_SEP "osc_sm.%s.%x.%d",
286+
mca_osc_sm_component.backing_directory, ompi_process_info.nodename,
287+
OMPI_PROC_MY_NAME->jobid, ompi_comm_get_cid(module->comm));
288+
if (ret < 0) {
269289
return OMPI_ERR_OUT_OF_RESOURCE;
270290
}
271291

@@ -274,6 +294,8 @@ component_select(struct ompi_win_t *win, void **base, size_t size, int disp_unit
274294
if (OPAL_SUCCESS != ret) {
275295
goto error;
276296
}
297+
298+
unlink_needed = true;
277299
}
278300

279301
ret = module->comm->c_coll->coll_bcast (&module->seg_ds, sizeof (module->seg_ds), MPI_BYTE, 0,
@@ -287,6 +309,17 @@ component_select(struct ompi_win_t *win, void **base, size_t size, int disp_unit
287309
goto error;
288310
}
289311

312+
ret = module->comm->c_coll->coll_bcast (&module->seg_ds, sizeof (module->seg_ds), MPI_BYTE, 0,
313+
module->comm, module->comm->c_coll->coll_bcast_module);
314+
if (OMPI_SUCCESS != ret) {
315+
goto error;
316+
}
317+
318+
if (0 == ompi_comm_rank (module->comm)) {
319+
opal_shmem_unlink (&module->seg_ds);
320+
unlink_needed = false;
321+
}
322+
290323
module->sizes = malloc(sizeof(size_t) * comm_size);
291324
if (NULL == module->sizes) return OMPI_ERR_TEMP_OUT_OF_RESOURCE;
292325
module->bases = malloc(sizeof(void*) * comm_size);
@@ -399,6 +432,11 @@ component_select(struct ompi_win_t *win, void **base, size_t size, int disp_unit
399432
return OMPI_SUCCESS;
400433

401434
error:
435+
436+
if (0 == ompi_comm_rank (module->comm) && unlink_needed) {
437+
opal_shmem_unlink (&module->seg_ds);
438+
}
439+
402440
ompi_osc_sm_free (win);
403441

404442
return ret;
@@ -477,10 +515,6 @@ ompi_osc_sm_free(struct ompi_win_t *win)
477515
module->comm->c_coll->coll_barrier(module->comm,
478516
module->comm->c_coll->coll_barrier_module);
479517

480-
if (0 == ompi_comm_rank (module->comm)) {
481-
opal_shmem_unlink (&module->seg_ds);
482-
}
483-
484518
opal_shmem_segment_detach (&module->seg_ds);
485519
} else {
486520
free(module->node_states);

0 commit comments

Comments
 (0)