From: Keith Busch <keith.busch@intel.com>
To: Jens Axboe <axboe@kernel.dk>, linux-block@vger.kernel.org
Cc: Keith Busch <keith.busch@intel.com>
Subject: [PATCH] fio: Add advise THP option to mmap engine
Date: Wed, 17 Apr 2019 15:28:16 -0600 [thread overview]
Message-ID: <20190417212816.6460-1-keith.busch@intel.com> (raw)
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).
Signed-off-by: Keith Busch <keith.busch@intel.com>
---
engines/mmap.c | 39 ++++++++++++++++++++++++++++++++++++---
optgroup.h | 2 ++
2 files changed, 38 insertions(+), 3 deletions(-)
diff --git a/engines/mmap.c b/engines/mmap.c
index 308b4665..7bca6c20 100644
--- a/engines/mmap.c
+++ b/engines/mmap.c
@@ -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)
diff --git a/optgroup.h b/optgroup.h
index adf4d09b..bf1bb036 100644
--- a/optgroup.h
+++ b/optgroup.h
@@ -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),
};
--
2.14.4
next reply other threads:[~2019-04-17 21:34 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-04-17 21:28 Keith Busch [this message]
2019-04-17 22:01 ` [PATCH] fio: Add advise THP option to mmap engine Jens Axboe
2019-04-17 22:01 ` Keith Busch
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190417212816.6460-1-keith.busch@intel.com \
--to=keith.busch@intel.com \
--cc=axboe@kernel.dk \
--cc=linux-block@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox