Skip to content

Commit

Permalink
mmap support
Browse files Browse the repository at this point in the history
  • Loading branch information
KoyamaSohei committed Oct 8, 2024
1 parent 1c4046e commit 5e58a2a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
run: autoreconf -i

- name: Configure the project
run: ./configure
run: ./configure --enable-mmap

- name: Build the project
run: make
Expand Down
7 changes: 7 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -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])

Expand Down
18 changes: 15 additions & 3 deletions lib/finchfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -208,6 +208,7 @@ fault_handler_thread(void *arg)
}
}
}
#endif

int
finchfs_init(const char *addrfile)
Expand All @@ -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;
Expand All @@ -246,6 +249,7 @@ finchfs_init(const char *addrfile)
log_error("pthread_create failed");
goto init_err;
}
#endif
return (0);
init_err:
finchfs_term();
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -1124,4 +1133,7 @@ finchfs_munmap(void *addr, size_t length)
return (-1);
}
return (0);
#endif
errno = ENOTSUP;
return (-1);
}

0 comments on commit 5e58a2a

Please sign in to comment.