Commit 12443c86 authored by Philip Carns's avatar Philip Carns

cleanups to mmap allocation mode

- differentiate file names by rank to allow single node tests
- use fallocate instead of fopen/fwrite to generate file
- error checking
parent 045f28c8
...@@ -44,8 +44,8 @@ struct options ...@@ -44,8 +44,8 @@ struct options
#define BW_TOTAL_MEM_SIZE 2147483648UL #define BW_TOTAL_MEM_SIZE 2147483648UL
static void* custom_mmap_alloc(const char* filename, size_t size); static void* custom_mmap_alloc(const char* filename, size_t size, int rank);
static void custom_mmap_free(const char* filename, void* addr, size_t size); static void custom_mmap_free(const char* filename, void* addr, size_t size, int rank);
static int parse_args(int argc, char **argv, struct options *opts); static int parse_args(int argc, char **argv, struct options *opts);
static void usage(void); static void usage(void);
...@@ -123,7 +123,7 @@ int main(int argc, char **argv) ...@@ -123,7 +123,7 @@ int main(int argc, char **argv)
if(g_opts.mmap_filename == NULL) { if(g_opts.mmap_filename == NULL) {
g_buffer = calloc(g_buffer_size, 1); g_buffer = calloc(g_buffer_size, 1);
} else { } else {
g_buffer = custom_mmap_alloc(g_opts.mmap_filename, g_buffer_size); g_buffer = custom_mmap_alloc(g_opts.mmap_filename, g_buffer_size, rank);
} }
if(!g_buffer) if(!g_buffer)
...@@ -267,7 +267,7 @@ int main(int argc, char **argv) ...@@ -267,7 +267,7 @@ int main(int argc, char **argv)
if(g_opts.mmap_filename == NULL) { if(g_opts.mmap_filename == NULL) {
free(g_buffer); free(g_buffer);
} else { } else {
custom_mmap_free(g_opts.mmap_filename, g_buffer, g_buffer_size); custom_mmap_free(g_opts.mmap_filename, g_buffer, g_buffer_size, rank);
} }
margo_finalize(mid); margo_finalize(mid);
...@@ -591,33 +591,49 @@ static void bw_worker(void *_arg) ...@@ -591,33 +591,49 @@ static void bw_worker(void *_arg)
return; return;
} }
static void* custom_mmap_alloc(const char* filename, size_t size) static void* custom_mmap_alloc(const char* filename, size_t size, int rank)
{ {
FILE *fptr; int fd;
fptr = fopen(filename, "w"); int ret;
assert(fptr); void *addr;
char data[1024]; char local_filename[256] = {0};
memset(data, 0, 1024);
size_t remaining = size; /* make filename unique per rank in case two procs are on the same node */
while(remaining) { sprintf(local_filename, "%s.%d", filename, rank);
if(remaining > 1024) {
fwrite(data, 1, 1024, fptr); fd = open(local_filename, O_CREAT|O_EXCL|O_RDWR, S_IRUSR|S_IWUSR);
remaining -= 1024; if(!fd)
} else { {
fwrite(data, 1, remaining, fptr); perror("creat");
remaining = 0; return(NULL);
} }
}
fclose(fptr); ret = posix_fallocate(fd, 0, size);
int fd = open(filename, O_RDWR); if(ret != 0)
assert(fd); {
void* addr = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_POPULATE, fd, 0); perror("posix_fallocate");
close(fd); return(NULL);
return addr; }
addr = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_POPULATE, fd, 0);
if(addr == MAP_FAILED)
{
perror("mmap");
return(NULL);
}
close(fd);
return addr;
} }
static void custom_mmap_free(const char* filename, void* addr, size_t size) static void custom_mmap_free(const char* filename, void* addr, size_t size, int rank)
{ {
char local_filename[256] = {0};
/* make filename unique per rank in case two procs are on the same node */
sprintf(local_filename, "%s.%d", filename, rank);
munmap(addr, size); munmap(addr, size);
remove(filename); remove(local_filename);
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment