diff --git a/src/aiori-MMAP.c b/src/aiori-MMAP.c index f812bdd..dd6c649 100644 --- a/src/aiori-MMAP.c +++ b/src/aiori-MMAP.c @@ -32,6 +32,7 @@ static IOR_offset_t MMAP_Xfer(int, void *, IOR_size_t *, IOR_offset_t, IOR_param_t *); static void MMAP_Close(void *, IOR_param_t *); static void MMAP_Fsync(void *, IOR_param_t *); +static option_help * MMAP_options(void ** init_backend_options, void * init_values); /************************** D E C L A R A T I O N S ***************************/ @@ -45,9 +46,38 @@ ior_aiori_t mmap_aiori = { .get_version = aiori_get_version, .fsync = MMAP_Fsync, .get_file_size = POSIX_GetFileSize, + .get_options = MMAP_options, }; /***************************** F U N C T I O N S ******************************/ +typedef struct{ + int direct_io_ignored; /* this option is ignored */ + void* mmap_ptr; /* for internal usage */ + + int madv_dont_need; + int madv_pattern; +} mmap_options_t; + +static option_help * MMAP_options(void ** init_backend_options, void * init_values){ + mmap_options_t * o = malloc(sizeof(mmap_options_t)); + + if (init_values != NULL){ + memcpy(o, init_values, sizeof(mmap_options_t)); + }else{ + o->direct_io_ignored = 0; + } + + *init_backend_options = o; + + option_help h [] = { + {0, "mmap.madv_dont_need", "Use advise don't need", OPTION_FLAG, 'd', & o->madv_dont_need}, + {0, "mmap.madv_pattern", "Use advise to indicate the pattern random/sequential", OPTION_FLAG, 'd', & o->madv_pattern}, + LAST_OPTION + }; + option_help * help = malloc(sizeof(h)); + memcpy(help, h, sizeof(h)); + return help; +} static void ior_mmap_file(int *file, IOR_param_t *param) { @@ -56,21 +86,27 @@ static void ior_mmap_file(int *file, IOR_param_t *param) if (param->open == WRITE) flags |= PROT_WRITE; + mmap_options_t *o = (mmap_options_t*) param->backend_options; - param->mmap_ptr = mmap(NULL, size, flags, MAP_SHARED, + o->mmap_ptr = mmap(NULL, size, flags, MAP_SHARED, *file, 0); - if (param->mmap_ptr == MAP_FAILED) + if (o->mmap_ptr == MAP_FAILED) ERR("mmap() failed"); if (param->randomOffset) flags = POSIX_MADV_RANDOM; else flags = POSIX_MADV_SEQUENTIAL; - if (posix_madvise(param->mmap_ptr, size, flags) != 0) - ERR("madvise() failed"); + + if(o->madv_pattern){ + if (posix_madvise(o->mmap_ptr, size, flags) != 0) + ERR("madvise() failed"); + } - if (posix_madvise(param->mmap_ptr, size, POSIX_MADV_DONTNEED) != 0) - ERR("madvise() failed"); + if (o->madv_dont_need){ + if (posix_madvise(o->mmap_ptr, size, POSIX_MADV_DONTNEED) != 0) + ERR("madvise() failed"); + } return; } @@ -107,16 +143,17 @@ static void *MMAP_Open(char *testFileName, IOR_param_t * param) static IOR_offset_t MMAP_Xfer(int access, void *file, IOR_size_t * buffer, IOR_offset_t length, IOR_param_t * param) { + mmap_options_t *o = (mmap_options_t*) param->backend_options; if (access == WRITE) { - memcpy(param->mmap_ptr + param->offset, buffer, length); + memcpy(o->mmap_ptr + param->offset, buffer, length); } else { - memcpy(buffer, param->mmap_ptr + param->offset, length); + memcpy(buffer, o->mmap_ptr + param->offset, length); } if (param->fsyncPerWrite == TRUE) { - if (msync(param->mmap_ptr + param->offset, length, MS_SYNC) != 0) + if (msync(o->mmap_ptr + param->offset, length, MS_SYNC) != 0) ERR("msync() failed"); - if (posix_madvise(param->mmap_ptr + param->offset, length, + if (posix_madvise(o->mmap_ptr + param->offset, length, POSIX_MADV_DONTNEED) != 0) ERR("madvise() failed"); } @@ -128,7 +165,8 @@ static IOR_offset_t MMAP_Xfer(int access, void *file, IOR_size_t * buffer, */ static void MMAP_Fsync(void *fd, IOR_param_t * param) { - if (msync(param->mmap_ptr, param->expectedAggFileSize, MS_SYNC) != 0) + mmap_options_t *o = (mmap_options_t*) param->backend_options; + if (msync(o->mmap_ptr, param->expectedAggFileSize, MS_SYNC) != 0) EWARN("msync() failed"); } @@ -137,8 +175,9 @@ static void MMAP_Fsync(void *fd, IOR_param_t * param) */ static void MMAP_Close(void *fd, IOR_param_t * param) { - if (munmap(param->mmap_ptr, param->expectedAggFileSize) != 0) + mmap_options_t *o = (mmap_options_t*) param->backend_options; + if (munmap(o->mmap_ptr, param->expectedAggFileSize) != 0) ERR("munmap failed"); - param->mmap_ptr = NULL; + o->mmap_ptr = NULL; POSIX_Close(fd, param); } diff --git a/src/aiori-POSIX.c b/src/aiori-POSIX.c index a446459..9e85fa7 100755 --- a/src/aiori-POSIX.c +++ b/src/aiori-POSIX.c @@ -74,11 +74,12 @@ static void POSIX_Fsync(void *, IOR_param_t *); /************************** O P T I O N S *****************************/ typedef struct{ + /* in case of a change, please update depending MMAP module too */ int direct_io; } posix_options_t; -static option_help * posix_options(void ** init_backend_options, void * init_values){ +option_help * POSIX_options(void ** init_backend_options, void * init_values){ posix_options_t * o = malloc(sizeof(posix_options_t)); if (init_values != NULL){ @@ -118,7 +119,7 @@ ior_aiori_t posix_aiori = { .rmdir = aiori_posix_rmdir, .access = aiori_posix_access, .stat = aiori_posix_stat, - .get_options = posix_options, + .get_options = POSIX_options, .enable_mdtest = true, }; diff --git a/src/aiori.h b/src/aiori.h index 782d1ac..d8cabb5 100755 --- a/src/aiori.h +++ b/src/aiori.h @@ -129,6 +129,8 @@ void *POSIX_Open(char *testFileName, IOR_param_t * param); IOR_offset_t POSIX_GetFileSize(IOR_param_t * test, MPI_Comm testComm, char *testFileName); void POSIX_Delete(char *testFileName, IOR_param_t * param); void POSIX_Close(void *fd, IOR_param_t * param); +option_help * POSIX_options(void ** init_backend_options, void * init_values); + /* NOTE: these 3 MPI-IO functions are exported for reuse by HDF5/PNetCDF */ void MPIIO_Delete(char *testFileName, IOR_param_t * param); diff --git a/src/ior.c b/src/ior.c index a1dc321..3ef411c 100755 --- a/src/ior.c +++ b/src/ior.c @@ -218,8 +218,6 @@ void init_IOR_Param_t(IOR_param_t * p) p->beegfs_numTargets = -1; p->beegfs_chunkSize = -1; - - p->mmap_ptr = NULL; } static void diff --git a/src/ior.h b/src/ior.h index acf3a7d..da4e5c1 100755 --- a/src/ior.h +++ b/src/ior.h @@ -162,8 +162,6 @@ typedef struct int fsyncPerWrite; /* fsync() after each write */ int fsync; /* fsync() after write */ - void* mmap_ptr; - /* MPI variables */ MPI_Comm testComm; /* MPI communicator */ MPI_Datatype transferType; /* datatype for transfer */