Re: [PATCH v2 1/2] page_fault: add mmap-backed ioengine for anonymous faults

Vincent Fu <[email protected]> Thu, 12 Mar 2026 09:34:19 -0400
Newsgroups org.kernel.vger.fio
Message-ID <CAOp=CXkc=47=2=xkqyZwwZE5kxDGfF+zm+oVi8dvc8R_9N5qrw@mail.gmail.com>
On Wed, Mar 11, 2026 at 11:52=E2=80=AFAM Nico Pache <[email protected]> wro=
te:
>
> 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 <[email protected]>
> ---
>  Makefile                |   2 +-
>  engines/page_fault.c    | 116 ++++++++++++++++++++++++++++++++++++++++
>  examples/page_fault.fio |  60 +++++++++++++++++++++
>  3 files changed, 177 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 :=3D     $(sort $(patsubst $(SRCDIR)/%,%,$(wildc=
ard $(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..88108644
> --- /dev/null
> +++ b/engines/page_fault.c
> @@ -0,0 +1,116 @@
> +/*
> + * page_fault engine
> + *
> + * IO engine that reads/writes directly to/from anonymous memory
> + * by triggering page faults.
> + */
> +#include "fio.h"
> +#include "ioengines.h"
> +#include <sys/mman.h>
> +
> +struct fio_page_fault_data {
> +  void *mmap_ptr;
> +  size_t mmap_sz;
> +};
> +
> +static int fio_page_fault_init(struct thread_data *td) {

The style we follow is to put the { on a new line. Also please use
tabs. We basically follow the kernel's style conventions. Did you use
the default LLVM conventions with clang-format?

> +  size_t total_io_size;
> +  struct fio_page_fault_data *fpd;
> +
> +  if (td->o.nr_files > 1) {
> +    log_err("page_fault engine does not support multiple files\n");

How about, "fio: page_fault ioengine ..."?

> +    return 1;
> +  }

Consider checking that td->o.offset =3D=3D 0 and emitting an error message
saying that the offset option must be zero for this ioengine to work.

> +
> +  fpd =3D calloc(1, sizeof(*fpd));
> +  if (!fpd)
> +    return 1;
> +
> +  total_io_size =3D td->o.size;
> +  fpd->mmap_sz =3D total_io_size;
> +  fpd->mmap_ptr =3D mmap(NULL, total_io_size, PROT_READ | PROT_WRITE,
> +                       MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
> +  if (fpd->mmap_ptr =3D=3D MAP_FAILED) {
> +    free(fpd);
> +    return 1;
> +  }
> +
> +  td->io_ops_data =3D fpd;
> +  FILE_SET_ENG_DATA(td->files[0], fpd);

I would avoid directly manipulating files[] here. Since there is only
a single instance of fpd, why not omit this and just access fpd via
td->io_ops_data in queue()?

Vincent