All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] fio: Add advise THP option to mmap engine
@ 2019-04-17 21:28 Keith Busch
  2019-04-17 22:01 ` Jens Axboe
  0 siblings, 1 reply; 3+ messages in thread
From: Keith Busch @ 2019-04-17 21:28 UTC (permalink / raw)
  To: Jens Axboe, linux-block; +Cc: 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).

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


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] fio: Add advise THP option to mmap engine
  2019-04-17 22:01 ` Jens Axboe
@ 2019-04-17 22:01   ` Keith Busch
  0 siblings, 0 replies; 3+ messages in thread
From: Keith Busch @ 2019-04-17 22:01 UTC (permalink / raw)
  To: Jens Axboe; +Cc: linux-block

On Wed, Apr 17, 2019 at 04:01:28PM -0600, Jens Axboe wrote:
> On 4/17/19 3:28 PM, Keith Busch wrote:
> > 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...

Sounds good. I like to fit in with the local customs, so will take
another shot at this.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] fio: Add advise THP option to mmap engine
  2019-04-17 21:28 [PATCH] fio: Add advise THP option to mmap engine Keith Busch
@ 2019-04-17 22:01 ` Jens Axboe
  2019-04-17 22:01   ` Keith Busch
  0 siblings, 1 reply; 3+ messages in thread
From: Jens Axboe @ 2019-04-17 22:01 UTC (permalink / raw)
  To: Keith Busch, linux-block

On 4/17/19 3:28 PM, Keith Busch wrote:
> 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...
 
-- 
Jens Axboe


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-04-17 22:07 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-04-17 21:28 [PATCH] fio: Add advise THP option to mmap engine Keith Busch
2019-04-17 22:01 ` Jens Axboe
2019-04-17 22:01   ` Keith Busch

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.