fuse direct write consolidation and parallel IO
Subsystems (3)
v4 cover fuse direct write consolidation and parallel IO
This series consolidates DIO writes into a single code path via fuse_cache_write_iter/generic_file_direct_write. Before
it was only used for O_DIRECT and when writeback cache was not enabled. For server/daemon dio enforcement (FOPEN_DIRECT_IO) another code path was used before, but I _think_ that is not needed and just IOCB_DIRECT needs to be set/enforced.
When writeback-cache was enabled another code path was used, with a fallback to write-through - for direct IO that should not be needed either.
So far O_DIRECT through fuse_cache_write_iter also took an exclusive lock, this should not be needed either, at least when server side sets FOPEN_PARALLEL_DIRECT_WRITES.
Regarding xfstests, without FOPEN_DIRECT_IO there are no differences between patched and unpatched. With FOPEN_DIRECT_IO the series fixes generic/647, which was failing unpatched ("pwrite is broken").
v4:
checkpatch cleanup
Addresses review comments
- Fix shared lock in fuse_cache_write_iter, file_remove_privs() needs the exclusive lock. In order to know if the exclusive lock is needed the new exported vfs function file_remove_privs() is introduced.
- Also fixed for the shared lock is the fallback to buffered writes, which also needs the exclusive lock.
- Fixed is the accidental turn around of false/true in fuse_dio_wr_exclusive_lock().
- Added documentation in fuse_write_flags() that the IOCB_DIRECT flag cannot be trusted.
New optional patches
- "fuse: Use the existing inode fuse_cache_write_iter"
- "[RFC] fuse: No privilege removal when FOPEN_DIRECT_IO is set"
v3:
Addresses review comments
- Rename fuse_direct_write_extending_i_size to io_past_eof
- Change to single line conditions in fuse_dio_wr_exclusive_lock (also fixes accidental parenthesis).
- Add another patch to rename fuse_direct_io to fuse_send_dio
- Add detailed information into the commit message of the patch that consolidates IO paths (5/6, previously 4/5) and also update the subject.
v2:
The entire v1 approach to route DIO writes through fuse_direct_write_iter was turned around and fuse_direct_write_iter is removed instead and all DIO writes are now routed through fuse_cache_write_iter
Bernd Schubert (10):
fuse: direct IO can use the write-through code path
fuse: Create helper function if DIO write needs exclusive lock
fuse: prepare support for shared lock for DIO writes
fs: Add and export file_needs_remove_privs
fuse: enable shared lock for O_DIRECT / handle privilege drop
fuse: Rename fuse_direct_io
fuse: Remove fuse_direct_write_iter code path / use IOCB_DIRECT
fuse: Remove page flush/invaliation in fuse_direct_io
fuse: Use the existing inode fuse_cache_write_iter [RFC] fuse: No privilege removal when FOPEN_DIRECT_IO is set
fs/fuse/cuse.c | 5 +- fs/fuse/dax.c | 2 +- fs/fuse/file.c | 189 +++++++++++++++++++++++---------------------- fs/fuse/fuse_i.h | 8 +- fs/inode.c | 8 ++ include/linux/fs.h | 1 + 6 files changed, 113 insertions(+), 100 deletions(-)
Signature · 1 line
2.39.2
PATCH v4 1/10 fuse: direct IO can use the write-through code path
Direct IO does not benefit from write back cache and it also avoides another direct IO write code path.
--- fs/fuse/file.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/fuse/file.c +1 -1
@@ -1307,7 +1307,7 @@ static ssize_t fuse_cache_write_iter(struct kiocb *iocb, struct iov_iter *from)ssize_t err;struct fuse_conn *fc =get_fuse_conn (inode); -if (fc->writeback_cache) { +if (fc->writeback_cache && !(iocb->ki_flags &IOCB_DIRECT )) {/* Update size (EOF optimization) and mode (SUID clearing) */ err =fuse_update_attributes (mapping->host, file,STATX_SIZE |STATX_MODE );
Signature · 1 line
2.39.2
PATCH v4 2/10 fuse: Create helper function if DIO write needs exclusive lock
In reply to Bernd SchubertThis is just a preparation to avoid code duplication in the next commit.
--- fs/fuse/file.c | 49 ++++++++++++++++++++++++++++++++++--------------- 1 file changed, 34 insertions(+), 15 deletions(-)
fs/fuse/file.c +34 -15
@@ -1298,6 +1298,38 @@ static ssize_t fuse_perform_write(struct kiocb *iocb, struct iov_iter *ii)return res; } +static bool fuse_io_past_eof (struct kiocb *iocb,struct iov_iter *iter) +{ +struct inode *inode =file_inode (iocb->ki_filp); + +return iocb->ki_pos +iov_iter_count (iter) >i_size_read (inode); +} + +/* +* @return true if an exclusive lock for direct IO writes is needed +*/ +static bool fuse_dio_wr_exclusive_lock (struct kiocb *iocb,struct iov_iter *from) +{ +struct file *file = iocb->ki_filp; +struct fuse_file *ff = file->private_data; + +/* server side has to advise that it supports parallel dio writes */ +if (!(ff->open_flags &FOPEN_PARALLEL_DIRECT_WRITES )) +return true; + +/* append will need to know the eventual eof - always needs an +* exclusive lock +*/ +if (iocb->ki_flags &IOCB_APPEND ) +return true; + +/* parallel dio beyond eof is at least for now not supported */ +if (fuse_io_past_eof (iocb, from)) +return true; + +return false; +} +static ssize_t fuse_cache_write_iter (struct kiocb *iocb,struct iov_iter *from) {struct file *file = iocb->ki_filp;
@@ -1557,25 +1589,12 @@ static ssize_t fuse_direct_read_iter(struct kiocb *iocb, struct iov_iter *to)return res; } -static bool fuse_direct_write_extending_i_size (struct kiocb *iocb, -struct iov_iter *iter) -{ -struct inode *inode =file_inode (iocb->ki_filp); - -return iocb->ki_pos +iov_iter_count (iter) >i_size_read (inode); -} -static ssize_t fuse_direct_write_iter (struct kiocb *iocb,struct iov_iter *from) {struct inode *inode =file_inode (iocb->ki_filp); -struct file *file = iocb->ki_filp; -struct fuse_file *ff = file->private_data;struct fuse_io_priv io =FUSE_IO_PRIV_SYNC (iocb);ssize_t res; -bool exclusive_lock = - !(ff->open_flags &FOPEN_PARALLEL_DIRECT_WRITES ) || - iocb->ki_flags &IOCB_APPEND || -fuse_direct_write_extending_i_size (iocb, from); +bool exclusive_lock =fuse_dio_wr_exclusive_lock (iocb, from);/* * Take exclusive lock if
@@ -1591,7 +1610,7 @@ static ssize_t fuse_direct_write_iter(struct kiocb *iocb, struct iov_iter *from)/* A race with truncate might have come up as the decision for * the lock type was done without holding the lock, check again. */ -if (fuse_direct_write_extending_i_size (iocb, from)) { +if (fuse_io_past_eof (iocb, from)) {inode_unlock_shared (inode);inode_lock (inode); exclusive_lock = true;
Signature · 1 line
2.39.2
PATCH v4 3/10 fuse: prepare support for shared lock for DIO writes
In reply to Bernd SchubertTake a shared lock in fuse_cache_write_iter. This was already done for FOPEN_DIRECT_IO in
commit 153524053bbb ("fuse: allow non-extending parallel direct writes on the same file")
but so far missing for plain O_DIRECT. Server side needs to set FOPEN_PARALLEL_DIRECT_WRITES in order to signal that it supports parallel dio writes.
From style point of view another goto target is introduced, although the existing writethrough target would be sufficient. This is just done to make the code easier to read.
In this commit the exclusive lock still enforced by an '|| 1'. For readability this will be solved in a follow up commit.
--- fs/fuse/file.c | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-)
fs/fuse/file.c +31 -2
@@ -1313,6 +1313,10 @@ static bool fuse_dio_wr_exclusive_lock(struct kiocb *iocb, struct iov_iter *fromstruct file *file = iocb->ki_filp;struct fuse_file *ff = file->private_data; +/* the shared lock is about direct IO only */ +if (!(iocb->ki_flags &IOCB_DIRECT )) +return true; +/* server side has to advise that it supports parallel dio writes */ if (!(ff->open_flags &FOPEN_PARALLEL_DIRECT_WRITES ))return true;
@@ -1338,6 +1342,7 @@ static ssize_t fuse_cache_write_iter(struct kiocb *iocb, struct iov_iter *from)struct inode *inode = mapping->host;ssize_t err;struct fuse_conn *fc =get_fuse_conn (inode); +bool excl_lock =fuse_dio_wr_exclusive_lock (iocb, from) ||1 ;if (fc->writeback_cache && !(iocb->ki_flags &IOCB_DIRECT )) {/* Update size (EOF optimization) and mode (SUID clearing) */
@@ -1356,7 +1361,20 @@ static ssize_t fuse_cache_write_iter(struct kiocb *iocb, struct iov_iter *from) } writethrough: -inode_lock (inode); +relock: +if (excl_lock) +inode_lock (inode); +else { +inode_lock_shared (inode); +if (fuse_io_past_eof (iocb, from)) { +/* file extending writes will trigger i_size_write, +* exclusive lock is needed +*/ +inode_unlock_shared (inode); + excl_lock = true; + goto relock; + } + } err =generic_write_checks (iocb, from);if (err <=0 )
@@ -1374,13 +1392,24 @@ static ssize_t fuse_cache_write_iter(struct kiocb *iocb, struct iov_iter *from) written =generic_file_direct_write (iocb, from);if (written <0 || !iov_iter_count (from)) goto out; + +if (!excl_lock) { +/* fallback to page IO needs the exclusive lock */ +inode_unlock_shared (inode); + excl_lock = true; + goto relock; + } + written =direct_write_fallback (iocb, from, written,fuse_perform_write (iocb, from)); }else { written =fuse_perform_write (iocb, from); } out: -inode_unlock (inode); +if (excl_lock) +inode_unlock (inode); +else +inode_unlock_shared (inode);if (written >0 ) written =generic_write_sync (iocb, written);
Signature · 1 line
2.39.2
PATCH v4 4/10 fs: Add and export file_needs_remove_privs
In reply to Bernd SchubertFuse cannot rely on S_NOSEC as local block device file systems. In order to still being able to parallel direct IO writes, it is going to use the new and exported function file_needs_remove_privs() in an upcoming commit.
--- fs/inode.c | 8 ++++++++ include/linux/fs.h | 1 + 2 files changed, 9 insertions(+)
fs/inode.c +8 -0
@@ -2013,6 +2013,14 @@ int dentry_needs_remove_privs(struct mnt_idmap *idmap,return mask; } +int file_needs_remove_privs (struct file *file) +{ +struct dentry *dentry =file_dentry (file); + +return dentry_needs_remove_privs (file_mnt_idmap (file), dentry); +} +EXPORT_SYMBOL_GPL (file_needs_remove_privs); +static int __remove_privs (struct mnt_idmap *idmap,struct dentry *dentry,int kill) {
include/linux/fs.h +1 -0
@@ -2721,6 +2721,7 @@ extern struct inode *new_inode_pseudo(struct super_block *sb);extern struct inode *new_inode (struct super_block *sb);extern void free_inode_nonrcu (struct inode *inode);extern int setattr_should_drop_suidgid (struct mnt_idmap *,struct inode *); +int file_needs_remove_privs (struct file *file);extern int file_remove_privs (struct file *);int setattr_should_drop_sgid (struct mnt_idmap *idmap,const struct inode *inode);
Signature · 1 line
2.39.2
PATCH v4 5/10 fuse: enable shared lock for O_DIRECT / handle privilege drop
In reply to Bernd SchubertThis eventually enabled a shared lock for O_DIRECT writes in fuse_cache_write_iter.
Missing was to check if privileges need to be dropped - if so, this needs to be done with a exclusive lock.
file_needs_remove_privs and file_remove_privs are both sending an getxattr call, assumption is that this is rare - should not have a performance impact.
fuse_dio_wr_exclusive_lock() is not using file_needs_remove_privs, as it needs to be called again while lock is hold - it would result in a typical double call into file_needs_remove_privs, with the expensive xattr retrieval.
--- fs/fuse/file.c | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-)
fs/fuse/file.c +19 -6
@@ -1308,7 +1308,8 @@ static bool fuse_io_past_eof(struct kiocb *iocb, struct iov_iter *iter)/* * @return true if an exclusive lock for direct IO writes is needed */ -static bool fuse_dio_wr_exclusive_lock (struct kiocb *iocb,struct iov_iter *from) +static bool fuse_dio_wr_exclusive_lock (struct kiocb *iocb,struct iov_iter *from, +struct inode *inode) {struct file *file = iocb->ki_filp;struct fuse_file *ff = file->private_data;
@@ -1342,7 +1343,8 @@ static ssize_t fuse_cache_write_iter(struct kiocb *iocb, struct iov_iter *from)struct inode *inode = mapping->host;ssize_t err;struct fuse_conn *fc =get_fuse_conn (inode); -bool excl_lock =fuse_dio_wr_exclusive_lock (iocb, from) ||1 ; +bool excl_lock =fuse_dio_wr_exclusive_lock (iocb, from, inode); +int remove_privs =1 ;if (fc->writeback_cache && !(iocb->ki_flags &IOCB_DIRECT )) {/* Update size (EOF optimization) and mode (SUID clearing) */
@@ -1380,9 +1382,20 @@ static ssize_t fuse_cache_write_iter(struct kiocb *iocb, struct iov_iter *from)if (err <=0 ) goto out; - err =file_remove_privs (file); -if (err) - goto out; +if (!excl_lock) { + remove_privs =file_needs_remove_privs (file); +if (remove_privs) { +inode_unlock_shared (inode); + excl_lock = true; + goto relock; + } + } + +if (remove_privs) { + err =file_remove_privs (file); +if (err) + goto out; + } err =file_update_time (file);if (err)
@@ -1623,7 +1636,7 @@ static ssize_t fuse_direct_write_iter(struct kiocb *iocb, struct iov_iter *from)struct inode *inode =file_inode (iocb->ki_filp);struct fuse_io_priv io =FUSE_IO_PRIV_SYNC (iocb);ssize_t res; -bool exclusive_lock =fuse_dio_wr_exclusive_lock (iocb, from); +bool exclusive_lock =fuse_dio_wr_exclusive_lock (iocb, from, inode);/* * Take exclusive lock if
Signature · 1 line
2.39.2
PATCH v4 6/10 fuse: Rename fuse_direct_io
In reply to Bernd SchubertJust to avoid confusion with fuse_direct_IO.
--- fs/fuse/cuse.c | 5 ++--- fs/fuse/dax.c | 2 +- fs/fuse/file.c | 14 +++++++------- fs/fuse/fuse_i.h | 8 ++++---- 4 files changed, 14 insertions(+), 15 deletions(-)
fs/fuse/cuse.c +2 -3
@@ -96,7 +96,7 @@ static ssize_t cuse_read_iter(struct kiocb *kiocb, struct iov_iter *to)struct fuse_io_priv io =FUSE_IO_PRIV_SYNC (kiocb);loff_t pos =0 ; -return fuse_direct_io (&io, to, &pos,FUSE_DIO_CUSE ); +return fuse_send_dio (&io, to, &pos,FUSE_DIO_CUSE ); }static ssize_t cuse_write_iter (struct kiocb *kiocb,struct iov_iter *from)
@@ -107,8 +107,7 @@ static ssize_t cuse_write_iter(struct kiocb *kiocb, struct iov_iter *from)* No locking or generic_write_checks(), the server is * responsible for locking and sanity checks. */ -return fuse_direct_io (&io, from, &pos, -FUSE_DIO_WRITE |FUSE_DIO_CUSE ); +return fuse_send_dio (&io, from, &pos,FUSE_DIO_WRITE |FUSE_DIO_CUSE ); }static int cuse_open (struct inode *inode,struct file *file)
fs/fuse/dax.c +1 -1
@@ -731,7 +731,7 @@ static ssize_t fuse_dax_direct_write(struct kiocb *iocb, struct iov_iter *from)struct fuse_io_priv io =FUSE_IO_PRIV_SYNC (iocb);ssize_t ret; - ret =fuse_direct_io (&io, from, &iocb->ki_pos,FUSE_DIO_WRITE ); + ret =fuse_send_dio (&io, from, &iocb->ki_pos,FUSE_DIO_WRITE );fuse_write_update_attr (inode, iocb->ki_pos, ret);return ret;
fs/fuse/file.c +7 -7
@@ -1496,8 +1496,8 @@ static int fuse_get_user_pages(struct fuse_args_pages *ap, struct iov_iter *ii,return ret <0 ? ret :0 ; } -ssize_t fuse_direct_io (struct fuse_io_priv *io,struct iov_iter *iter, -loff_t *ppos,int flags) +ssize_t fuse_send_dio (struct fuse_io_priv *io,struct iov_iter *iter, +loff_t *ppos,int flags) {int write = flags &FUSE_DIO_WRITE ;int cuse = flags &FUSE_DIO_CUSE ;
@@ -1598,7 +1598,7 @@ ssize_t fuse_direct_io(struct fuse_io_priv *io, struct iov_iter *iter,return res >0 ? res : err; } -EXPORT_SYMBOL_GPL (fuse_direct_io); +EXPORT_SYMBOL_GPL (fuse_send_dio); static ssize_t __fuse_direct_read(struct fuse_io_priv *io, struct iov_iter *iter,
@@ -1607,7 +1607,7 @@ static ssize_t __fuse_direct_read(struct fuse_io_priv *io,ssize_t res;struct inode *inode =file_inode (io->iocb->ki_filp); - res =fuse_direct_io (io, iter, ppos,0 ); + res =fuse_send_dio (io, iter, ppos,0 );fuse_invalidate_atime (inode);
@@ -1664,8 +1664,8 @@ static ssize_t fuse_direct_write_iter(struct kiocb *iocb, struct iov_iter *from)if (!is_sync_kiocb (iocb) && iocb->ki_flags &IOCB_DIRECT ) { res =fuse_direct_IO (iocb, from); }else { - res =fuse_direct_io (&io, from, &iocb->ki_pos, -FUSE_DIO_WRITE ); + res =fuse_send_dio (&io, from, &iocb->ki_pos, +FUSE_DIO_WRITE );fuse_write_update_attr (inode, iocb->ki_pos, res); } }
@@ -3001,7 +3001,7 @@ fuse_direct_IO(struct kiocb *iocb, struct iov_iter *iter) }if (iov_iter_rw (iter) ==WRITE ) { - ret =fuse_direct_io (io, iter, &pos,FUSE_DIO_WRITE ); + ret =fuse_send_dio (io, iter, &pos,FUSE_DIO_WRITE );fuse_invalidate_attr_mask (inode,FUSE_STATX_MODSIZE ); }else { ret =__fuse_direct_read (io, iter, &pos);
fs/fuse/fuse_i.h +4 -4
@@ -1247,17 +1247,17 @@ int fuse_do_open(struct fuse_mount *fm, u64 nodeid, struct file *file, bool isdir);/** -* fuse_direct_io() flags +* fuse_send_dio() flags */ /** If set, it is WRITE; otherwise - READ */ #define FUSE_DIO_WRITE (1 << 0) -/** CUSE pass fuse_direct_io() a file which f_mapping->host is not from FUSE */ +/** CUSE pass fuse_send_dio() a file which f_mapping->host is not from FUSE */ #define FUSE_DIO_CUSE (1 << 1) -ssize_t fuse_direct_io (struct fuse_io_priv *io,struct iov_iter *iter, -loff_t *ppos,int flags); +ssize_t fuse_send_dio (struct fuse_io_priv *io,struct iov_iter *iter, +loff_t *ppos,int flags);long fuse_do_ioctl (struct file *file,unsigned int cmd,unsigned long arg,unsigned int flags); long fuse_ioctl_common(struct file *file, unsigned int cmd,
Signature · 1 line
2.39.2
PATCH v4 7/10 fuse: Remove fuse_direct_write_iter code path / use IOCB_DIRECT
In reply to Bernd Schubertfuse_direct_write_iter is basically duplicating what is already in fuse_cache_write_iter/generic_file_direct_write. That can be avoided by setting IOCB_DIRECT in fuse_file_write_iter, after that fuse_cache_write_iter can be used for the FOPEN_DIRECT_IO code path and fuse_direct_write_iter can be removed.
Before it was using for FOPEN_DIRECT_IO
1) async (!is_sync_kiocb(iocb)) && IOCB_DIRECT
fuse_file_write_iter
fuse_direct_write_iter
fuse_direct_IO
fuse_send_dio
2) sync (is_sync_kiocb(iocb)) or IOCB_DIRECT not being set
fuse_file_write_iter
fuse_direct_write_iter
fuse_send_dio
3) FOPEN_DIRECT_IO not set
Same as the consolidates path below
The new consolidated code path is always
fuse_file_write_iter
fuse_cache_write_iter
generic_file_write_iter
__generic_file_write_iter
generic_file_direct_write
mapping->a_ops->direct_IO / fuse_direct_IO
fuse_send_dioSo in general for FOPEN_DIRECT_IO the code path gets longer. Additionally fuse_direct_IO does an allocation of struct fuse_io_priv - might be a bit slower in micro benchmarks.
Also, the IOCB_DIRECT information gets lost (as we now set it outselves). But then IOCB_DIRECT is directly related to O_DIRECT set in struct file::f_flags.
An additional change is for condition 2 above, which might will now do async IO on the condition ff->fm->fc->async_dio. Given that async IO for FOPEN_DIRECT_IO was especially introduced in commit
'commit 23c94e1cdcbf ("fuse: Switch to using async direct IO for
FOPEN_DIRECT_IO")'
it should not matter. Especially as fuse_direct_IO is blocking for is_sync_kiocb(), at worst it has another slight overhead.
Advantage is the removal of code paths and conditions and it is now also possible to remove FOPEN_DIRECT_IO conditions in fuse_send_dio (in a later patch).
--- fs/fuse/file.c | 58 +++++++------------------------------------------- 1 file changed, 8 insertions(+), 50 deletions(-)
fs/fuse/file.c +8 -50
@@ -1052,6 +1052,10 @@ static void fuse_write_args_fill(struct fuse_io_args *ia, struct fuse_file *ff, args->out_args[0 ].value = &ia->write.out; } +/** +* Note: iocb->ki_flags & IOCB_DIRECT cannot be trusted here, +* it might be set when FOPEN_DIRECT_IO is used. +*/ static unsigned int fuse_write_flags (struct kiocb *iocb) {unsigned int flags = iocb->ki_filp->f_flags;
@@ -1631,52 +1635,6 @@ static ssize_t fuse_direct_read_iter(struct kiocb *iocb, struct iov_iter *to)return res; } -static ssize_t fuse_direct_write_iter (struct kiocb *iocb,struct iov_iter *from) -{ -struct inode *inode =file_inode (iocb->ki_filp); -struct fuse_io_priv io =FUSE_IO_PRIV_SYNC (iocb); -ssize_t res; -bool exclusive_lock =fuse_dio_wr_exclusive_lock (iocb, from, inode); - -/* -* Take exclusive lock if -* - Parallel direct writes are disabled - a user space decision -* - Parallel direct writes are enabled and i_size is being extended. -* This might not be needed at all, but needs further investigation. -*/ -if (exclusive_lock) -inode_lock (inode); -else { -inode_lock_shared (inode); - -/* A race with truncate might have come up as the decision for -* the lock type was done without holding the lock, check again. -*/ -if (fuse_io_past_eof (iocb, from)) { -inode_unlock_shared (inode); -inode_lock (inode); - exclusive_lock = true; - } - } - - res =generic_write_checks (iocb, from); -if (res >0 ) { -if (!is_sync_kiocb (iocb) && iocb->ki_flags &IOCB_DIRECT ) { - res =fuse_direct_IO (iocb, from); - }else { - res =fuse_send_dio (&io, from, &iocb->ki_pos, -FUSE_DIO_WRITE ); -fuse_write_update_attr (inode, iocb->ki_pos, res); - } - } -if (exclusive_lock) -inode_unlock (inode); -else -inode_unlock_shared (inode); - -return res; -} -static ssize_t fuse_file_read_iter (struct kiocb *iocb,struct iov_iter *to) {struct file *file = iocb->ki_filp;
@@ -1707,10 +1665,10 @@ static ssize_t fuse_file_write_iter(struct kiocb *iocb, struct iov_iter *from)if (FUSE_IS_DAX (inode))return fuse_dax_write_iter (iocb, from); -if (!(ff->open_flags &FOPEN_DIRECT_IO )) -return fuse_cache_write_iter (iocb, from); -else -return fuse_direct_write_iter (iocb, from); +if (ff->open_flags &FOPEN_DIRECT_IO ) + iocb->ki_flags |=IOCB_DIRECT ; + +return fuse_cache_write_iter (iocb, from); }static void fuse_writepage_free (struct fuse_writepage_args *wpa)
Signature · 1 line
2.39.2
kernel test robot
build botRe: [PATCH v4 07/10] fuse: Remove fuse_direct_write_iter code path / use IOCB_DIRECT
kernel test robot noticed the following build warnings:
Hi Bernd,
kernel test robot noticed the following build warnings:
[auto build test WARNING on mszeredi-fuse/for-next]
[also build test WARNING on linus/master v6.6-rc2 next-20230918] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Bernd-Schubert/fuse-direct-IO-can-use-the-write-through-code-path/20230919-005745 base: https://git.kernel.org/pub/scm/linux/kernel/git/mszeredi/fuse.git for-next patch link: https://lore.kernel.org/r/20230918150313.3845114-8-bschubert%40ddn.com patch subject: [PATCH v4 07/10] fuse: Remove fuse_direct_write_iter code path / use IOCB_DIRECT config: m68k-allyesconfig (https://download.01.org/0day-ci/archive/20230919/[email protected]/config) compiler: m68k-linux-gcc (GCC) 13.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20230919/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All warnings (new ones prefixed by >>):
>> fs/fuse/file.c:1060: warning: Function parameter or member 'iocb' not described in 'fuse_write_flags' >> fs/fuse/file.c:1060: warning: expecting prototype for Note(). Prototype was for fuse_write_flags() instead
vim +1060 fs/fuse/file.c
338f2e3f3341a9 Miklos Szeredi 2019-09-10 1054
abb63dd79fa5c1 Bernd Schubert 2023-09-18 1055 /**
abb63dd79fa5c1 Bernd Schubert 2023-09-18 1056 * Note: iocb->ki_flags & IOCB_DIRECT cannot be trusted here,
abb63dd79fa5c1 Bernd Schubert 2023-09-18 1057 * it might be set when FOPEN_DIRECT_IO is used.
abb63dd79fa5c1 Bernd Schubert 2023-09-18 1058 */
338f2e3f3341a9 Miklos Szeredi 2019-09-10 1059 static unsigned int fuse_write_flags(struct kiocb *iocb)
338f2e3f3341a9 Miklos Szeredi 2019-09-10 @1060 {
338f2e3f3341a9 Miklos Szeredi 2019-09-10 1061 unsigned int flags = iocb->ki_filp->f_flags;
338f2e3f3341a9 Miklos Szeredi 2019-09-10 1062
91b94c5d6ae55d Al Viro 2022-05-22 1063 if (iocb_is_dsync(iocb))
338f2e3f3341a9 Miklos Szeredi 2019-09-10 1064 flags |= O_DSYNC;
338f2e3f3341a9 Miklos Szeredi 2019-09-10 1065 if (iocb->ki_flags & IOCB_SYNC)
338f2e3f3341a9 Miklos Szeredi 2019-09-10 1066 flags |= O_SYNC;
338f2e3f3341a9 Miklos Szeredi 2019-09-10 1067
338f2e3f3341a9 Miklos Szeredi 2019-09-10 1068 return flags;
338f2e3f3341a9 Miklos Szeredi 2019-09-10 1069 }
338f2e3f3341a9 Miklos Szeredi 2019-09-10 1070 Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
Re: [PATCH v4 07/10] fuse: Remove fuse_direct_write_iter code path / use IOCB_DIRECT
Quoted 5 lines · kernel test robot
Hi Bernd,
kernel test robot noticed the following build warnings:
[auto build test WARNING on mszeredi-fuse/for-next]
Thanks, updated patch:
---
From: Bernd Schubert <[email protected]>
Subject: fuse: Remove fuse_direct_write_iter code path / use
IOCB_DIRECT
fuse_direct_write_iter is basically duplicating what is already in fuse_cache_write_iter/generic_file_direct_write. That can be avoided by setting IOCB_DIRECT in fuse_file_write_iter, after that fuse_cache_write_iter can be used for the FOPEN_DIRECT_IO code path and fuse_direct_write_iter can be removed.
Before it was using for FOPEN_DIRECT_IO
1) async (!is_sync_kiocb(iocb)) && IOCB_DIRECT
fuse_file_write_iter
fuse_direct_write_iter
fuse_direct_IO
fuse_send_dio
2) sync (is_sync_kiocb(iocb)) or IOCB_DIRECT not being set
fuse_file_write_iter
fuse_direct_write_iter
fuse_send_dio
3) FOPEN_DIRECT_IO not set
Same as the consolidates path below
The new consolidated code path is always
fuse_file_write_iter
fuse_cache_write_iter
generic_file_write_iter
__generic_file_write_iter
generic_file_direct_write
mapping->a_ops->direct_IO / fuse_direct_IO
fuse_send_dioSo in general for FOPEN_DIRECT_IO the code path gets longer. Additionally fuse_direct_IO does an allocation of struct fuse_io_priv - might be a bit slower in micro benchmarks.
Also, the IOCB_DIRECT information gets lost (as we now set it outselves). But then IOCB_DIRECT is directly related to O_DIRECT set in struct file::f_flags.
An additional change is for condition 2 above, which might will now do async IO on the condition ff->fm->fc->async_dio. Given that async IO for FOPEN_DIRECT_IO was especially introduced in commit
'commit 23c94e1cdcbf ("fuse: Switch to using async direct IO for
FOPEN_DIRECT_IO")'
it should not matter. Especially as fuse_direct_IO is blocking for is_sync_kiocb(), at worst it has another slight overhead.
Advantage is the removal of code paths and conditions and it is now also possible to remove FOPEN_DIRECT_IO conditions in fuse_send_dio (in a later patch).
--- fs/fuse/file.c | 60 +++++++++----------------------------------------- 1 file changed, 10 insertions(+), 50 deletions(-)
fs/fuse/file.c +10 -50
@@ -1061,6 +1061,12 @@ static unsigned int fuse_write_flags(struct kiocb *iocb)if (iocb->ki_flags &IOCB_SYNC ) flags |=O_SYNC ; +/* +* Note: If O_DIRECT should be ever added here, +* iocb->ki_flags & IOCB_DIRECT cannot be trusted when +* FOPEN_DIRECT_IO is set. +*/ +return flags; }
@@ -1631,52 +1637,6 @@ static ssize_t fuse_direct_read_iter(struct kiocb *iocb, struct iov_iter *to)return res; } -static ssize_t fuse_direct_write_iter (struct kiocb *iocb,struct iov_iter *from) -{ -struct inode *inode =file_inode (iocb->ki_filp); -struct fuse_io_priv io =FUSE_IO_PRIV_SYNC (iocb); -ssize_t res; -bool exclusive_lock =fuse_dio_wr_exclusive_lock (iocb, from, inode); - -/* -* Take exclusive lock if -* - Parallel direct writes are disabled - a user space decision -* - Parallel direct writes are enabled and i_size is being extended. -* This might not be needed at all, but needs further investigation. -*/ -if (exclusive_lock) -inode_lock (inode); -else { -inode_lock_shared (inode); - -/* A race with truncate might have come up as the decision for -* the lock type was done without holding the lock, check again. -*/ -if (fuse_io_past_eof (iocb, from)) { -inode_unlock_shared (inode); -inode_lock (inode); - exclusive_lock = true; - } - } - - res =generic_write_checks (iocb, from); -if (res >0 ) { -if (!is_sync_kiocb (iocb) && iocb->ki_flags &IOCB_DIRECT ) { - res =fuse_direct_IO (iocb, from); - }else { - res =fuse_send_dio (&io, from, &iocb->ki_pos, -FUSE_DIO_WRITE ); -fuse_write_update_attr (inode, iocb->ki_pos, res); - } - } -if (exclusive_lock) -inode_unlock (inode); -else -inode_unlock_shared (inode); - -return res; -} -static ssize_t fuse_file_read_iter (struct kiocb *iocb,struct iov_iter *to) {struct file *file = iocb->ki_filp;
@@ -1707,10 +1667,10 @@ static ssize_t fuse_file_write_iter(struct kiocb *iocb, struct iov_iter *from)if (FUSE_IS_DAX (inode))return fuse_dax_write_iter (iocb, from); -if (!(ff->open_flags &FOPEN_DIRECT_IO )) -return fuse_cache_write_iter (iocb, from); -else -return fuse_direct_write_iter (iocb, from); +if (ff->open_flags &FOPEN_DIRECT_IO ) + iocb->ki_flags |=IOCB_DIRECT ; + +return fuse_cache_write_iter (iocb, from); }static void fuse_writepage_free (struct fuse_writepage_args *wpa)
Signature · 1 line
2.39.2
PATCH v4 8/10 fuse: Remove page flush/invaliation in fuse_direct_io
In reply to Bernd SchubertPage flush and invalidation in fuse_direct_io can when FOPEN_DIRECT_IO is set can be removed, as the code path is now always via generic_file_direct_write, which already does it.
--- fs/fuse/file.c | 17 ----------------- 1 file changed, 17 deletions(-)
fs/fuse/file.c +0 -17
@@ -1519,20 +1519,11 @@ ssize_t fuse_send_dio(struct fuse_io_priv *io, struct iov_iter *iter,int err =0 ;struct fuse_io_args *ia;unsigned int max_pages; -bool fopen_direct_io = ff->open_flags &FOPEN_DIRECT_IO ; - max_pages =iov_iter_npages (iter, fc->max_pages); ia =fuse_io_alloc (io, max_pages);if (!ia)return -ENOMEM ; -if (fopen_direct_io && fc->direct_io_relax) { - res =filemap_write_and_wait_range (mapping, pos, pos + count -1 ); -if (res) { -fuse_io_free (ia); -return res; - } - }if (!cuse &&fuse_range_is_writeback (inode, idx_from, idx_to)) {if (!write)inode_lock (inode);
@@ -1541,14 +1532,6 @@ ssize_t fuse_send_dio(struct fuse_io_priv *io, struct iov_iter *iter,inode_unlock (inode); } -if (fopen_direct_io && write) { - res =invalidate_inode_pages2_range (mapping, idx_from, idx_to); -if (res) { -fuse_io_free (ia); -return res; - } - } - io->should_dirty = !write &&user_backed_iter (iter);while (count) {ssize_t nres;
Signature · 1 line
2.39.2
PATCH v4 9/10 fuse: Use the existing inode fuse_cache_write_iter
In reply to Bernd Schubertmakes the code slightly smaller, I guess the compiler would havve optimized that out already.
The other is file_inode(file), but I'm not sure if there is any risk that they might differ.
--- fs/fuse/file.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/fuse/file.c +1 -1
@@ -1352,7 +1352,7 @@ static ssize_t fuse_cache_write_iter(struct kiocb *iocb, struct iov_iter *from)if (fc->writeback_cache && !(iocb->ki_flags &IOCB_DIRECT )) {/* Update size (EOF optimization) and mode (SUID clearing) */ - err =fuse_update_attributes (mapping->host, file, + err =fuse_update_attributes (inode, file,STATX_SIZE |STATX_MODE );if (err)return err;
Signature · 1 line
2.39.2
RFC PATCH v4 10/10 fuse: No privilege removal when FOPEN_DIRECT_IO is set
In reply to Bernd SchubertTraditionally this was not done for FOPEN_DIRECT_IO and adding it might have a performance impact.
The better solution would be probably to have a xattr cache.
--- fs/fuse/file.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
fs/fuse/file.c +5 -2
@@ -1342,13 +1342,16 @@ static bool fuse_dio_wr_exclusive_lock(struct kiocb *iocb, struct iov_iter *fromstatic ssize_t fuse_cache_write_iter (struct kiocb *iocb,struct iov_iter *from) {struct file *file = iocb->ki_filp; +struct fuse_file *ff = file->private_data;struct address_space *mapping = file->f_mapping;ssize_t written =0 ;struct inode *inode = mapping->host;ssize_t err;struct fuse_conn *fc =get_fuse_conn (inode);bool excl_lock =fuse_dio_wr_exclusive_lock (iocb, from, inode); -int remove_privs =1 ; + +/* traditionally FOPEN_DIRECT_IO does not do remove privileges */ +int remove_privs = ff->open_flags &FOPEN_DIRECT_IO ?0 :1 ;if (fc->writeback_cache && !(iocb->ki_flags &IOCB_DIRECT )) {/* Update size (EOF optimization) and mode (SUID clearing) */
@@ -1386,7 +1389,7 @@ static ssize_t fuse_cache_write_iter(struct kiocb *iocb, struct iov_iter *from)if (err <=0 ) goto out; -if (!excl_lock) { +if (!excl_lock && remove_privs) { remove_privs =file_needs_remove_privs (file);if (remove_privs) {inode_unlock_shared (inode);
Signature · 1 line
2.39.2