Skip to content

Commit

Permalink
Merge pull request #1321 from trapexit/allowmmap
Browse files Browse the repository at this point in the history
Add support for 'direct-io-allow-mmap' if supported by kernel
  • Loading branch information
trapexit authored Mar 22, 2024
2 parents 977d042 + f0444a1 commit b21172c
Show file tree
Hide file tree
Showing 8 changed files with 152 additions and 114 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ start with one of the following option sets.

`cache.files=auto-full,dropcacheonclose=true,category.create=mfs`

or if you are on a Linux kernel >= 6.6.x mergerfs will enable a mode
that allows shared mmap when `cache.files=off`. To be sure of the best
performance between `cache.files=off` and `cache.files=auto-full`
you'll need to do your own benchmarking but often `off` is faster.

#### You don't need `mmap`

`cache.files=off,dropcacheonclose=true,category.create=mfs`
Expand Down Expand Up @@ -162,6 +167,11 @@ These options are the same regardless of whether you use them with the
longer need the data and it can drop its cache. Recommended when
**cache.files=partial|full|auto-full|per-process** to limit double
caching. (default: false)
* **direct-io-allow-mmap=BOOL**: On newer kernels (>= 6.6) it is
possible to disable file page caching while still allowing for
shared mmap support. mergerfs will enable this feature if available
but an option is provided to turn it off for testing and debugging
purposes. (default: true)
* **symlinkify=BOOL**: When enabled and a file is not writable and its
mtime or ctime is older than **symlinkify_timeout** files will be
reported as symlinks to the original files. Please read more below
Expand Down
84 changes: 24 additions & 60 deletions libfuse/include/fuse_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,23 +108,26 @@ struct fuse_file_info_t
* FUSE_CAP_IOCTL_DIR: ioctl support on directories
* FUSE_CAP_CACHE_SYMLINKS: cache READLINK responses
*/
#define FUSE_CAP_ASYNC_READ (1 << 0)
#define FUSE_CAP_POSIX_LOCKS (1 << 1)
#define FUSE_CAP_ATOMIC_O_TRUNC (1 << 3)
#define FUSE_CAP_EXPORT_SUPPORT (1 << 4)
#define FUSE_CAP_BIG_WRITES (1 << 5)
#define FUSE_CAP_DONT_MASK (1 << 6)
#define FUSE_CAP_FLOCK_LOCKS (1 << 10)
#define FUSE_CAP_IOCTL_DIR (1 << 11)
#define FUSE_CAP_READDIR_PLUS (1 << 13)
#define FUSE_CAP_READDIR_PLUS_AUTO (1 << 14)
#define FUSE_CAP_ASYNC_DIO (1 << 15)
#define FUSE_CAP_WRITEBACK_CACHE (1 << 16)
#define FUSE_CAP_PARALLEL_DIROPS (1 << 18)
#define FUSE_CAP_POSIX_ACL (1 << 19)
#define FUSE_CAP_CACHE_SYMLINKS (1 << 20)
#define FUSE_CAP_MAX_PAGES (1 << 21)
#define FUSE_CAP_SETXATTR_EXT (1 << 22)
#define FUSE_CAP_ASYNC_READ (1ULL << 0)
#define FUSE_CAP_POSIX_LOCKS (1ULL << 1)
#define FUSE_CAP_ATOMIC_O_TRUNC (1ULL << 3)
#define FUSE_CAP_EXPORT_SUPPORT (1ULL << 4)
#define FUSE_CAP_BIG_WRITES (1ULL << 5)
#define FUSE_CAP_DONT_MASK (1ULL << 6)
#define FUSE_CAP_FLOCK_LOCKS (1ULL << 10)
#define FUSE_CAP_IOCTL_DIR (1ULL << 11)
#define FUSE_CAP_READDIR_PLUS (1ULL << 13)
#define FUSE_CAP_READDIR_PLUS_AUTO (1ULL << 14)
#define FUSE_CAP_ASYNC_DIO (1ULL << 15)
#define FUSE_CAP_WRITEBACK_CACHE (1ULL << 16)
#define FUSE_CAP_PARALLEL_DIROPS (1ULL << 18)
#define FUSE_CAP_POSIX_ACL (1ULL << 19)
#define FUSE_CAP_CACHE_SYMLINKS (1ULL << 20)
#define FUSE_CAP_MAX_PAGES (1ULL << 21)
#define FUSE_CAP_SETXATTR_EXT (1ULL << 22)
#define FUSE_CAP_DIRECT_IO_ALLOW_MMAP (1ULL << 23)
#define FUSE_CAP_CREATE_SUPP_GROUP (1ULL << 24)


/**
* Ioctl flags
Expand All @@ -150,56 +153,17 @@ struct fuse_file_info_t
* indicate the value requested by the filesystem. The requested
* value must usually be smaller than the indicated value.
*/
struct fuse_conn_info {
/**
* Major version of the protocol (read-only)
*/
struct fuse_conn_info
{
unsigned proto_major;

/**
* Minor version of the protocol (read-only)
*/
unsigned proto_minor;

/**
* Maximum size of the write buffer
*/
unsigned max_write;

/**
* Maximum readahead
*/
unsigned max_readahead;

/**
* Capability flags, that the kernel supports
*/
unsigned capable;

/**
* Capability flags, that the filesystem wants to enable
*/
unsigned want;

/**
* Maximum number of backgrounded requests
*/
uint64_t capable;
uint64_t want;
unsigned max_background;

/**
* Kernel congestion threshold parameter
*/
unsigned congestion_threshold;

/**
* Max pages
*/
uint16_t max_pages;

/**
* For future use.
*/
unsigned reserved[22];
};

struct fuse_session;
Expand Down
44 changes: 30 additions & 14 deletions libfuse/lib/debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,9 @@ open_flag_to_str(const uint64_t offset_)
static
const
char*
fuse_flag_to_str(const uint32_t offset_)
fuse_flag_to_str(const uint64_t offset_)
{
switch(1 << offset_)
switch(1ULL << offset_)
{
FUSE_INIT_FLAG_CASE(ASYNC_READ);
FUSE_INIT_FLAG_CASE(POSIX_LOCKS);
Expand Down Expand Up @@ -189,6 +189,16 @@ fuse_flag_to_str(const uint32_t offset_)
FUSE_INIT_FLAG_CASE(NO_OPENDIR_SUPPORT);
FUSE_INIT_FLAG_CASE(EXPLICIT_INVAL_DATA);
FUSE_INIT_FLAG_CASE(MAP_ALIGNMENT);
FUSE_INIT_FLAG_CASE(SUBMOUNTS);
FUSE_INIT_FLAG_CASE(HANDLE_KILLPRIV_V2);
FUSE_INIT_FLAG_CASE(SETXATTR_EXT);
FUSE_INIT_FLAG_CASE(INIT_EXT);
FUSE_INIT_FLAG_CASE(INIT_RESERVED);
FUSE_INIT_FLAG_CASE(SECURITY_CTX);
FUSE_INIT_FLAG_CASE(HAS_INODE_DAX);
FUSE_INIT_FLAG_CASE(CREATE_SUPP_GROUP);
FUSE_INIT_FLAG_CASE(HAS_EXPIRE_ONLY);
FUSE_INIT_FLAG_CASE(DIRECT_IO_ALLOW_MMAP);
}

return NULL;
Expand All @@ -200,7 +210,7 @@ static
void
debug_open_flags(const uint32_t flags_)
{
fprintf(stderr,"%s,",open_accmode_to_str(flags_));
fprintf(stderr,"%s, ",open_accmode_to_str(flags_));
for(int i = 0; i < (sizeof(flags_) * 8); i++)
{
const char *str;
Expand All @@ -212,7 +222,7 @@ debug_open_flags(const uint32_t flags_)
if(str == NULL)
continue;

fprintf(stderr,"%s,",str);
fprintf(stderr,"%s, ",str);
}
}

Expand Down Expand Up @@ -717,28 +727,31 @@ debug_fuse_fallocate_in(const void *arg_)
void
debug_fuse_init_in(const struct fuse_init_in *arg_)
{
uint64_t flags;

flags = (((uint64_t)arg_->flags) | ((uint64_t)arg_->flags2) << 32);
fprintf(g_OUTPUT,
"FUSE_INIT_IN: "
" major=%u;"
" minor=%u;"
" max_readahead=%u;"
" flags=0x%08X (",
" flags=0x%016lx (",
arg_->major,
arg_->minor,
arg_->max_readahead,
arg_->flags);
for(uint64_t i = 0; i < (sizeof(arg_->flags)*8); i++)
flags);
for(uint64_t i = 0; i < (sizeof(flags)*8); i++)
{
const char *str;

if(!(arg_->flags & (1ULL << i)))
if(!(flags & (1ULL << i)))
continue;

str = fuse_flag_to_str(i);
if(str == NULL)
continue;

fprintf(g_OUTPUT,"%s,",str);
fprintf(g_OUTPUT,"%s, ",str);
}
fprintf(g_OUTPUT,")\n");
}
Expand All @@ -748,7 +761,10 @@ debug_fuse_init_out(const uint64_t unique_,
const struct fuse_init_out *arg_,
const uint64_t argsize_)
{
uint64_t flags;
const struct fuse_init_out *arg = arg_;

flags = (((uint64_t)arg->flags) | ((uint64_t)arg->flags2) << 32);
fprintf(g_OUTPUT,
/* "unique=0x%016"PRIx64";" */
/* " opcode=RESPONSE;" */
Expand All @@ -758,27 +774,27 @@ debug_fuse_init_out(const uint64_t unique_,
" major=%u;"
" minor=%u;"
" max_readahead=%u;"
" flags=0x%08X ("
" flags=0x%016lx ("
,
/* unique_, */
/* sizeof(struct fuse_out_header) + argsize_, */
arg->major,
arg->minor,
arg->max_readahead,
arg->flags);
flags);

for(uint64_t i = 0; i < (sizeof(arg->flags)*8); i++)
for(uint64_t i = 0; i < (sizeof(flags)*8); i++)
{
const char *str;

if(!(arg->flags & (1ULL << i)))
if(!(flags & (1ULL << i)))
continue;

str = fuse_flag_to_str(i);
if(str == NULL)
continue;

fprintf(g_OUTPUT,"%s,",str);
fprintf(g_OUTPUT,"%s, ",str);
}

fprintf(g_OUTPUT,
Expand Down
Loading

0 comments on commit b21172c

Please sign in to comment.