1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
2 /*
3 * Copyright (c) 2004-2008 The Trustees of Indiana University and Indiana
4 * University Research and Technology
5 * Corporation. All rights reserved.
6 * Copyright (c) 2004-2005 The University of Tennessee and The University
7 * of Tennessee Research Foundation. All rights
8 * reserved.
9 * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
10 * University of Stuttgart. All rights reserved.
11 * Copyright (c) 2004-2005 The Regents of the University of California.
12 * All rights reserved.
13 * Copyright (c) 2007-2015 Cisco Systems, Inc. All rights reserved.
14 * Copyright (c) 2010-2015 Los Alamos National Security, LLC. All rights
15 * reserved.
16 * Copyright (c) 2016 Intel, Inc. All rights reserved.
17 * $COPYRIGHT$
18 *
19 * Additional copyrights may follow
20 *
21 * $HEADER$
22 *
23 * These symbols are in a file by themselves to provide nice linker
24 * semantics. Since linkers generally pull in symbols by object
25 * files, keeping these symbols as the only symbols in this file
26 * prevents utility programs such as "ompi_info" from having to import
27 * entire components just to query their version and parameters.
28 */
29
30 #include "opal_config.h"
31
32 #include "opal/constants.h"
33 #include "opal/mca/shmem/shmem.h"
34 #include "shmem_mmap.h"
35
36 /**
37 * public string showing the shmem ompi_mmap component version number
38 */
39 const char *opal_shmem_mmap_component_version_string =
40 "OPAL mmap shmem MCA component version " OPAL_VERSION;
41
42 int opal_shmem_mmap_relocate_backing_file = 0;
43 char *opal_shmem_mmap_backing_file_base_dir = NULL;
44 bool opal_shmem_mmap_nfs_warning = true;
45
46 /**
47 * local functions
48 */
49 static int mmap_register(void);
50 static int mmap_open(void);
51 static int mmap_close(void);
52 static int mmap_query(mca_base_module_t **module, int *priority);
53 static int mmap_runtime_query(mca_base_module_t **module,
54 int *priority,
55 const char *hint);
56
57 /**
58 * instantiate the public struct with all of our public information
59 * and pointers to our public functions in it
60 */
61 opal_shmem_mmap_component_t mca_shmem_mmap_component = {
62 .super = {
63 .base_version = {
64 OPAL_SHMEM_BASE_VERSION_2_0_0,
65
66 /* component name and version */
67 .mca_component_name = "mmap",
68 MCA_BASE_MAKE_VERSION(component, OPAL_MAJOR_VERSION, OPAL_MINOR_VERSION,
69 OPAL_RELEASE_VERSION),
70
71 .mca_open_component = mmap_open,
72 .mca_close_component = mmap_close,
73 .mca_query_component = mmap_query,
74 .mca_register_component_params = mmap_register,
75 },
76 /* MCA v2.0.0 component meta data */
77 .base_data = {
78 /* the component is checkpoint ready */
79 MCA_BASE_METADATA_PARAM_CHECKPOINT
80 },
81 .runtime_query = mmap_runtime_query,
82 },
83 };
84
85 /* ////////////////////////////////////////////////////////////////////////// */
86 static int
87 mmap_runtime_query(mca_base_module_t **module,
88 int *priority,
89 const char *hint)
90 {
91 /* no run-time query needed for mmap, so this is easy */
92 *priority = mca_shmem_mmap_component.priority;
93 *module = (mca_base_module_t *)&opal_shmem_mmap_module.super;
94 return OPAL_SUCCESS;
95 }
96
97 static int
98 mmap_register(void)
99 {
100 int ret;
101
102
103 /* ////////////////////////////////////////////////////////////////////// */
104 /* (default) priority - set high to make mmap the default */
105 mca_shmem_mmap_component.priority = 50;
106 ret = mca_base_component_var_register (&mca_shmem_mmap_component.super.base_version,
107 "priority", "Priority for shmem mmap "
108 "component (default: 50)", MCA_BASE_VAR_TYPE_INT,
109 NULL, 0, MCA_BASE_VAR_FLAG_SETTABLE,
110 OPAL_INFO_LVL_3,
111 MCA_BASE_VAR_SCOPE_ALL_EQ,
112 &mca_shmem_mmap_component.priority);
113
114 /*
115 * Do we want the "warning: your mmap file is on NFS!" message? Per a
116 * thread on the OMPI devel list
117 * (http://www.open-mpi.org/community/lists/devel/2011/12/10054.php),
118 * on some systems, it doesn't seem to matter. But per older threads,
119 * it definitely does matter on some systems. Perhaps newer kernels
120 * are smarter about this kind of stuff...? Regardless, we should
121 * provide the ability to turn off this message for systems where the
122 * effect doesn't matter.
123 */
124 opal_shmem_mmap_nfs_warning = true;
125 ret = mca_base_component_var_register (&mca_shmem_mmap_component.super.base_version,
126 "enable_nfs_warning",
127 "Enable the warning emitted when Open MPI detects "
128 "that its shared memory backing file is located on "
129 "a network filesystem (1 = enabled, 0 = disabled).",
130 MCA_BASE_VAR_TYPE_BOOL, NULL, 0, MCA_BASE_VAR_FLAG_SETTABLE,
131 OPAL_INFO_LVL_9, MCA_BASE_VAR_SCOPE_LOCAL,
132 &opal_shmem_mmap_nfs_warning);
133 if (0 > ret) {
134 return ret;
135 }
136
137 opal_shmem_mmap_relocate_backing_file = 0;
138 ret = mca_base_component_var_register (&mca_shmem_mmap_component.super.base_version,
139 "relocate_backing_file",
140 "Whether to change the default placement of backing files or not "
141 "(Negative = try to relocate backing files to an area rooted at "
142 "the path specified by "
143 "shmem_mmap_backing_file_base_dir, but continue "
144 "with the default path if the relocation fails, 0 = do not relocate, "
145 "Positive = same as the negative option, but will fail if the "
146 "relocation fails.", MCA_BASE_VAR_TYPE_INT, NULL, 0,
147 MCA_BASE_VAR_FLAG_SETTABLE, OPAL_INFO_LVL_9,
148 MCA_BASE_VAR_SCOPE_ALL_EQ, &opal_shmem_mmap_relocate_backing_file);
149 if (0 > ret) {
150 return ret;
151 }
152
153 opal_shmem_mmap_backing_file_base_dir = "/dev/shm";
154 ret = mca_base_component_var_register (&mca_shmem_mmap_component.super.base_version,
155 "backing_file_base_dir",
156 "Specifies where backing files will be created when "
157 "shmem_mmap_relocate_backing_file is in use.", MCA_BASE_VAR_TYPE_STRING,
158 NULL, 0, MCA_BASE_VAR_FLAG_SETTABLE, OPAL_INFO_LVL_9,
159 MCA_BASE_VAR_SCOPE_ALL_EQ,
160 &opal_shmem_mmap_backing_file_base_dir);
161 if (0 > ret) {
162 return ret;
163 }
164
165 return OPAL_SUCCESS;
166 }
167
168 /* ////////////////////////////////////////////////////////////////////////// */
169 static int
170 mmap_open(void)
171 {
172 return OPAL_SUCCESS;
173 }
174
175 /* ////////////////////////////////////////////////////////////////////////// */
176 static int
177 mmap_query(mca_base_module_t **module, int *priority)
178 {
179 *priority = mca_shmem_mmap_component.priority;
180 *module = (mca_base_module_t *)&opal_shmem_mmap_module.super;
181 return OPAL_SUCCESS;
182 }
183
184 /* ////////////////////////////////////////////////////////////////////////// */
185 static int
186 mmap_close(void)
187 {
188 return OPAL_SUCCESS;
189 }
190