Skip to content

Commit 1275766

Browse files
authored
Merge pull request #7207 from devreal/remove_shmem_seg_hdr
Remove unused opal_shmem_seg_hdr_t to retain alignment
2 parents 9f4365f + ee80bab commit 1275766

File tree

4 files changed

+42
-98
lines changed

4 files changed

+42
-98
lines changed

opal/mca/shmem/mmap/shmem_mmap_module.c

Lines changed: 16 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ shmem_ds_reset(opal_shmem_ds_t *ds_buf)
136136
ds_buf->seg_id = OPAL_SHMEM_DS_ID_INVALID;
137137
ds_buf->seg_size = 0;
138138
memset(ds_buf->seg_name, '\0', OPAL_PATH_MAX);
139-
ds_buf->seg_base_addr = (unsigned char *)MAP_FAILED;
139+
ds_buf->seg_base_addr = MAP_FAILED;
140140
}
141141

142142
/* ////////////////////////////////////////////////////////////////////////// */
@@ -306,12 +306,7 @@ segment_create(opal_shmem_ds_t *ds_buf,
306306
pid_t my_pid = getpid();
307307
bool space_available = false;
308308
uint64_t amount_space_avail = 0;
309-
310-
/* the real size of the shared memory segment. this includes enough space
311-
* to store our segment header.
312-
*/
313-
size_t real_size = size + sizeof(opal_shmem_seg_hdr_t);
314-
opal_shmem_seg_hdr_t *seg_hdrp = MAP_FAILED;
309+
void *segment = MAP_FAILED;
315310

316311
/* init the contents of opal_shmem_ds_t */
317312
shmem_ds_reset(ds_buf);
@@ -375,8 +370,7 @@ segment_create(opal_shmem_ds_t *ds_buf,
375370
real_file_name);
376371
}
377372
/* let's make sure we have enough space for the backing file */
378-
if (OPAL_SUCCESS != (rc = enough_space(real_file_name,
379-
real_size,
373+
if (OPAL_SUCCESS != (rc = enough_space(real_file_name, size,
380374
&amount_space_avail,
381375
&space_available))) {
382376
opal_output(0, "shmem: mmap: an error occurred while determining "
@@ -389,7 +383,7 @@ segment_create(opal_shmem_ds_t *ds_buf,
389383
hn = opal_gethostname();
390384
rc = OPAL_ERR_OUT_OF_RESOURCE;
391385
opal_show_help("help-opal-shmem-mmap.txt", "target full", 1,
392-
real_file_name, hn, (unsigned long)real_size,
386+
real_file_name, hn, (unsigned long)size,
393387
(unsigned long long)amount_space_avail);
394388
goto out;
395389
}
@@ -403,8 +397,8 @@ segment_create(opal_shmem_ds_t *ds_buf,
403397
rc = OPAL_ERROR;
404398
goto out;
405399
}
406-
/* size backing file - note the use of real_size here */
407-
if (0 != ftruncate(ds_buf->seg_id, real_size)) {
400+
/* size backing file */
401+
if (0 != ftruncate(ds_buf->seg_id, size)) {
408402
int err = errno;
409403
const char *hn;
410404
hn = opal_gethostname();
@@ -413,8 +407,7 @@ segment_create(opal_shmem_ds_t *ds_buf,
413407
rc = OPAL_ERROR;
414408
goto out;
415409
}
416-
if (MAP_FAILED == (seg_hdrp = (opal_shmem_seg_hdr_t *)
417-
mmap(NULL, real_size,
410+
if (MAP_FAILED == (segment = mmap(NULL, size,
418411
PROT_READ | PROT_WRITE, MAP_SHARED,
419412
ds_buf->seg_id, 0))) {
420413
int err = errno;
@@ -427,20 +420,11 @@ segment_create(opal_shmem_ds_t *ds_buf,
427420
}
428421
/* all is well */
429422
else {
430-
/* -- initialize the shared memory segment -- */
431-
opal_atomic_rmb();
432-
433-
/* init segment lock */
434-
opal_atomic_lock_init(&seg_hdrp->lock, OPAL_ATOMIC_LOCK_UNLOCKED);
435-
/* i was the creator of this segment, so note that fact */
436-
seg_hdrp->cpid = my_pid;
437-
438-
opal_atomic_wmb();
439423

440424
/* -- initialize the contents of opal_shmem_ds_t -- */
441425
ds_buf->seg_cpid = my_pid;
442-
ds_buf->seg_size = real_size;
443-
ds_buf->seg_base_addr = (unsigned char *)seg_hdrp;
426+
ds_buf->seg_size = size;
427+
ds_buf->seg_base_addr = segment;
444428
(void)opal_string_copy(ds_buf->seg_name, real_file_name, OPAL_PATH_MAX);
445429

446430
/* set "valid" bit because setment creation was successful */
@@ -474,8 +458,8 @@ segment_create(opal_shmem_ds_t *ds_buf,
474458
}
475459
/* an error occured, so invalidate the shmem object and munmap if needed */
476460
if (OPAL_SUCCESS != rc) {
477-
if (MAP_FAILED != seg_hdrp) {
478-
munmap((void *)seg_hdrp, real_size);
461+
if (MAP_FAILED != segment) {
462+
munmap(segment, size);
479463
}
480464
shmem_ds_reset(ds_buf);
481465
}
@@ -504,10 +488,9 @@ segment_attach(opal_shmem_ds_t *ds_buf)
504488
"open(2)", "", strerror(err), err);
505489
return NULL;
506490
}
507-
if (MAP_FAILED == (ds_buf->seg_base_addr = (unsigned char *)
508-
mmap(NULL, ds_buf->seg_size,
509-
PROT_READ | PROT_WRITE, MAP_SHARED,
510-
ds_buf->seg_id, 0))) {
491+
if (MAP_FAILED == (ds_buf->seg_base_addr = mmap(NULL, ds_buf->seg_size,
492+
PROT_READ | PROT_WRITE, MAP_SHARED,
493+
ds_buf->seg_id, 0))) {
511494
int err = errno;
512495
const char *hn;
513496
hn = opal_gethostname();
@@ -545,7 +528,7 @@ segment_attach(opal_shmem_ds_t *ds_buf)
545528
);
546529

547530
/* update returned base pointer with an offset that hides our stuff */
548-
return (ds_buf->seg_base_addr + sizeof(opal_shmem_seg_hdr_t));
531+
return ds_buf->seg_base_addr;
549532
}
550533

551534
/* ////////////////////////////////////////////////////////////////////////// */
@@ -563,7 +546,7 @@ segment_detach(opal_shmem_ds_t *ds_buf)
563546
ds_buf->seg_id, (unsigned long)ds_buf->seg_size, ds_buf->seg_name)
564547
);
565548

566-
if (0 != munmap((void *)ds_buf->seg_base_addr, ds_buf->seg_size)) {
549+
if (0 != munmap(ds_buf->seg_base_addr, ds_buf->seg_size)) {
567550
int err = errno;
568551
const char *hn;
569552
hn = opal_gethostname();

opal/mca/shmem/posix/shmem_posix_module.c

Lines changed: 16 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ shmem_ds_reset(opal_shmem_ds_t *ds_buf)
126126
ds_buf->seg_id = OPAL_SHMEM_DS_ID_INVALID;
127127
ds_buf->seg_size = 0;
128128
memset(ds_buf->seg_name, '\0', OPAL_PATH_MAX);
129-
ds_buf->seg_base_addr = (unsigned char *)MAP_FAILED;
129+
ds_buf->seg_base_addr = MAP_FAILED;
130130
}
131131

132132
/* ////////////////////////////////////////////////////////////////////////// */
@@ -177,11 +177,7 @@ segment_create(opal_shmem_ds_t *ds_buf,
177177
{
178178
int rc = OPAL_SUCCESS;
179179
pid_t my_pid = getpid();
180-
/* the real size of the shared memory segment. this includes enough space
181-
* to store our segment header.
182-
*/
183-
size_t real_size = size + sizeof(opal_shmem_seg_hdr_t);
184-
opal_shmem_seg_hdr_t *seg_hdrp = MAP_FAILED;
180+
void *segment = MAP_FAILED;
185181

186182
/* init the contents of opal_shmem_ds_t */
187183
shmem_ds_reset(ds_buf);
@@ -203,8 +199,8 @@ segment_create(opal_shmem_ds_t *ds_buf,
203199
rc = OPAL_ERROR;
204200
goto out;
205201
}
206-
/* size backing file - note the use of real_size here */
207-
else if (0 != ftruncate(ds_buf->seg_id, real_size)) {
202+
/* size backing file */
203+
else if (0 != ftruncate(ds_buf->seg_id, size)) {
208204
int err = errno;
209205
const char *hn;
210206
hn = opal_gethostname();
@@ -213,9 +209,9 @@ segment_create(opal_shmem_ds_t *ds_buf,
213209
rc = OPAL_ERROR;
214210
goto out;
215211
}
216-
else if (MAP_FAILED == (seg_hdrp = (opal_shmem_seg_hdr_t*)mmap(NULL, real_size,
217-
PROT_READ | PROT_WRITE, MAP_SHARED,
218-
ds_buf->seg_id, 0))) {
212+
else if (MAP_FAILED == (segment = mmap(NULL, size,
213+
PROT_READ | PROT_WRITE, MAP_SHARED,
214+
ds_buf->seg_id, 0))) {
219215
int err = errno;
220216
const char *hn;
221217
hn = opal_gethostname();
@@ -226,20 +222,11 @@ segment_create(opal_shmem_ds_t *ds_buf,
226222
}
227223
/* all is well */
228224
else {
229-
/* -- initialize the shared memory segment -- */
230-
opal_atomic_rmb();
231-
232-
/* init segment lock */
233-
opal_atomic_lock_init(&seg_hdrp->lock, OPAL_ATOMIC_LOCK_UNLOCKED);
234-
/* i was the creator of this segment, so note that fact */
235-
seg_hdrp->cpid = my_pid;
236-
237-
opal_atomic_wmb();
238225

239226
/* -- initialize the contents of opal_shmem_ds_t -- */
240227
ds_buf->seg_cpid = my_pid;
241-
ds_buf->seg_size = real_size;
242-
ds_buf->seg_base_addr = (unsigned char *)seg_hdrp;
228+
ds_buf->seg_size = size;
229+
ds_buf->seg_base_addr = segment;
243230

244231
/* notice that we are not setting ds_buf->name here. at this point,
245232
* posix_shm_open was successful, so the contents of ds_buf->name are
@@ -286,8 +273,8 @@ segment_create(opal_shmem_ds_t *ds_buf,
286273
if (-1 != ds_buf->seg_id) {
287274
shm_unlink(ds_buf->seg_name);
288275
}
289-
if (MAP_FAILED != seg_hdrp) {
290-
munmap((void*)seg_hdrp, real_size);
276+
if (MAP_FAILED != segment) {
277+
munmap((void*)segment, size);
291278
}
292279
/* always invalidate in this error path */
293280
shmem_ds_reset(ds_buf);
@@ -313,10 +300,9 @@ segment_attach(opal_shmem_ds_t *ds_buf)
313300
"open(2)", "", strerror(err), err);
314301
return NULL;
315302
}
316-
else if (MAP_FAILED == (ds_buf->seg_base_addr =
317-
(unsigned char*)mmap(NULL, ds_buf->seg_size,
318-
PROT_READ | PROT_WRITE, MAP_SHARED,
319-
ds_buf->seg_id, 0))) {
303+
else if (MAP_FAILED == (ds_buf->seg_base_addr = mmap(NULL, ds_buf->seg_size,
304+
PROT_READ | PROT_WRITE, MAP_SHARED,
305+
ds_buf->seg_id, 0))) {
320306
int err = errno;
321307
const char *hn;
322308
hn = opal_gethostname();
@@ -356,7 +342,7 @@ segment_attach(opal_shmem_ds_t *ds_buf)
356342
);
357343

358344
/* update returned base pointer with an offset that hides our stuff */
359-
return (ds_buf->seg_base_addr + sizeof(opal_shmem_seg_hdr_t));
345+
return ds_buf->seg_base_addr;
360346
}
361347

362348
/* ////////////////////////////////////////////////////////////////////////// */
@@ -374,7 +360,7 @@ segment_detach(opal_shmem_ds_t *ds_buf)
374360
ds_buf->seg_id, (unsigned long)ds_buf->seg_size, ds_buf->seg_name)
375361
);
376362

377-
if (0 != munmap((void*)ds_buf->seg_base_addr, ds_buf->seg_size)) {
363+
if (0 != munmap(ds_buf->seg_base_addr, ds_buf->seg_size)) {
378364
int err = errno;
379365
const char *hn;
380366
hn = opal_gethostname();

opal/mca/shmem/shmem_types.h

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
#define OPAL_SHMEM_TYPES_H
3333

3434
#include "opal_config.h"
35-
#include "opal/align.h"
3635

3736
#include <stddef.h>
3837
#include <string.h>
@@ -98,15 +97,6 @@ do { \
9897

9998
typedef uint8_t opal_shmem_ds_flag_t;
10099

101-
/* shared memory segment header */
102-
struct opal_shmem_seg_hdr_t {
103-
/* segment lock */
104-
opal_atomic_lock_t lock;
105-
/* pid of the segment creator */
106-
pid_t cpid;
107-
} __opal_attribute_aligned__(OPAL_ALIGN_MIN);
108-
typedef struct opal_shmem_seg_hdr_t opal_shmem_seg_hdr_t;
109-
110100
struct opal_shmem_ds_t {
111101
/* pid of the shared memory segment creator */
112102
pid_t seg_cpid;
@@ -117,7 +107,7 @@ struct opal_shmem_ds_t {
117107
/* size of shared memory segment */
118108
size_t seg_size;
119109
/* base address of shared memory segment */
120-
unsigned char *seg_base_addr;
110+
void *seg_base_addr;
121111
/* path to backing store -- last element so we can easily calculate the
122112
* "real" size of opal_shmem_ds_t. that is, the amount of the struct that
123113
* is actually being used. for example: if seg_name is something like:

opal/mca/shmem/sysv/shmem_sysv_module.c

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -179,11 +179,7 @@ segment_create(opal_shmem_ds_t *ds_buf,
179179
{
180180
int rc = OPAL_SUCCESS;
181181
pid_t my_pid = getpid();
182-
/* the real size of the shared memory segment. this includes enough space
183-
* to store our segment header.
184-
*/
185-
size_t real_size = size + sizeof(opal_shmem_seg_hdr_t);
186-
opal_shmem_seg_hdr_t *seg_hdrp = MAP_FAILED;
182+
void *segment = MAP_FAILED;
187183

188184
/* init the contents of opal_shmem_ds_t */
189185
shmem_ds_reset(ds_buf);
@@ -192,10 +188,8 @@ segment_create(opal_shmem_ds_t *ds_buf,
192188
* being located on a network file system... so no check is needed here.
193189
*/
194190

195-
/* create a new shared memory segment and save the shmid. note the use of
196-
* real_size here
197-
*/
198-
if (-1 == (ds_buf->seg_id = shmget(IPC_PRIVATE, real_size,
191+
/* create a new shared memory segment and save the shmid. */
192+
if (-1 == (ds_buf->seg_id = shmget(IPC_PRIVATE, size,
199193
IPC_CREAT | IPC_EXCL | S_IRWXU))) {
200194
int err = errno;
201195
const char *hn;
@@ -206,7 +200,7 @@ segment_create(opal_shmem_ds_t *ds_buf,
206200
goto out;
207201
}
208202
/* attach to the sement */
209-
else if ((void *)-1 == (seg_hdrp = shmat(ds_buf->seg_id, NULL, 0))) {
203+
else if ((void *)-1 == (segment = shmat(ds_buf->seg_id, NULL, 0))) {
210204
int err = errno;
211205
const char *hn;
212206
hn = opal_gethostname();
@@ -231,20 +225,11 @@ segment_create(opal_shmem_ds_t *ds_buf,
231225
}
232226
/* all is well */
233227
else {
234-
/* -- initialize the shared memory segment -- */
235-
opal_atomic_rmb();
236-
237-
/* init segment lock */
238-
opal_atomic_lock_init(&seg_hdrp->lock, OPAL_ATOMIC_LOCK_UNLOCKED);
239-
/* i was the creator of this segment, so note that fact */
240-
seg_hdrp->cpid = my_pid;
241-
242-
opal_atomic_wmb();
243228

244229
/* -- initialize the contents of opal_shmem_ds_t -- */
245230
ds_buf->seg_cpid = my_pid;
246-
ds_buf->seg_size = real_size;
247-
ds_buf->seg_base_addr = (unsigned char *)seg_hdrp;
231+
ds_buf->seg_size = size;
232+
ds_buf->seg_base_addr = (unsigned char *)segment;
248233

249234
/* notice that we are not setting ds_buf->name here. sysv doesn't use
250235
* it, so don't worry about it - shmem_ds_reset took care of
@@ -270,8 +255,8 @@ segment_create(opal_shmem_ds_t *ds_buf,
270255
*/
271256
if (OPAL_SUCCESS != rc) {
272257
/* best effort to delete the segment. */
273-
if ((void *)-1 != seg_hdrp) {
274-
shmdt((char*)seg_hdrp);
258+
if ((void *)-1 != segment) {
259+
shmdt((char*)segment);
275260
}
276261
shmctl(ds_buf->seg_id, IPC_RMID, NULL);
277262

@@ -316,7 +301,7 @@ segment_attach(opal_shmem_ds_t *ds_buf)
316301
);
317302

318303
/* update returned base pointer with an offset that hides our stuff */
319-
return (ds_buf->seg_base_addr + sizeof(opal_shmem_seg_hdr_t));
304+
return ds_buf->seg_base_addr;
320305
}
321306

322307
/* ////////////////////////////////////////////////////////////////////////// */

0 commit comments

Comments
 (0)