From 5e58a2a65f0780dd7df04db1569cc5fcb63089b7 Mon Sep 17 00:00:00 2001 From: Sohei Koyama Date: Tue, 8 Oct 2024 18:36:17 +0900 Subject: [PATCH] mmap support --- .github/workflows/ci.yaml | 2 +- configure.ac | 7 +++++++ lib/finchfs.c | 18 +++++++++++++++--- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 7bf02d4..61cde1d 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -28,7 +28,7 @@ jobs: run: autoreconf -i - name: Configure the project - run: ./configure + run: ./configure --enable-mmap - name: Build the project run: make diff --git a/configure.ac b/configure.ac index d0cbeaf..ac3f900 100644 --- a/configure.ac +++ b/configure.ac @@ -30,6 +30,13 @@ if test x$with_pmemkv != xno; then PKG_CHECK_MODULES([LIBPMEMKV], [libpmemkv]) fi +AC_ARG_ENABLE([mmap], + [AS_HELP_STRING([--enable-mmap], [Enable mmap support])], + [if test "x$enable_mmap" = "xyes"; then + AC_DEFINE([FINCH_MMAP_SUPPORT], 1, [Enable mmap support]) + fi], + [enable_mmap=no]) + # Checks for header files. AC_CHECK_HEADERS([stdlib.h string.h unistd.h stdint.h]) diff --git a/lib/finchfs.c b/lib/finchfs.c index ecf7405..3d425a4 100644 --- a/lib/finchfs.c +++ b/lib/finchfs.c @@ -43,7 +43,9 @@ static struct fd_table { uint64_t pos; } getdents_state; } *fd_table; +#define IS_NULL_STRING(str) (str == NULL || str[0] == '\0') +#ifdef FINCH_MMAP_SUPPORT struct mmap_item; typedef struct mmap_item { @@ -113,8 +115,6 @@ query_mmap(uint64_t fault_addr) return (NULL); } -#define IS_NULL_STRING(str) (str == NULL || str[0] == '\0') - static void * fault_handler_thread(void *arg) { @@ -208,6 +208,7 @@ fault_handler_thread(void *arg) } } } +#endif int finchfs_init(const char *addrfile) @@ -232,8 +233,10 @@ finchfs_init(const char *addrfile) fd_table[i].path = NULL; fd_table[i].eid = malloc(sizeof(uint64_t) * nvprocs); } +#ifdef FINCH_MMAP_SUPPORT if ((uffd = syscall(__NR_userfaultfd, O_CLOEXEC | O_NONBLOCK)) < 0) { - log_error("syscall(__NR_userfaultfd) failed errno=%d", errno); + log_error("NOTE: /proc/sys/vm/unprivileged_userfaultfd should " + "be set 1"); goto init_err; } uffdio_api.api = UFFD_API; @@ -246,6 +249,7 @@ finchfs_init(const char *addrfile) log_error("pthread_create failed"); goto init_err; } +#endif return (0); init_err: finchfs_term(); @@ -1068,6 +1072,7 @@ void * finchfs_mmap(void *addr, size_t length, int prot, int flags, int fd, off_t offset) { +#ifdef FINCH_MMAP_SUPPORT struct uffdio_register uffdio_register; if (fd < 0 || fd >= fd_table_size || fd_table[fd].path == NULL) { errno = EBADF; @@ -1105,11 +1110,15 @@ finchfs_mmap(void *addr, size_t length, int prot, int flags, int fd, item->offset = offset; add_mmap_item(item); return (addr); +#endif + errno = ENOTSUP; + return (MAP_FAILED); } int finchfs_munmap(void *addr, size_t length) { +#ifdef FINCH_MMAP_SUPPORT struct uffdio_range uffdio_range; uffdio_range.start = (uint64_t)addr; uffdio_range.len = length; @@ -1124,4 +1133,7 @@ finchfs_munmap(void *addr, size_t length) return (-1); } return (0); +#endif + errno = ENOTSUP; + return (-1); }