projects
/
fio.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
options: add support for checking if an option has been set
[fio.git]
/
memory.c
diff --git
a/memory.c
b/memory.c
index f97749bc72c657f7b0d9f3739853dd7039797280..76da8a86269e859889366c283281815e9ffac1dc 100644
(file)
--- a/
memory.c
+++ b/
memory.c
@@
-5,10
+5,12
@@
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
-#include <sys/shm.h>
#include <sys/mman.h>
#include "fio.h"
#include <sys/mman.h>
#include "fio.h"
+#ifndef FIO_NO_HAVE_SHM_H
+#include <sys/shm.h>
+#endif
void fio_unpin_memory(struct thread_data *td)
{
void fio_unpin_memory(struct thread_data *td)
{
@@
-115,9
+117,18
@@
static void free_mem_shm(struct thread_data *td)
static int alloc_mem_mmap(struct thread_data *td, size_t total_mem)
{
static int alloc_mem_mmap(struct thread_data *td, size_t total_mem)
{
- int flags = MAP_PRIVATE;
+ int flags = 0;
+
+ td->mmapfd = -1;
+
+ if (td->o.mem_type == MEM_MMAPHUGE) {
+ unsigned long mask = td->o.hugepage_size - 1;
- td->mmapfd = 1;
+ /* TODO: make sure the file is a real hugetlbfs file */
+ if (!td->o.mmapfile)
+ flags |= MAP_HUGETLB;
+ total_mem = (total_mem + mask) & ~mask;
+ }
if (td->o.mmapfile) {
td->mmapfd = open(td->o.mmapfile, O_RDWR|O_CREAT, 0644);
if (td->o.mmapfile) {
td->mmapfd = open(td->o.mmapfile, O_RDWR|O_CREAT, 0644);
@@
-127,24
+138,30
@@
static int alloc_mem_mmap(struct thread_data *td, size_t total_mem)
td->orig_buffer = NULL;
return 1;
}
td->orig_buffer = NULL;
return 1;
}
- if (ftruncate(td->mmapfd, total_mem) < 0) {
+ if (td->o.mem_type != MEM_MMAPHUGE &&
+ ftruncate(td->mmapfd, total_mem) < 0) {
td_verror(td, errno, "truncate mmap file");
td->orig_buffer = NULL;
return 1;
}
td_verror(td, errno, "truncate mmap file");
td->orig_buffer = NULL;
return 1;
}
+ if (td->o.mem_type == MEM_MMAPHUGE)
+ flags |= MAP_SHARED;
+ else
+ flags |= MAP_PRIVATE;
} else
} else
- flags |= OS_MAP_ANON;
+ flags |= OS_MAP_ANON
| MAP_PRIVATE
;
td->orig_buffer = mmap(NULL, total_mem, PROT_READ | PROT_WRITE, flags,
td->mmapfd, 0);
td->orig_buffer = mmap(NULL, total_mem, PROT_READ | PROT_WRITE, flags,
td->mmapfd, 0);
- dprint(FD_MEM, "mmap %
u/%d %p\n", total_mem, td->mmapfd
,
- td->orig_buffer);
+ dprint(FD_MEM, "mmap %
llu/%d %p\n", (unsigned long long) total_mem
,
+ td->
mmapfd, td->
orig_buffer);
if (td->orig_buffer == MAP_FAILED) {
td_verror(td, errno, "mmap");
td->orig_buffer = NULL;
if (td->orig_buffer == MAP_FAILED) {
td_verror(td, errno, "mmap");
td->orig_buffer = NULL;
- if (td->mmapfd) {
+ if (td->mmapfd
!= 1
) {
close(td->mmapfd);
close(td->mmapfd);
- unlink(td->o.mmapfile);
+ if (td->o.mmapfile)
+ unlink(td->o.mmapfile);
}
return 1;
}
return 1;
@@
-155,10
+172,12
@@
static int alloc_mem_mmap(struct thread_data *td, size_t total_mem)
static void free_mem_mmap(struct thread_data *td, size_t total_mem)
{
static void free_mem_mmap(struct thread_data *td, size_t total_mem)
{
- dprint(FD_MEM, "munmap %u %p\n", total_mem, td->orig_buffer);
+ dprint(FD_MEM, "munmap %llu %p\n", (unsigned long long) total_mem,
+ td->orig_buffer);
munmap(td->orig_buffer, td->orig_buffer_size);
if (td->o.mmapfile) {
munmap(td->orig_buffer, td->orig_buffer_size);
if (td->o.mmapfile) {
- close(td->mmapfd);
+ if (td->mmapfd != -1)
+ close(td->mmapfd);
unlink(td->o.mmapfile);
free(td->o.mmapfile);
}
unlink(td->o.mmapfile);
free(td->o.mmapfile);
}
@@
-167,7
+186,8
@@
static void free_mem_mmap(struct thread_data *td, size_t total_mem)
static int alloc_mem_malloc(struct thread_data *td, size_t total_mem)
{
td->orig_buffer = malloc(total_mem);
static int alloc_mem_malloc(struct thread_data *td, size_t total_mem)
{
td->orig_buffer = malloc(total_mem);
- dprint(FD_MEM, "malloc %u %p\n", total_mem, td->orig_buffer);
+ dprint(FD_MEM, "malloc %llu %p\n", (unsigned long long) total_mem,
+ td->orig_buffer);
return td->orig_buffer == NULL;
}
return td->orig_buffer == NULL;
}
@@
-191,14
+211,14
@@
int allocate_io_mem(struct thread_data *td)
total_mem = td->orig_buffer_size;
total_mem = td->orig_buffer_size;
- if (td->o.odirect || td->o.mem_align ||
+ if (td->o.odirect || td->o.mem_align ||
td->o.oatomic ||
(td->io_ops->flags & FIO_MEMALIGN)) {
total_mem += page_mask;
if (td->o.mem_align && td->o.mem_align > page_size)
total_mem += td->o.mem_align - page_size;
}
(td->io_ops->flags & FIO_MEMALIGN)) {
total_mem += page_mask;
if (td->o.mem_align && td->o.mem_align > page_size)
total_mem += td->o.mem_align - page_size;
}
- dprint(FD_MEM, "Alloc %l
u for buffers\n", (size_t
) total_mem);
+ dprint(FD_MEM, "Alloc %l
lu for buffers\n", (unsigned long long
) total_mem);
if (td->o.mem_type == MEM_MALLOC)
ret = alloc_mem_malloc(td, total_mem);
if (td->o.mem_type == MEM_MALLOC)
ret = alloc_mem_malloc(td, total_mem);
@@
-222,7
+242,7
@@
void free_io_mem(struct thread_data *td)
unsigned int total_mem;
total_mem = td->orig_buffer_size;
unsigned int total_mem;
total_mem = td->orig_buffer_size;
- if (td->o.odirect)
+ if (td->o.odirect
|| td->o.oatomic
)
total_mem += page_mask;
if (td->o.mem_type == MEM_MALLOC)
total_mem += page_mask;
if (td->o.mem_type == MEM_MALLOC)