From: Nico Pache <npache@redhat.com>
To: fio@vger.kernel.org
Cc: axboe@kernel.dk, vincentfu@gmail.com, npache@redhat.com,
david@kernel.org, willy@infradead.org
Subject: [RFC 1/2] page_fault: add mmap-backed ioengine for anonymous faults
Date: Thu, 29 Jan 2026 11:43:00 -0700 [thread overview]
Message-ID: <20260129184302.34887-2-npache@redhat.com> (raw)
In-Reply-To: <20260129184302.34887-1-npache@redhat.com>
Introduce a new ioengine that mmaps anonymous memory and copies data
on read/write to trigger page faults. This allows us to leverage FIOs
powerful framework for MM related testing, and will ideally allow us to
quickly expand testing, by leveraging previously FS related fio scripts.
Signed-off-by: Nico Pache <npache@redhat.com>
---
Makefile | 2 +-
engines/page_fault.c | 105 ++++++++++++++++++++++++++++++++++++++++
examples/page_fault.fio | 9 ++++
3 files changed, 115 insertions(+), 1 deletion(-)
create mode 100644 engines/page_fault.c
create mode 100644 examples/page_fault.fio
diff --git a/Makefile b/Makefile
index 0337e8fe..099e2f94 100644
--- a/Makefile
+++ b/Makefile
@@ -57,7 +57,7 @@ SOURCE := $(sort $(patsubst $(SRCDIR)/%,%,$(wildcard $(SRCDIR)/crc/*.c)) \
smalloc.c filehash.c profile.c debug.c engines/cpu.c \
engines/mmap.c engines/sync.c engines/null.c engines/net.c \
engines/ftruncate.c engines/fileoperations.c \
- engines/exec.c \
+ engines/exec.c engines/page_fault.c \
server.c client.c iolog.c backend.c libfio.c flow.c cconv.c \
gettime-thread.c helpers.c json.c idletime.c td_error.c \
profiles/tiobench.c profiles/act.c io_u_queue.c filelock.c \
diff --git a/engines/page_fault.c b/engines/page_fault.c
new file mode 100644
index 00000000..e0a3c9e5
--- /dev/null
+++ b/engines/page_fault.c
@@ -0,0 +1,105 @@
+#include "ioengines.h"
+#include "fio.h"
+#include <sys/mman.h>
+
+struct fio_page_fault_data {
+ void *mmap_ptr;
+ size_t mmap_sz;
+ off_t mmap_off;
+};
+
+static int fio_page_fault_init(struct thread_data *td)
+{
+ size_t total_io_size;
+ struct fio_page_fault_data *fpd = calloc(1, sizeof(*fpd));
+ if (!fpd)
+ return 1;
+
+ total_io_size = td->o.size;
+ fpd->mmap_sz = total_io_size;
+ fpd->mmap_off = 0;
+ fpd->mmap_ptr = mmap(NULL, total_io_size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
+ if (fpd->mmap_ptr == MAP_FAILED)
+ {
+ free(fpd);
+ return 1;
+ }
+
+ FILE_SET_ENG_DATA(td->files[0], fpd);
+ return 0;
+}
+
+static int fio_page_fault_prep(struct thread_data *td, struct io_u *io_u)
+{
+ return 0;
+}
+
+static enum fio_q_status fio_page_fault_queue(struct thread_data *td, struct io_u *io_u)
+{
+ void * mmap_head;
+ struct fio_page_fault_data *fpd = FILE_ENG_DATA(io_u->file);
+ if (!fpd)
+ return 1;
+
+ if (io_u->offset + io_u->buflen > fpd->mmap_sz)
+ return 1;
+
+ mmap_head = fpd->mmap_ptr + io_u->offset;
+ switch (io_u->ddir)
+ {
+ case DDIR_READ:
+ for (size_t i = 0; i < io_u->buflen; i++)
+ {
+ ((unsigned char *)(io_u->xfer_buf))[i] = ((unsigned char *)(mmap_head))[i];
+ }
+ break;
+ case DDIR_WRITE:
+ for (size_t i = 0; i < io_u->buflen; i++)
+ {
+ ((unsigned char *)(mmap_head))[i] = ((unsigned char *)(io_u->xfer_buf))[i];
+ }
+ break;
+ default:
+ return 1;
+ }
+
+ return FIO_Q_COMPLETED;
+}
+
+static int fio_page_fault_open_file(struct thread_data *td, struct fio_file *f)
+{
+ return 0;
+}
+
+static int fio_page_fault_close_file(struct thread_data *td, struct fio_file *f)
+{
+ struct fio_page_fault_data *fpd = FILE_ENG_DATA(f);
+ if (!fpd)
+ return 1;
+ if (fpd->mmap_ptr && fpd->mmap_sz)
+ munmap(fpd->mmap_ptr, fpd->mmap_sz);
+ free(fpd);
+ return 0;
+}
+
+static struct ioengine_ops ioengine = {
+ .name = "page_fault",
+ .version = FIO_IOOPS_VERSION,
+ .init = fio_page_fault_init,
+ .prep = fio_page_fault_prep,
+ .queue = fio_page_fault_queue,
+ .open_file = fio_page_fault_open_file,
+ .close_file = fio_page_fault_close_file,
+ .get_file_size = generic_get_file_size,
+ .flags = FIO_SYNCIO | FIO_NOEXTEND | FIO_DISKLESSIO,
+};
+
+static void fio_init fio_page_fault_register(void)
+{
+ register_ioengine(&ioengine);
+}
+
+static void fio_exit fio_page_fault_unregister(void)
+{
+ unregister_ioengine(&ioengine);
+}
\ No newline at end of file
diff --git a/examples/page_fault.fio b/examples/page_fault.fio
new file mode 100644
index 00000000..9001f570
--- /dev/null
+++ b/examples/page_fault.fio
@@ -0,0 +1,9 @@
+[global]
+bs=4k
+
+[page_fault]
+ioengine=page_fault
+size=2g
+rw=randrw
+rwmixread=50
+verify=crc32c
\ No newline at end of file
--
2.52.0
next prev parent reply other threads:[~2026-01-29 18:43 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-29 18:42 [RFC 0/2] Introduce a page_fault ioengine for MM workflows Nico Pache
2026-01-29 18:43 ` Nico Pache [this message]
2026-01-29 18:43 ` [RFC 2/2] page_fault: add hugepage_delay option for delayed MADV_HUGEPAGE Nico Pache
2026-01-30 20:08 ` Vincent Fu
2026-02-02 15:24 ` Nico Pache
2026-01-30 21:00 ` [RFC 0/2] Introduce a page_fault ioengine for MM workflows fiotestbot
2026-01-31 13:59 ` Jens Axboe
2026-02-02 15:22 ` Nico Pache
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=20260129184302.34887-2-npache@redhat.com \
--to=npache@redhat.com \
--cc=axboe@kernel.dk \
--cc=david@kernel.org \
--cc=fio@vger.kernel.org \
--cc=vincentfu@gmail.com \
--cc=willy@infradead.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