fio: Add advise THP option to mmap engine
PATCH 1/1 fio: Add advise THP option to mmap engine
The transparent hugepage Linux-specific memory advisory has potentially significant implications for how the memory management behaves. Add a new mmap specific option that enables private TLP mmap mode when set so we can test running fio with anonymous memory (i.e. mmap /dev/zero).
--- engines/mmap.c | 39 ++++++++++++++++++++++++++++++++++++--- optgroup.h | 2 ++ 2 files changed, 38 insertions(+), 3 deletions(-)
engines/mmap.c +36 -3
@@ -11,6 +11,7 @@#include <sys/mman.h> #include "../fio.h" +#include "../optgroup.h" #include "../verify.h" /*
@@ -26,6 +27,26 @@ struct fio_mmap_data {off_t mmap_off; }; +struct mmap_options { +void *pad; +unsigned int thp; +}; + +static struct fio_option options[] = { + { + .name ="thp" , + .lname ="Transparent Huge Pages" , + .type =FIO_OPT_INT , + .off1 = offsetof(struct mmap_options , thp), + .help ="Memory Advise Huge Page" , + .category =FIO_OPT_C_ENGINE , + .group =FIO_OPT_G_MMAP , + }, + { + .name =NULL , + }, +}; +static bool fio_madvise_file (struct thread_data *td,struct fio_file *f,size_t length)
@@ -54,7 +75,8 @@ static int fio_mmap_file(struct thread_data *td, struct fio_file *f, size_t length, off_t off) {struct fio_mmap_data *fmd =FILE_ENG_DATA (f); -int flags =0 ; +struct mmap_options *o = td->eo; +int flags =0 , shared =MAP_SHARED ;if (td_rw (td) && !td->o.verify_only) flags =PROT_READ |PROT_WRITE ;
@@ -66,7 +88,12 @@ static int fio_mmap_file(struct thread_data *td, struct fio_file *f, }else flags =PROT_READ ; - fmd->mmap_ptr =mmap (NULL , length, flags,MAP_SHARED , f->fd, off); +#if FIO_OS ==os_linux +if (o->thp) + shared =MAP_PRIVATE ; +#endif + + fmd->mmap_ptr =mmap (NULL , length, flags, shared, f->fd, off);if (fmd->mmap_ptr ==MAP_FAILED ) { fmd->mmap_ptr =NULL ;td_verror (td, errno,"mmap" );
@@ -146,6 +173,7 @@ static int fio_mmapio_prep(struct thread_data *td, struct io_u *io_u) {struct fio_file *f = io_u->file;struct fio_mmap_data *fmd =FILE_ENG_DATA (f); +struct mmap_options *o = td->eo;int ret;/*
@@ -170,10 +198,13 @@ static int fio_mmapio_prep(struct thread_data *td, struct io_u *io_u)if (ret)return ret; } - done: io_u->mmap_data = fmd->mmap_ptr + io_u->offset - fmd->mmap_off - f->file_offset; +#if FIO_OS ==os_linux +if (o->thp) +madvise (io_u->mmap_data, fmd->mmap_sz,MADV_HUGEPAGE ); +#endif return 0 ; }
@@ -275,6 +306,8 @@ static struct ioengine_ops ioengine = { .close_file = fio_mmapio_close_file, .get_file_size = generic_get_file_size, .flags = FIO_SYNCIO | FIO_NOEXTEND, + .options = options, + .option_struct_size = sizeof(struct mmap_options), }; static void fio_init fio_mmapio_register(void)
optgroup.h +2 -0
@@ -61,6 +61,7 @@ enum opt_category_group { __FIO_OPT_G_MTD, __FIO_OPT_G_HDFS, __FIO_OPT_G_SG, + __FIO_OPT_G_MMAP, __FIO_OPT_G_NR, FIO_OPT_G_RATE = (1ULL << __FIO_OPT_G_RATE),
@@ -97,6 +98,7 @@ enum opt_category_group {FIO_OPT_G_MTD = (1ULL << __FIO_OPT_G_MTD),FIO_OPT_G_HDFS = (1ULL << __FIO_OPT_G_HDFS),FIO_OPT_G_SG = (1ULL << __FIO_OPT_G_SG), +FIO_OPT_G_MMAP = (1ULL << __FIO_OPT_G_MMAP), FIO_OPT_G_INVALID = (1ULL << __FIO_OPT_G_NR), };
Signature · 1 line
2.14.4
Jens Axboe
maintainerQuoted 4 lines · Keith Busch
The transparent hugepage Linux-specific memory advisory has potentially significant implications for how the memory management behaves. Add a new mmap specific option that enables private TLP mmap mode when set so we can test running fio with anonymous memory (i.e. mmap
/dev/zero).
I'm fine with this, but the usual approach to platform stuff like this is to have
#define FIO_HAVE_THP
or similar in the os/os-linux.h file and then have:
#if FIO_OS==os_linux if (o->thp) madvise(io_u->mmap_data, fmd->mmap_sz, MADV_HUGEPAGE);
#endif
#if defined(FIO_HAVE_THP) ...
#endif
instead. Since we need MADV_HUGEPAGE as well, might even make sense to just have this be a configure check instead...
Signature · 1 line
Jens Axboe
Quoted 16 lines · Jens Axboe
Quoted 4 lines · Keith Busch
The transparent hugepage Linux-specific memory advisory has potentially significant implications for how the memory management behaves. Add a new mmap specific option that enables private TLP mmap mode when set so we can test running fio with anonymous memory (i.e. mmap
/dev/zero).I'm fine with this, but the usual approach to platform stuff like this is to have
#define
FIO_HAVE_THPor similar in the
os/os-linux.hfile and then have:#if FIO_OS==os_linux if (o->thp) madvise(io_u->mmap_data, fmd->mmap_sz, MADV_HUGEPAGE);
Quoted 8 lines
#endif
#if defined(FIO_HAVE_THP) ...#endif
instead. Since we need
MADV_HUGEPAGEas well, might even make sense to just have this be a configure check instead...
Sounds good. I like to fit in with the local customs, so will take another shot at this.