fuse: add FOPEN_NOFLUSH
Subsystems (2)
PATCH 1/1 fuse: add FOPEN_NOFLUSH
Add flag returned by OPENDIR request to avoid flushing data cache on close.
Different filesystems implement ->flush() is different ways:
- Most disk filesystems do not implement ->flush() at all
- Some network filesystem (e.g. nfs) flush local write cache of FMODE_WRITE file and send a "flush" command to server
- Some network filesystem (e.g. cifs) flush local write cache of FMODE_WRITE file without sending an additional command to server
FUSE flushes local write cache of ANY file, even non FMODE_WRITE and sends a "flush" command to server (if server implements it).
The FUSE implementation of ->flush() seems over agressive and arbitrary and does not make a lot of sense when writeback caching is disabled.
Instead of deciding on another arbitrary implementation that makes sense, leave the choice of per-file flush behavior in the hands of the server.
---
Hi Miklos,
I've tested this manually by watching --debug-fuse prints with and without --nocache option to passthrough_hp.
The libfuse+passthrough_hp patch is at:
https://github.com/amir73il/libfuse/commits/fopen_noflush
Thanks,
Amir.
fs/fuse/file.c | 3 +++ include/uapi/linux/fuse.h | 3 +++ 2 files changed, 6 insertions(+)
fs/fuse/file.c +3 -0
@@ -483,6 +483,9 @@ static int fuse_flush(struct file *file, fl_owner_t id)if (fuse_is_bad (inode))return -EIO ; +if (ff->open_flags &FOPEN_NOFLUSH ) +return 0 ; + err =write_inode_now (inode,1 );if (err)return err;
include/uapi/linux/fuse.h +3 -0
@@ -184,6 +184,7 @@* * 7.34 * - add FUSE_SYNCFS +* - add FOPEN_NOFLUSH */ #ifndef _LINUX_FUSE_H
@@ -290,12 +291,14 @@ struct fuse_file_lock {* FOPEN_NONSEEKABLE: the file is not seekable * FOPEN_CACHE_DIR: allow caching this directory * FOPEN_STREAM: the file is stream-like (no file position at all) +* FOPEN_NOFLUSH: don't flush data cache on every close */ #define FOPEN_DIRECT_IO (1 << 0)#define FOPEN_KEEP_CACHE (1 << 1)#define FOPEN_NONSEEKABLE (1 << 2)#define FOPEN_CACHE_DIR (1 << 3)#define FOPEN_STREAM (1 << 4) +#define FOPEN_NOFLUSH (1 << 5)/** * INIT request/reply flags
Signature · 1 line
2.25.1
A message that is not in the archive (sent off-list or not yet received): YXVltvcDKNCqodJz@lpc
A message that is not in the archive (sent off-list or not yet received): CAOQ4uxjV2LXvu0kiLuDR_kvgHxLcwPCT1Y5NyD6aaMWrwg1EiQ@mail.gmail.com
A message that is not in the archive (sent off-list or not yet received): YXV4/u4iryv/sXFX@lpc
Quoted 8 lines · Shachar Sharon
Quoted 6 lines · Amir Goldstein
Quoted 5 lines · Shachar Sharon
Quoted 3 lines · Amir Goldstein
Add flag returned by OPENDIR request to avoid flushing data cache on close.
Quoted 9 lines
Quoted 6 lines
Quoted 3 lines
I believe this holds not only for
FUSE_OPENDIRbut also toFUSE_OPENandFUSE_CREATE(see 'structfuse_open_out').Oops that was a copy&paste typo.
Of course this is only relevant forFUSE_OPENandFUSE_CREATE.IMHO it is relevant to all 3 cases (
FUSE_OPEN,FUSE_CREATE,FUSE_OPENDIR).
fuse_dir_operations have no ->flush() as there is no write cache for directories.
Quoted 66 lines
Quoted 66 lines
Quoted 65 lines
Quoted 59 lines
Different filesystems implement ->flush() is different ways:
- Most disk filesystems do not implement ->flush() at all
- Some network filesystem (e.g. nfs) flush local write cache ofFMODE_WRITEfile and send a "flush" command to server
- Some network filesystem (e.g. cifs) flush local write cache ofFMODE_WRITEfile without sending an additional command to serverFUSE flushes local write cache of ANY file, even non
FMODE_WRITEand sends a "flush" command to server (if server implements it).The FUSE implementation of ->flush() seems over agressive and arbitrary and does not make a lot of sense when writeback caching is disabled.
Instead of deciding on another arbitrary implementation that makes sense, leave the choice of per-file flush behavior in the hands of the server.
Link https://lore.kernel.org/linux-fsdevel/CAJfpegspE8e6aKd47uZtSYX8Y-1e1FWS0VL0DH2Skb9gQP5RJQ@mail.gmail.com/ open hereSuggested-by Miklos Szeredi <[email protected]>Signed-off-by Amir Goldstein <[email protected]>---
Hi Miklos,
I've tested this manually by watching --debug-fuse prints with and without --nocache option to
passthrough_hp.The libfuse+passthrough_hp patch is at:
https://github.com/amir73il/libfuse/commits/fopen_noflushThanks,
Amir.
fs/fuse/file.c| 3 +++include/uapi/linux/fuse.h| 3 +++2 files changed, 6 insertions(+)fs/fuse/file.c +3
-0@@ -483,6 +483,9 @@ static int fuse_flush(struct file *file, fl_owner_t id)if (fuse_is_bad (inode))return -EIO ; +if (ff->open_flags &FOPEN_NOFLUSH ) +return 0 ; + err =write_inode_now (inode,1 );if (err)return err;include/uapi/linux/fuse.h +0
-0include/uapi/linux/fuse.h line 186
Quoted 3 lines
include/uapi/linux/fuse.h +0
-0@@ -184,6 +184,7 @@* * 7.34 * - add FUSE_SYNCFS Most likely you want to bump to 7.35; 7.34 is already out in the wild (e.g., on my Fedora33 workstation)
Quoted 5 lines
Quoted 5 lines
Possibly. I wasn't sure what was the rationale behind when the version should be bumped.
One argument against bumping the version is that there is not much harm is passing this flag to an old kernel - it just ignored the flag and sends the flush requests anyway.
Miklos, do I need to bump the protocol version?
Thanks,
Amir.
Miklos Szeredi
maintainerQuoted 10 lines · Amir Goldstein
Quoted 8 lines · Shachar Sharon
Quoted 6 lines · Amir Goldstein
Quoted 5 lines · Shachar Sharon
Quoted 3 lines · Amir Goldstein
Add flag returned by OPENDIR request to avoid flushing data cache on close.
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 3 lines
I believe this holds not only for
FUSE_OPENDIRbut also toFUSE_OPENandFUSE_CREATE(see 'structfuse_open_out').Oops that was a copy&paste typo.
Of course this is only relevant forFUSE_OPENandFUSE_CREATE.
Fixed up.
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
fs/fuse/file.c| 3 +++include/uapi/linux/fuse.h| 3 +++2 files changed, 6 insertions(+)fs/fuse/file.c +0
-0@@ -483,6 +483,9 @@ static int fuse_flush(struct file *file, fl_owner_t id)if (fuse_is_bad (inode))return -EIO ;
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
fs/fuse/file.c static int fuse_flush(struct file *file, fl_owner_t id) · line 486
Quoted 1 line
fs/fuse/file.c +1
-0+if (ff->open_flags &FOPEN_NOFLUSH )
This needs to check for !fc->writeback_cache. Fixed up.
Without this dirty pages could persist after the file is finally closed, which is undesirable for several reasons. One is that a writably open file is no longer guaranteed to exist (needed for filling fuse_write_in::fh). Another is that writing out pages from memory reclaim is deadlock prone. So even if we could omit the fh field we'd need to make sure that reclaim doesn't wait for fuse writeback. So while having dirty pages beyond last close(2) could be really useful, it's not something we can currently do.
Note: while mainline currently does flush pages from ->release(), that's wrong, and removed in fuse.git#for_next.
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 9 lines
include/uapi/linux/fuse.h line 186
Quoted 6 lines
include/uapi/linux/fuse.h +0
-0@@ -184,6 +184,7 @@* * 7.34 * - add FUSE_SYNCFS Most likely you want to bump to 7.35; 7.34 is already out in the wild (e.g., on my Fedora33 workstation)
Quoted 7 lines
Quoted 5 lines
Quoted 5 lines
Possibly. I wasn't sure what was the rationale behind when the version should be bumped.
One argument against bumping the version is that there is not much harm is passing this flag to an old kernel - it just ignored the flag and sends the flush requests anyway.Miklos, do I need to bump the protocol version?
We've historically done that. But the last minor version that is
actually checked by the kernel or libfuse was 23 (the fuse_init_out expansion), so nothing bad would happen if for some reason the bump was forgotten.
I've fixed this up too and pushed out to #for-next.
Thanks,
Miklos