1
1

bcol/basesmuma: fix leak in basesmuma code

Basesmuma was vallocing space for control data then mmapping over that
data. Nothing in the code suggests any need for mmapping a specific
address so I did the following to remove the leak:

 - Removed the valloc of the buffer space

 - ftruncate the mmaped file to ensure there is sufficient memory to
   allocate space for the control data.

Ideally this code should be using opal/shmem but that is a larger
change. Keeping it simple for now.

cmr=v1.8.2:reviewer=manjugv

This commit was SVN r31822.
Этот коммит содержится в:
Nathan Hjelm 2014-05-19 15:21:58 +00:00
родитель dedf6b377e
Коммит 22e59b056a
2 изменённых файлов: 19 добавлений и 17 удалений

Просмотреть файл

@ -23,11 +23,9 @@
#include "ompi/mca/mpool/base/base.h"
#include "ompi/mca/bcol/bcol.h"
#include "ompi/mca/bcol/base/base.h"
#include "opal/align.h"
#include "bcol_basesmuma.h"
#define ROUND_UP_POW2(x, y) (((x) + ((y) - 1)) & ~((y) - 1))
/*
* Public string showing the coll ompi_sm V2 component version number
*/
@ -291,6 +289,9 @@ static int mca_bcol_basesmuma_deregister_ctl_sm(mca_bcol_basesmuma_component_t *
}
#endif
free (bcol_component->sm_ctl_structs);
bcol_component->sm_ctl_structs = NULL;
return OMPI_SUCCESS;
}
@ -313,7 +314,6 @@ static int basesmuma_close(void)
}
OBJ_DESTRUCT(&(cs->ctl_structures));
/* deregister the progress function */
ret=opal_progress_unregister(bcol_basesmuma_progress);
if (MPI_SUCCESS != ret) {
@ -369,7 +369,7 @@ int mca_bcol_basesmuma_allocate_sm_ctl_memory(mca_bcol_basesmuma_component_t *cs
/* local variables */
int name_length, ret;
size_t ctl_length;
char *name, *ctl_mem;
char *name;
size_t page_size = getpagesize ();
/* set the file name */
@ -400,18 +400,10 @@ int mca_bcol_basesmuma_allocate_sm_ctl_memory(mca_bcol_basesmuma_component_t *cs
ctl_length+=cs->my_scratch_shared_memory_size;
/* round up to multiple of page size */
ctl_length = ROUND_UP_POW2(ctl_length, page_size);
/* allocate memory that will be mmaped */
ctl_mem=(char *)valloc(ctl_length);
if( !ctl_mem) {
opal_output (ompi_bcol_base_framework.framework_output, "failed to allocate bcol/basesmuma control memory");
return OMPI_ERR_OUT_OF_RESOURCE;
}
ctl_length = OPAL_ALIGN(ctl_length, page_size, size_t);
/* allocate the shared file */
cs->sm_ctl_structs=bcol_basesmuma_smcm_mem_reg(ctl_mem,
ctl_length,getpagesize(),name);
cs->sm_ctl_structs=bcol_basesmuma_smcm_mem_reg (NULL, ctl_length, getpagesize(), name);
if( !cs->sm_ctl_structs) {
opal_output (ompi_bcol_base_framework.framework_output,
"In mca_bcol_basesmuma_allocate_sm_ctl_memory failed to allocathe backing file %s\n", name);

Просмотреть файл

@ -27,13 +27,13 @@
#include "ompi/proc/proc.h"
#include "ompi/patterns/comm/coll_ops.h"
#include "opal/align.h"
#include "opal/dss/dss.h"
#include "opal/util/error.h"
#include "opal/util/output.h"
#include "opal/class/opal_list.h"
#include "opal/class/opal_hash_table.h"
#include "opal/align.h"
#include "bcol_basesmuma.h"
@ -400,6 +400,8 @@ bcol_basesmuma_smcm_mmap_t *bcol_basesmuma_smcm_mem_reg(void *in_ptr,
/* local variables */
int fd = -1;
bcol_basesmuma_smcm_mmap_t *map = NULL;
int rc;
/* if pointer is not allocated - return error. We have no clue how the user will allocate or
* free this memory.
*/
@ -414,6 +416,12 @@ bcol_basesmuma_smcm_mmap_t *bcol_basesmuma_smcm_mem_reg(void *in_ptr,
opal_output (ompi_bcol_base_framework.framework_output, "basesmuma shared memory allocation ftruncate failed with errno: %d",
errno);
} else {
/* ensure there is enough space for the backing store */
rc = ftruncate (fd, length);
if (0 > rc) {
opal_output (ompi_bcol_base_framework.framework_output, "failed to truncate the file to be mapped. errno: %d", errno);
return NULL;
}
map = bcol_basesmuma_smcm_reg_mmap(in_ptr, fd, length, alignment, file_name);
if (NULL == map) {
@ -462,7 +470,9 @@ bcol_basesmuma_smcm_mmap_t * bcol_basesmuma_smcm_reg_mmap(void *in_ptr,
myaddr = (unsigned char *) seg;
/* if we have a data segment (i.e. if 0 != data_seg_alignement) */
if ( 0 != alignment) {
/* all mmaped regions are required to be at least page size aligned so this
* code does nothing unless you want greater alignment */
if (alignment > getpagesize ()) {
myaddr = OPAL_ALIGN_PTR(myaddr, alignment, unsigned char*);
/* is addr past the end of the file? */