summaryrefslogtreecommitdiff
path: root/memory.c
diff options
context:
space:
mode:
authorJens Axboe <jens.axboe@oracle.com>2006-12-20 14:40:44 +0100
committerJens Axboe <jens.axboe@oracle.com>2006-12-20 14:40:44 +0100
commitd0bdaf49eb3f4faa941d02274f2bd875a187e7d7 (patch)
treef5f86b02044b4ce7bfc5b1e104e075ce7d3f9fca /memory.c
parente0a223354342cc45a916b669343718b80a20c2ea (diff)
downloadfio-d0bdaf49eb3f4faa941d02274f2bd875a187e7d7.tar.gz
fio-d0bdaf49eb3f4faa941d02274f2bd875a187e7d7.tar.bz2
[PATCH] Support for mmap of hugetlb files as memory backing
Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
Diffstat (limited to 'memory.c')
-rw-r--r--memory.c35
1 files changed, 31 insertions, 4 deletions
diff --git a/memory.c b/memory.c
index d336c2bc..5f3c4fa5 100644
--- a/memory.c
+++ b/memory.c
@@ -81,12 +81,34 @@ int allocate_io_mem(struct thread_data *td)
td->orig_buffer = NULL;
return 1;
}
- } else if (td->mem_type == MEM_MMAP) {
- td->orig_buffer = mmap(NULL, td->orig_buffer_size, PROT_READ | PROT_WRITE, MAP_PRIVATE | OS_MAP_ANON, 0, 0);
+ } else if (td->mem_type == MEM_MMAP || td->mem_type == MEM_MMAPHUGE) {
+ int flags = MAP_PRIVATE;
+
+ td->hugefd = 0;
+
+ if (td->mem_type == MEM_MMAPHUGE) {
+ fprintf(stderr, "file=%s\n", td->hugefile);
+ td->hugefd = open(td->hugefile, O_RDWR|O_CREAT, 0644);
+
+ if (td->hugefd < 0) {
+ td_verror(td, errno);
+ perror("open huge file");
+ td->orig_buffer = NULL;
+ return 1;
+ }
+ } else
+ flags |= OS_MAP_ANON;
+
+ fprintf(stderr, "mmaping %lu\n", (unsigned long) td->orig_buffer_size);
+ td->orig_buffer = mmap(NULL, td->orig_buffer_size, PROT_READ | PROT_WRITE, flags, td->hugefd, 0);
+ fprintf(stderr, "mmaped %p\n", td->orig_buffer);
if (td->orig_buffer == MAP_FAILED) {
td_verror(td, errno);
perror("mmap");
td->orig_buffer = NULL;
+ if (td->hugefd)
+ close(td->hugefd);
+
return 1;
}
}
@@ -103,9 +125,14 @@ void free_io_mem(struct thread_data *td)
shmdt(td->orig_buffer);
shmctl(td->shm_id, IPC_RMID, &sbuf);
- } else if (td->mem_type == MEM_MMAP)
+ } else if (td->mem_type == MEM_MMAP || td->mem_type == MEM_MMAPHUGE) {
munmap(td->orig_buffer, td->orig_buffer_size);
- else
+ if (td->mem_type == MEM_MMAPHUGE) {
+ close(td->hugefd);
+ unlink(td->hugefile);
+ free(td->hugefile);
+ }
+ } else
log_err("Bad memory type %u\n", td->mem_type);
td->orig_buffer = NULL;