+#ifdef CONFIG_HAVE_THP
+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,
+ },
+};
+#endif
+
+static bool fio_madvise_file(struct thread_data *td, struct fio_file *f,
+ size_t length)
+
+{
+ struct fio_mmap_data *fmd = FILE_ENG_DATA(f);
+#ifdef CONFIG_HAVE_THP
+ struct mmap_options *o = td->eo;
+
+ /* Ignore errors on this optional advisory */
+ if (o->thp)
+ madvise(fmd->mmap_ptr, length, MADV_HUGEPAGE);
+#endif
+
+ if (!td->o.fadvise_hint)
+ return true;
+
+ if (!td_random(td)) {
+ if (posix_madvise(fmd->mmap_ptr, length, POSIX_MADV_SEQUENTIAL) < 0) {
+ td_verror(td, errno, "madvise");
+ return false;
+ }
+ } else {
+ if (posix_madvise(fmd->mmap_ptr, length, POSIX_MADV_RANDOM) < 0) {
+ td_verror(td, errno, "madvise");
+ return false;
+ }
+ }
+
+ return true;
+}
+
+#ifdef CONFIG_HAVE_THP
+static int fio_mmap_get_shared(struct thread_data *td)
+{
+ struct mmap_options *o = td->eo;
+
+ if (o->thp)
+ return MAP_PRIVATE;
+ return MAP_SHARED;
+}
+#else
+static int fio_mmap_get_shared(struct thread_data *td)
+{
+ return MAP_SHARED;
+}
+#endif
+