X-Git-Url: https://git.kernel.dk/?p=fio.git;a=blobdiff_plain;f=memory.c;h=4a9dc4af212d05feee7b360c9fd6dd08ea6200f4;hp=39fb9f237bb6fcb3d2a378997ed6debe71e2f236;hb=15cf40b2844caad4cf8da0cdaeddd132cd6adefc;hpb=d9a7ba88af39b1047c9f8c077280932cd12cb58e diff --git a/memory.c b/memory.c index 39fb9f23..4a9dc4af 100644 --- a/memory.c +++ b/memory.c @@ -5,7 +5,9 @@ #include #include #include +#ifndef FIO_NO_HAVE_SHM_H #include +#endif #include #include "fio.h" @@ -115,12 +117,19 @@ static void free_mem_shm(struct thread_data *td) shmctl(td->shm_id, IPC_RMID, &sbuf); } -static int alloc_mem_mmap(struct thread_data *td, unsigned int total_mem) +static int alloc_mem_mmap(struct thread_data *td, size_t total_mem) { int flags = MAP_PRIVATE; td->mmapfd = 1; + if (td->o.mem_type == MEM_MMAPHUGE) { + unsigned long mask = td->o.hugepage_size - 1; + + flags |= MAP_HUGETLB; + total_mem = (total_mem + mask) & ~mask; + } + if (td->mmapfile) { td->mmapfd = open(td->mmapfile, O_RDWR|O_CREAT, 0644); @@ -155,7 +164,7 @@ static int alloc_mem_mmap(struct thread_data *td, unsigned int total_mem) return 0; } -static void free_mem_mmap(struct thread_data *td, unsigned int 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); munmap(td->orig_buffer, td->orig_buffer_size); @@ -166,7 +175,7 @@ static void free_mem_mmap(struct thread_data *td, unsigned int total_mem) } } -static int alloc_mem_malloc(struct thread_data *td, unsigned int 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); @@ -185,7 +194,7 @@ static void free_mem_malloc(struct thread_data *td) */ int allocate_io_mem(struct thread_data *td) { - unsigned int total_mem; + size_t total_mem; int ret = 0; if (td->io_ops->flags & FIO_NOIO) @@ -200,6 +209,8 @@ int allocate_io_mem(struct thread_data *td) total_mem += td->o.mem_align - page_size; } + dprint(FD_MEM, "Alloc %lu for buffers\n", (size_t) total_mem); + if (td->o.mem_type == MEM_MALLOC) ret = alloc_mem_malloc(td, total_mem); else if (td->o.mem_type == MEM_SHM || td->o.mem_type == MEM_SHMHUGE)