io_uring getdents
Subsystems (33)
v6 cover io_uring getdents
From: Hao Xu <[email protected]>
This series introduce getdents64 to io_uring, the code logic is similar with the snychronized version's. It first try nowait issue, and offload it to io-wq threads if the first try fails.
Patch1 and Patch2 are some preparation
Patch3 supports nowait for xfs getdents code
Patch4-11 are vfs change, include adding helpers and trylock for locks
Tests I've done:
A liburing test case for functional test:
https://github.com/HowHsu/liburing/commit/39dc9a8e19c06a8cebf8c2301b85320eb45c061e?diff=unified
Tested it with a liburing performance test:
https://github.com/HowHsu/liburing/blob/getdents/test/getdents2.c
The test is controlled by the below script[2] which runs getdents2.t 100 times and calulate the avg.
The result show that io_uring version is about 2.6% faster:
note:
[1] the number of getdents call/request in io_uring and normal sync version are made sure to be same beforehand.
[2] run_getdents.py
```python3
import subprocess
N = 100
sum = 0.0
args = ["/data/home/howeyxu/tmpdir", "sync"]
for i in range(N):
output = subprocess.check_output(["./liburing/test/getdents2.t"] + args)
sum += float(output)
average = sum / N
print("Average of sync:", average)
sum = 0.0
args = ["/data/home/howeyxu/tmpdir", "iouring"]
for i in range(N):
output = subprocess.check_output(["./liburing/test/getdents2.t"] + args)
sum += float(output)
average = sum / N
print("Average of iouring:", average)
```v5->v6:
- remove xfs journal stuff since there are fundamental issues in the design.
v4->v5:
- move atime update to the beginning of getdents operation
- trylock for i_rwsem
- nowait semantics for involved xfs journal stuff
v3->v4:
- add Dave's xfs nowait code and fix a deadlock problem, with some code style tweak.
- disable fixed file to avoid a race problem for now
- add a test program.
v2->v3:
- removed the kernfs patches
- add f_pos_lock logic
- remove the "reduce last EOF getdents try" optimization since Dominique reports that doesn't make difference
- remove the rewind logic, I think the right way is to introduce lseek to io_uring not to patch this logic to getdents.
- add Singed-off-by of Stefan Roesch for patch 1 since checkpatch complained that Co-developed-by someone should be accompanied with Signed-off-by same person, I can remove them if Stefan thinks that's not proper.
Dominique Martinet (1):
fs: split off vfs_getdents function of getdents64 syscall
Hao Xu (10):
xfs: add NOWAIT semantics for readdir
vfs: add nowait flag for struct dir_context
vfs: add a vfs helper for io_uring file pos lock
vfs: add file_pos_unlock() for io_uring usage
vfs: add a nowait parameter for touch_atime()
vfs: add nowait parameter for file_accessed()
vfs: move file_accessed() to the beginning of iterate_dir()
vfs: error out -EAGAIN if atime needs to be updated
vfs: trylock inode->i_rwsem in iterate_dir() to support nowait
io_uring: add support for getdents
arch/s390/hypfs/inode.c | 2 +- block/fops.c | 2 +- fs/btrfs/file.c | 2 +- fs/btrfs/inode.c | 2 +- fs/cachefiles/namei.c | 2 +- fs/coda/dir.c | 4 +-- fs/ecryptfs/file.c | 4 +-- fs/ext2/file.c | 4 +-- fs/ext4/file.c | 6 ++-- fs/f2fs/file.c | 4 +-- fs/file.c | 13 ++++++++ fs/fuse/dax.c | 2 +- fs/fuse/file.c | 4 +-- fs/gfs2/file.c | 2 +- fs/hugetlbfs/inode.c | 2 +- fs/inode.c | 10 ++++-- fs/internal.h | 8 +++++ fs/namei.c | 4 +-- fs/nfsd/vfs.c | 2 +- fs/nilfs2/file.c | 2 +- fs/orangefs/file.c | 2 +- fs/orangefs/inode.c | 2 +- fs/overlayfs/file.c | 2 +- fs/overlayfs/inode.c | 2 +- fs/pipe.c | 2 +- fs/ramfs/file-nommu.c | 2 +- fs/readdir.c | 61 ++++++++++++++++++++++++++-------- fs/smb/client/cifsfs.c | 2 +- fs/splice.c | 2 +- fs/stat.c | 2 +- fs/ubifs/file.c | 2 +- fs/udf/file.c | 2 +- fs/xfs/libxfs/xfs_da_btree.c | 16 +++++++++ fs/xfs/libxfs/xfs_da_btree.h | 1 + fs/xfs/libxfs/xfs_dir2_block.c | 7 ++-- fs/xfs/libxfs/xfs_dir2_priv.h | 2 +- fs/xfs/scrub/dir.c | 2 +- fs/xfs/scrub/readdir.c | 2 +- fs/xfs/xfs_dir2_readdir.c | 49 +++++++++++++++++++++------ fs/xfs/xfs_file.c | 6 ++-- fs/xfs/xfs_inode.c | 27 +++++++++++++++ fs/xfs/xfs_inode.h | 17 ++++++---- fs/zonefs/file.c | 4 +-- include/linux/file.h | 7 ++++ include/linux/fs.h | 15 +++++++-- include/uapi/linux/io_uring.h | 1 + io_uring/fs.c | 53 +++++++++++++++++++++++++++++ io_uring/fs.h | 3 ++ io_uring/opdef.c | 8 +++++ kernel/bpf/inode.c | 4 +-- mm/filemap.c | 8 ++--- mm/shmem.c | 6 ++-- net/unix/af_unix.c | 4 +-- 53 files changed, 310 insertions(+), 96 deletions(-)
Signature · 1 line
2.25.1
PATCH v6 1/11 fs: split off vfs_getdents function of getdents64 syscall
From: Dominique Martinet <[email protected]>
This splits off the vfs_getdents function from the getdents64 system call.
This will allow io_uring to call the vfs_getdents function.
--- fs/internal.h | 8 ++++++++ fs/readdir.c | 34 ++++++++++++++++++++++++++-------- 2 files changed, 34 insertions(+), 8 deletions(-)
fs/internal.h +8 -0
@@ -304,3 +304,11 @@ ssize_t __kernel_write_iter(struct file *file, struct iov_iter *from, loff_t *postruct mnt_idmap *alloc_mnt_idmap (struct user_namespace *mnt_userns);struct mnt_idmap *mnt_idmap_get (struct mnt_idmap *idmap);void mnt_idmap_put (struct mnt_idmap *idmap); + +/* +* fs/readdir.c +*/ +struct linux_dirent64 ; + +int vfs_getdents (struct file *file,struct linux_dirent64 __user *dirent, +unsigned int count);
fs/readdir.c +26 -8
@@ -21,6 +21,7 @@#include <linux/unistd.h> #include <linux/compat.h> #include <linux/uaccess.h> +#include "internal.h" #include <asm/unaligned.h>
@@ -351,10 +352,16 @@ static bool filldir64(struct dir_context *ctx, const char *name, int namlen,return false; } -SYSCALL_DEFINE3(getdents64, unsigned int, fd, - struct linux_dirent64 __user *, dirent, unsigned int, count) + +/** +* vfs_getdents - getdents without fdget +* @file : pointer to file struct of directory +* @dirent : pointer to user directory structure +* @count : size of buffer +*/ +int vfs_getdents (struct file *file,struct linux_dirent64 __user *dirent, +unsigned int count) { -struct fd f;struct getdents_callback64 buf = { .ctx.actor = filldir64, .count = count,
@@ -362,11 +369,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd, };int error; - f =fdget_pos (fd); -if (!f.file) -return -EBADF ; - - error =iterate_dir (f.file, &buf.ctx); + error =iterate_dir (file, &buf.ctx);if (error >=0 ) error = buf.error;if (buf.prev_reclen) {
@@ -379,6 +382,21 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,else error = count - buf.count; } +return error; +} + +SYSCALL_DEFINE3(getdents64, unsigned int, fd, + struct linux_dirent64 __user *, dirent, unsigned int, count) +{ +struct fd f; +int error; + + f =fdget_pos (fd); +if (!f.file) +return -EBADF ; + + error =vfs_getdents (f.file, dirent, count); +fdput_pos (f);return error; }
Signature · 1 line
2.25.1
PATCH v6 2/11 xfs: add NOWAIT semantics for readdir
In reply to Hao XuFrom: Hao Xu <[email protected]>
Implement NOWAIT semantics for readdir. Return EAGAIN error to the caller if it would block, like failing to get locks, or going to do IO.
--- fs/xfs/libxfs/xfs_da_btree.c | 16 +++++++++++ fs/xfs/libxfs/xfs_da_btree.h | 1 + fs/xfs/libxfs/xfs_dir2_block.c | 7 ++--- fs/xfs/libxfs/xfs_dir2_priv.h | 2 +- fs/xfs/scrub/dir.c | 2 +- fs/xfs/scrub/readdir.c | 2 +- fs/xfs/xfs_dir2_readdir.c | 49 ++++++++++++++++++++++++++-------- fs/xfs/xfs_inode.c | 27 +++++++++++++++++++ fs/xfs/xfs_inode.h | 17 +++++++----- 9 files changed, 99 insertions(+), 24 deletions(-)
fs/xfs/libxfs/xfs_da_btree.c +16 -0
@@ -2643,16 +2643,32 @@ xfs_da_read_buf(struct xfs_buf_map map, *mapp = ↦int nmap =1 ;int error; +int buf_flags =0 ; *bpp =NULL ; error =xfs_dabuf_map (dp, bno, flags, whichfork, &mapp, &nmap);if (error || !nmap) goto out_free; +/* +* NOWAIT semantics mean we don't wait on the buffer lock nor do we +* issue IO for this buffer if it is not already in memory. Caller will +* retry. This will return -EAGAIN if the buffer is in memory and cannot +* be locked, and no buffer and no error if it isn't in memory. We +* translate both of those into a return state of -EAGAIN and *bpp = +* NULL. +*/ +if (flags &XFS_DABUF_NOWAIT ) + buf_flags |=XBF_TRYLOCK |XBF_INCORE ; error =xfs_trans_read_buf_map (mp, tp, mp->m_ddev_targp, mapp, nmap,0 , &bp, ops);if (error) goto out_free; +if (!bp) { +ASSERT (flags &XFS_DABUF_NOWAIT ); + error = -EAGAIN ; + goto out_free; + }if (whichfork ==XFS_ATTR_FORK )xfs_buf_set_ref (bp,XFS_ATTR_BTREE_REF );
fs/xfs/libxfs/xfs_da_btree.h +1 -0
@@ -205,6 +205,7 @@ int xfs_da3_node_read_mapped(struct xfs_trans *tp, struct xfs_inode *dp,*/ #define XFS_DABUF_MAP_HOLE_OK (1u << 0) +#define XFS_DABUF_NOWAIT (1u << 1)int xfs_da_grow_inode (xfs_da_args_t *args,xfs_dablk_t *new_blkno); int xfs_da_grow_inode_int(struct xfs_da_args *args, xfs_fileoff_t *bno,
fs/xfs/libxfs/xfs_dir2_block.c +4 -3
@@ -135,13 +135,14 @@ intxfs_dir3_block_read ( struct xfs_trans *tp, struct xfs_inode *dp, + unsigned int flags, struct xfs_buf **bpp) { struct xfs_mount *mp = dp->i_mount;xfs_failaddr_t fa;int err; - err =xfs_da_read_buf (tp, dp, mp->m_dir_geo->datablk,0 , bpp, + err =xfs_da_read_buf (tp, dp, mp->m_dir_geo->datablk, flags, bpp,XFS_DATA_FORK , &xfs_dir3_block_buf_ops);if (err || !*bpp)return err;
@@ -380,7 +381,7 @@ xfs_dir2_block_addname( tp = args->trans;/* Read the (one and only) directory block into bp. */ - error =xfs_dir3_block_read (tp, dp, &bp); + error =xfs_dir3_block_read (tp, dp,0 , &bp);if (error)return error;
@@ -695,7 +696,7 @@ xfs_dir2_block_lookup_int( dp = args->dp; tp = args->trans; - error =xfs_dir3_block_read (tp, dp, &bp); + error =xfs_dir3_block_read (tp, dp,0 , &bp);if (error)return error;
fs/xfs/libxfs/xfs_dir2_priv.h +1 -1
@@ -51,7 +51,7 @@ extern int xfs_dir_cilookup_result(struct xfs_da_args *args,/* xfs_dir2_block.c */ extern int xfs_dir3_block_read (struct xfs_trans *tp,struct xfs_inode *dp, -struct xfs_buf **bpp); +unsigned int flags,struct xfs_buf **bpp);extern int xfs_dir2_block_addname (struct xfs_da_args *args);extern int xfs_dir2_block_lookup (struct xfs_da_args *args);extern int xfs_dir2_block_removename (struct xfs_da_args *args);
fs/xfs/scrub/dir.c +1 -1
@@ -313,7 +313,7 @@ xchk_directory_data_bestfree(/* dir block format */ if (lblk !=XFS_B_TO_FSBT (mp,XFS_DIR2_DATA_OFFSET ))xchk_fblock_set_corrupt (sc,XFS_DATA_FORK , lblk); - error =xfs_dir3_block_read (sc->tp, sc->ip, &bp); + error =xfs_dir3_block_read (sc->tp, sc->ip,0 , &bp); }else {/* dir data format */ error =xfs_dir3_data_read (sc->tp, sc->ip, lblk,0 , &bp);
fs/xfs/scrub/readdir.c +1 -1
@@ -101,7 +101,7 @@ xchk_dir_walk_block(unsigned int off, next_off, end;int error; - error =xfs_dir3_block_read (sc->tp, dp, &bp); + error =xfs_dir3_block_read (sc->tp, dp,0 , &bp);if (error)return error;
fs/xfs/xfs_dir2_readdir.c +38 -11
120 lines not on this page · raw message
fs/xfs/xfs_inode.c +27 -0
@@ -120,6 +120,33 @@ xfs_ilock_data_map_shared(return lock_mode; } +/* +* Similar to xfs_ilock_data_map_shared(), except that it will only try to lock +* the inode in shared mode if the extents are already in memory. If it fails to +* get the lock or has to do IO to read the extent list, fail the operation by +* returning 0 as the lock mode. +*/ +uint +xfs_ilock_data_map_shared_nowait ( +struct xfs_inode *ip) +{ +if (xfs_need_iread_extents (&ip->i_df)) +return 0 ; +if (!xfs_ilock_nowait (ip,XFS_ILOCK_SHARED )) +return 0 ; +return XFS_ILOCK_SHARED ; +} + +int +xfs_ilock_data_map_shared_generic ( +struct xfs_inode *dp, +bool nowait) +{ +if (nowait) +return xfs_ilock_data_map_shared_nowait (dp); +return xfs_ilock_data_map_shared (dp); +} +uint xfs_ilock_attr_map_shared (struct xfs_inode *ip)
fs/xfs/xfs_inode.h +10 -7
@@ -490,13 +490,16 @@ int xfs_rename(struct mnt_idmap *idmap,struct xfs_name *target_name, struct xfs_inode *target_ip, unsigned int flags); -void xfs_ilock (xfs_inode_t *,uint ); -int xfs_ilock_nowait (xfs_inode_t *,uint ); -void xfs_iunlock (xfs_inode_t *,uint ); -void xfs_ilock_demote (xfs_inode_t *,uint ); -bool xfs_isilocked (struct xfs_inode *,uint ); -uint xfs_ilock_data_map_shared (struct xfs_inode *); -uint xfs_ilock_attr_map_shared (struct xfs_inode *); +void xfs_ilock (struct xfs_inode *ip,uint lockmode); +int xfs_ilock_nowait (struct xfs_inode *ip,uint lockmode); +void xfs_iunlock (struct xfs_inode *ip,uint lockmode); +void xfs_ilock_demote (struct xfs_inode *ip,uint lockmode); +bool xfs_isilocked (struct xfs_inode *ip,uint lockmode); +uint xfs_ilock_data_map_shared (struct xfs_inode *ip); +uint xfs_ilock_data_map_shared_nowait (struct xfs_inode *ip); +int xfs_ilock_data_map_shared_generic (struct xfs_inode *ip, +bool nowait); +uint xfs_ilock_attr_map_shared (struct xfs_inode *ip);uint xfs_ip2xflags (struct xfs_inode *);int xfs_ifree (struct xfs_trans *,struct xfs_inode *);
Signature · 1 line
2.25.1
Matthew Wilcox
maintainerRe: [PATCH 02/11] xfs: add NOWAIT semantics for readdir
Quoted 10 lines · Hao Xu
+++
b/fs/xfs/libxfs/xfs_da_btree.cfs/xfs/libxfs/xfs_da_btree.c +1
-0@@ -2643,16 +2643,32 @@ xfs_da_read_buf(struct xfs_buf_map map, *mapp = ↦int nmap =1 ;int error; +int buf_flags =0 ; *bpp =NULL ; error =xfs_dabuf_map (dp, bno, flags, whichfork, &mapp, &nmap);if (error || !nmap)
fs/xfs/libxfs/xfs_da_btree.c xfs_da_read_buf( · line 2660
Quoted 10 lines
fs/xfs/libxfs/xfs_da_btree.c +8
-0goto out_free; +/* +* NOWAIT semantics mean we don't wait on the buffer lock nor do we +* issue IO for this buffer if it is not already in memory. Caller will +* retry. This will return -EAGAIN if the buffer is in memory and cannot +* be locked, and no buffer and no error if it isn't in memory. We +* translate both of those into a return state of -EAGAIN and *bpp = +* NULL. +*/
I would not include this comment.
fs/xfs/libxfs/xfs_da_btree.c xfs_da_read_buf( · line 2664
Quoted 4 lines
fs/xfs/libxfs/xfs_da_btree.c +2
-0+if (flags &XFS_DABUF_NOWAIT ) + buf_flags |=XBF_TRYLOCK |XBF_INCORE ; error =xfs_trans_read_buf_map (mp, tp, mp->m_ddev_targp, mapp, nmap,0 , &bp, ops);
what tsting did you do with this? Because you don't actually _use_ buf_flags anywhere in this patch (presumably they should be the sixth argument to xfs_trans_read_buf_map() instead of 0). So I can only conclude that either you didn't test, or your testing was inadequate.
fs/xfs/libxfs/xfs_da_btree.c xfs_da_read_buf( · line 2668
Quoted 4 lines
fs/xfs/libxfs/xfs_da_btree.c +2
-0if (error) goto out_free; +if (!bp) { +ASSERT (flags &XFS_DABUF_NOWAIT );
I don't think this ASSERT is appropriate.
Quoted 5 lines
fs/xfs/xfs_dir2_readdir.c +0
-1@@ -391,10 +401,17 @@ xfs_dir2_leaf_getdents( bp =NULL ; } -if (*lock_mode ==0 )
fs/xfs/xfs_dir2_readdir.c xfs_dir2_leaf_getdents( · line 412
Quoted 10 lines
fs/xfs/xfs_dir2_readdir.c +9
-1- *lock_mode =xfs_ilock_data_map_shared (dp); +if (*lock_mode ==0 ) { + *lock_mode = +xfs_ilock_data_map_shared_generic (dp, + ctx->flags &DIR_CONTEXT_F_NOWAIT ); +if (!*lock_mode) { + error = -EAGAIN ; +break ; + } + }
'generic' doesn't seem like a great suffix to mean 'takes nowait flag'. And this is far too far indented.
xfs_dir2_lock(dp, ctx, lock_mode);
with:
STATIC void xfs_dir2_lock(struct xfs_inode *dp, struct dir_context *ctx,
unsigned int lock_mode)
{
if (*lock_mode)
return;
if (ctx->flags & DIR_CONTEXT_F_NOWAIT)
return xfs_ilock_data_map_shared_nowait(dp);
return xfs_ilock_data_map_shared(dp);
}... which I think you can use elsewhere in this patch (reformat it to XFS coding style, of course). And then you don't need xfs_ilock_data_map_shared_generic().
Re: [PATCH 02/11] xfs: add NOWAIT semantics for readdir
Quoted 13 lines · Matthew Wilcox
Quoted 12 lines · Hao Xu
+++
b/fs/xfs/libxfs/xfs_da_btree.cfs/xfs/libxfs/xfs_da_btree.c +1
-0@@ -2643,16 +2643,32 @@ xfs_da_read_buf(struct xfs_buf_map map, *mapp = ↦int nmap =1 ;int error; +int buf_flags =0 ; *bpp =NULL ; error =xfs_dabuf_map (dp, bno, flags, whichfork, &mapp, &nmap);if (error || !nmap) goto out_free;
Quoted 10 lines
fs/xfs/libxfs/xfs_da_btree.c xfs_da_read_buf( · line 2660
Quoted 8 lines
fs/xfs/libxfs/xfs_da_btree.c +8
-0+/* +* NOWAIT semantics mean we don't wait on the buffer lock nor do we +* issue IO for this buffer if it is not already in memory. Caller will +* retry. This will return -EAGAIN if the buffer is in memory and cannot +* be locked, and no buffer and no error if it isn't in memory. We +* translate both of those into a return state of -EAGAIN and *bpp = +* NULL. +*/ I would not include this comment.
No strong comment here, since this patch is mostly from Dave, it's better if Dave can ack this.
Quoted 11 lines
fs/xfs/libxfs/xfs_da_btree.c xfs_da_read_buf( · line 2664
Quoted 5 lines
fs/xfs/libxfs/xfs_da_btree.c +2
-0+if (flags &XFS_DABUF_NOWAIT ) + buf_flags |=XBF_TRYLOCK |XBF_INCORE ; error =xfs_trans_read_buf_map (mp, tp, mp->m_ddev_targp, mapp, nmap,0 , &bp, ops);what tsting did you do with this? Because you don't actually _use_
buf_flagsanywhere in this patch (presumably they should be the sixth argument toxfs_trans_read_buf_map()instead of 0). So I can only conclude that either you didn't test, or your testing was inadequate.
The tests I've done are listed in the cover-letter, this one is missed, the tricky place is it's hard to get this kind of mistake since it runs well without nowait logic...I'll fix it in next version.
Quoted 40 lines
fs/xfs/libxfs/xfs_da_btree.c xfs_da_read_buf( · line 2668
Quoted 4 lines
fs/xfs/libxfs/xfs_da_btree.c +2
-0if (error) goto out_free; +if (!bp) { +ASSERT (flags &XFS_DABUF_NOWAIT );I don't think this ASSERT is appropriate.
Quoted 5 lines
fs/xfs/xfs_dir2_readdir.c +0
-1@@ -391,10 +401,17 @@ xfs_dir2_leaf_getdents( bp =NULL ; } -if (*lock_mode ==0 )fs/xfs/xfs_dir2_readdir.c xfs_dir2_leaf_getdents( · line 412
Quoted 10 lines
fs/xfs/xfs_dir2_readdir.c +9
-1- *lock_mode =xfs_ilock_data_map_shared (dp); +if (*lock_mode ==0 ) { + *lock_mode = +xfs_ilock_data_map_shared_generic (dp, + ctx->flags &DIR_CONTEXT_F_NOWAIT ); +if (!*lock_mode) { + error = -EAGAIN ; +break ; + } + }'generic' doesn't seem like a great suffix to mean 'takes nowait flag'. And this is far too far indented.
xfs_dir2_lock(dp, ctx, lock_mode);with:
STATIC void xfs_dir2_lock(struct
xfs_inode*dp, structdir_context*ctx,
unsigned intlock_mode){ if (*lock_mode) return; if (ctx->flags & DIR_CONTEXT_F_NOWAIT) return xfs_ilock_data_map_shared_nowait(dp); return xfs_ilock_data_map_shared(dp); }
Quoted 4 lines
... which I think you can use elsewhere in this patch (reformat it to XFS coding style, of course). And then you don't need
xfs_ilock_data_map_shared_generic().
How about rename xfs_ilock_data_map_shared() to xfs_ilock_data_map_block() and rename xfs_ilock_data_map_shared_generic() to xfs_ilock_data_map_shared()?
STATIC void xfs_ilock_data_map_shared(struct xfs_inode *dp, struct dir_context *ctx, unsigned int lock_mode) {
if (*lock_mode)
return;
if (ctx->flags & DIR_CONTEXT_F_NOWAIT)
return xfs_ilock_data_map_shared_nowait(dp);
return xfs_ilock_data_map_shared_block(dp);
}
Matthew Wilcox
maintainerRe: [PATCH 02/11] xfs: add NOWAIT semantics for readdir
Quoted 49 lines · Hao Xu
Quoted 32 lines · Matthew Wilcox
Quoted 4 lines
fs/xfs/xfs_dir2_readdir.c +0
-1@@ -391,10 +401,17 @@ xfs_dir2_leaf_getdents( bp =NULL ; } -if (*lock_mode ==0 )fs/xfs/xfs_dir2_readdir.c xfs_dir2_leaf_getdents( · line 411
Quoted 10 lines
fs/xfs/xfs_dir2_readdir.c +9
-1- *lock_mode =xfs_ilock_data_map_shared (dp); +if (*lock_mode ==0 ) { + *lock_mode = +xfs_ilock_data_map_shared_generic (dp, + ctx->flags &DIR_CONTEXT_F_NOWAIT ); +if (!*lock_mode) { + error = -EAGAIN ; +break ; + } + }'generic' doesn't seem like a great suffix to mean 'takes nowait flag'. And this is far too far indented.
xfs_dir2_lock(dp, ctx, lock_mode);with:
STATIC void xfs_dir2_lock(struct
xfs_inode*dp, structdir_context*ctx,
unsigned intlock_mode){ if (*lock_mode) return; if (ctx->flags & DIR_CONTEXT_F_NOWAIT) return xfs_ilock_data_map_shared_nowait(dp); return xfs_ilock_data_map_shared(dp); }Quoted 3 lines
... which I think you can use elsewhere in this patch (reformat it to XFS coding style, of course). And then you don't need
xfs_ilock_data_map_shared_generic().How about rename
xfs_ilock_data_map_shared()toxfs_ilock_data_map_block()and renamexfs_ilock_data_map_shared_generic()toxfs_ilock_data_map_shared()?STATIC void
xfs_ilock_data_map_shared(struct xfs_inode *dp, struct dir_context *ctx, unsigned int lock_mode)
{(quoted diff) +0
-0if (*lock_mode) return; if (ctx->flags & DIR_CONTEXT_F_NOWAIT) return xfs_ilock_data_map_shared_nowait(dp); return xfs_ilock_data_map_shared_block(dp);
Quoted 1 line
}
xfs_ilock_data_map_shared() is used for a lot of things which are not directories. I think a new function name is appropriate, and that function name should include the word 'dir' in it somewhere.
Re: [PATCH 02/11] xfs: add NOWAIT semantics for readdir
In reply to Hao XuQuoted 7 lines · Hao Xu
From: Hao Xu <[email protected]>
Implement NOWAIT semantics for readdir. Return EAGAIN error to the caller if it would block, like failing to get locks, or going to do IO.
Co-developed-by Dave Chinner <[email protected]>
Not really.
"Co-developed" implies equal development input between all the parties, which is not the case here - this patch is based on prototype I wrote, whilst you're doing the refining, testing and correctness work.
In these cases with XFS code, we add a line in the commit message to say:
"This is based on a patch originally written by Dave Chinner."
Quoted 3 lines
Signed-off-by Dave Chinner <[email protected]>Signed-off-by Hao Xu <[email protected]>[fixes deadlock issue, tweak code style]
With a signoff chain like you already have.
In the end you'll also get a RVB from me, which seems rather wrong to me if I've apparently been "co-developing" the code....
....
fs/xfs/xfs_dir2_readdir.c xfs_dir2_block_getdents( · line 165
Quoted 11 lines
fs/xfs/xfs_dir2_readdir.c +3
-1@@ -156,7 +157,9 @@ xfs_dir2_block_getdents(if (xfs_dir2_dataptr_to_db (geo, ctx->pos) > geo->datablk)return 0 ; - error =xfs_dir3_block_read (args->trans, dp, &bp); +if (ctx->flags &DIR_CONTEXT_F_NOWAIT ) + flags |=XFS_DABUF_NOWAIT ; + error =xfs_dir3_block_read (args->trans, dp, flags, &bp);if (error)return error;
Given we do this same check in both block and leaf formats to set XFS_DABUF_NOWAIT, and we do the DIR_CONTEXT_F_NOWAIT check in xfs_readdir() as well, we should probably do this check once at the higher level and pass flags down from there with XFS_DABUF_NOWAIT already set.
Quoted 15 lines
fs/xfs/xfs_dir2_readdir.c +1
-3@@ -240,6 +243,7 @@ xfs_dir2_block_getdents( STATIC int xfs_dir2_leaf_readbuf( struct xfs_da_args *args, + struct dir_context *ctx, size_t bufsize, xfs_dir2_off_t *cur_off, xfs_dablk_t *ra_blk,@@ -258,10 +262,15 @@ xfs_dir2_leaf_readbuf(struct xfs_iext_cursor icur;int ra_want;int error =0 ; - - error =xfs_iread_extents (args->trans, dp,XFS_DATA_FORK ); -if (error)
fs/xfs/xfs_dir2_readdir.c xfs_dir2_leaf_readbuf( · line 273
Quoted 10 lines
fs/xfs/xfs_dir2_readdir.c +9
-1- goto out; +unsigned int flags =0 ; + +if (ctx->flags &DIR_CONTEXT_F_NOWAIT ) { + flags |=XFS_DABUF_NOWAIT ; + }else { + error =xfs_iread_extents (args->trans, dp,XFS_DATA_FORK ); +if (error) + goto out; + }
Especially as, in hindsight, this doesn't make a whole lot of sense. If XFS_DABUF_NOWAIT is set, we keep going until xfs_ilock_data_map_shared_nowait() where we call xfs_need_iread_extents() to see if we need to read the extents in and abort at that point.
So, really, we shouldn't get this far with nowait semantics if we haven't read the extents in yet - we're supposed to already have the inode locked here and so we should have already checked this condition before we bother locking the inode...
i.e. all we should be doing here is this:
if (!(flags & XFS_DABUF_NOWAIT)) {
error = xfs_iread_extents(args->trans, dp, XFS_DATA_FORK);
if (error)
goto out;
}And then we don't need to pass the VFS dir_context down into low level XFS functions unnecessarily.
Quoted 29 lines
fs/xfs/xfs_dir2_readdir.c +3
-5/* * Look for mapped directory blocks at or above the current offset. @@ -280,7 +289,7 @@ xfs_dir2_leaf_readbuf( new_off =xfs_dir2_da_to_byte (geo, map.br_startoff);if (new_off > *cur_off) *cur_off = new_off; - error =xfs_dir3_data_read (args->trans, dp, map.br_startoff,0 , &bp); + error =xfs_dir3_data_read (args->trans, dp, map.br_startoff, flags, &bp);if (error) goto out;@@ -360,6 +369,7 @@ xfs_dir2_leaf_getdents(int byteoff;/* offset in current block */ unsigned int offset =0 ;int error =0 ;/* error return value */ +int written =0 ;/* * If the offset is at or past the largest allowed value, @@ -391,10 +401,17 @@ xfs_dir2_leaf_getdents( bp =NULL ; } -if (*lock_mode ==0 ) - *lock_mode =xfs_ilock_data_map_shared (dp); - error =xfs_dir2_leaf_readbuf (args, bufsize, &curoff, - &rablk, &bp); +if (*lock_mode ==0 ) {
fs/xfs/xfs_dir2_readdir.c xfs_dir2_leaf_getdents( · line 414
Quoted 10 lines
fs/xfs/xfs_dir2_readdir.c +10
-0+ *lock_mode = +xfs_ilock_data_map_shared_generic (dp, + ctx->flags &DIR_CONTEXT_F_NOWAIT ); +if (!*lock_mode) { + error = -EAGAIN ; +break ; + } + } + error =xfs_dir2_leaf_readbuf (args, ctx, bufsize, + &curoff, &rablk, &bp);
int
xfs_ilock_readdir(
struct xfs_inode *ip,
int flags)
{
if (flags & XFS_DABUF_NOWAIT) {
if (!xfs_ilock_nowait(dp, XFS_ILOCK_SHARED))
return -EAGAIN;
return XFS_ILOCK_SHARED;
}
return xfs_ilock_data_map_shared(dp);
}And then this code simply becomes:
if (*lock_mode == 0) *lock_mode = xfs_ilock_readdir(ip, flags);
Quoted 29 lines
fs/xfs/xfs_dir2_readdir.c +4
-0if (error || !bp)break ;@@ -479,6 +496,7 @@ xfs_dir2_leaf_getdents(*/ offset += length; curoff += length; + written += length;/* bufsize may have just been a guess; don't go negative */ bufsize = bufsize > length ? bufsize - length :0 ; }@@ -492,6 +510,8 @@ xfs_dir2_leaf_getdents( ctx->pos =xfs_dir2_byte_to_dataptr (curoff) &0x7fffffff ;if (bp)xfs_trans_brelse (args->trans, bp); +if (error == -EAGAIN && written >0 ) + error =0 ;return error; }@@ -514,6 +534,7 @@ xfs_readdir(unsigned int lock_mode;bool isblock;int error; +bool nowait;trace_xfs_readdir (dp);
fs/xfs/xfs_dir2_readdir.c xfs_readdir( · line 559
Quoted 9 lines
fs/xfs/xfs_dir2_readdir.c +5
-1@@ -531,7 +552,11 @@ xfs_readdir(if (dp->i_df.if_format ==XFS_DINODE_FMT_LOCAL )return xfs_dir2_sf_getdents (&args, ctx); - lock_mode =xfs_ilock_data_map_shared (dp); + nowait = ctx->flags &DIR_CONTEXT_F_NOWAIT ; + lock_mode =xfs_ilock_data_map_shared_generic (dp, nowait); +if (!lock_mode) +return -EAGAIN ; +
Given what I said above:
if (ctx->flags & DIR_CONTEXT_F_NOWAIT) {
/*
* If we need to read extents, then we must do IO
* and we must use exclusive locking. We don't want
* to do either of those things, so just bail if we
* have to read extents. Doing this check explicitly
* here means we don't have to do it anywhere else
* in the XFS_DABUF_NOWAIT path.
*/
if (xfs_need_iread_extents(&ip->i_df))
return -EAGAIN;
flags |= XFS_DABUF_NOWAIT;
}
lock_mode = xfs_ilock_readdir(dp, flags);And with this change, we probably should be marking the entire operation as having nowait semantics. i.e. using args->op_flags here and only use XFS_DABUF_NOWAIT for the actual IO. ie.
args->op_flags |= XFS_DA_OP_NOWAIT;
This makes it clear that the entire directory op should run under NOWAIT constraints, and it avoids needing to pass an extra flag through the stack. That then makes the readdir locking function look like this:
/*
* When we are locking an inode for readdir, we need to ensure that
* the extents have been read in first. This requires the inode to
* be locked exclusively across the extent read, but otherwise we
* want to use shared locking.
*
* For XFS_DA_OP_NOWAIT operations, we do an up-front check to see
* if the extents have been read in, so all we need to do in this
* case is a shared try-lock as we never need exclusive locking in
* this path.
*/
static int
xfs_ilock_readdir(
struct xfs_da_args *args)
{
if (args->op_flags & XFS_DA_OP_NOWAIT) {
if (!xfs_ilock_nowait(args->dp, XFS_ILOCK_SHARED))
return -EAGAIN;
return XFS_ILOCK_SHARED;
}
return xfs_ilock_data_map_shared(args->dp);
}Quoted 24 lines
fs/xfs/xfs_inode.c +16
-0@@ -120,6 +120,33 @@ xfs_ilock_data_map_shared(return lock_mode; } +/* +* Similar to xfs_ilock_data_map_shared(), except that it will only try to lock +* the inode in shared mode if the extents are already in memory. If it fails to +* get the lock or has to do IO to read the extent list, fail the operation by +* returning 0 as the lock mode. +*/ +uint +xfs_ilock_data_map_shared_nowait ( +struct xfs_inode *ip) +{ +if (xfs_need_iread_extents (&ip->i_df)) +return 0 ; +if (!xfs_ilock_nowait (ip,XFS_ILOCK_SHARED )) +return 0 ; +return XFS_ILOCK_SHARED ; +}
fs/xfs/xfs_inode.c xfs_ilock_data_map_shared( · line 148
Quoted 10 lines
fs/xfs/xfs_inode.c +10
-0+ +int +xfs_ilock_data_map_shared_generic ( +struct xfs_inode *dp, +bool nowait) +{ +if (nowait) +return xfs_ilock_data_map_shared_nowait (dp); +return xfs_ilock_data_map_shared (dp); +}
And all this "generic" locking stuff goes away.
FWIW, IMO, "generic" is a poor name for an XFS function as there's nothing "generic" in XFS. We tend name the functions after what they do, not some abstract concept. Leave "generic" as a keyword for widely used core infrastructure functions, not niche, one-off use cases like this.
Cheers,
Dave.
Signature · 2 lines
Dave Chinner [email protected]
PATCH v6 3/11 vfs: add nowait flag for struct dir_context
In reply to Hao XuFrom: Hao Xu <[email protected]>
The flags will allow passing DIR_CONTEXT_F_NOWAIT to iterate() implementations that support it (as signaled through FMODE_NWAIT in file->f_mode)
Notes:
- considered using IOCB_NOWAIT but if we add more flags later it would be confusing to keep track of which values are valid, use dedicated flags
- might want to check ctx.flags & DIR_CONTEXT_F_NOWAIT is only set when file->f_mode & FMODE_NOWAIT in iterate_dir() as e.g. WARN_ONCE?
--- fs/internal.h | 2 +- fs/readdir.c | 6 ++++-- include/linux/fs.h | 8 ++++++++ 3 files changed, 13 insertions(+), 3 deletions(-)
fs/internal.h +1 -1
@@ -311,4 +311,4 @@ void mnt_idmap_put(struct mnt_idmap *idmap);struct linux_dirent64 ;int vfs_getdents (struct file *file,struct linux_dirent64 __user *dirent, -unsigned int count); +unsigned int count,unsigned long flags);
fs/readdir.c +4 -2
@@ -358,12 +358,14 @@ static bool filldir64(struct dir_context *ctx, const char *name, int namlen,* @file : pointer to file struct of directory * @dirent : pointer to user directory structure * @count : size of buffer +* @flags : additional dir_context flags */ int vfs_getdents (struct file *file,struct linux_dirent64 __user *dirent, -unsigned int count) +unsigned int count,unsigned long flags) {struct getdents_callback64 buf = { .ctx.actor = filldir64, + .ctx.flags = flags, .count = count, .current_dir = dirent };
@@ -395,7 +397,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,if (!f.file)return -EBADF ; - error =vfs_getdents (f.file, dirent, count); + error =vfs_getdents (f.file, dirent, count,0 );fdput_pos (f);return error;
include/linux/fs.h +8 -0
@@ -1719,8 +1719,16 @@ typedef bool (*filldir_t)(struct dir_context *, const char *, int, loff_t, u64,struct dir_context {filldir_t actor;loff_t pos; +unsigned long flags; }; +/* +* flags for dir_context flags +* DIR_CONTEXT_F_NOWAIT: Request non-blocking iterate +* (requires file->f_mode & FMODE_NOWAIT) +*/ +#define DIR_CONTEXT_F_NOWAIT (1 << 0) +/* * These flags let !MMU mmap() govern direct device mapping vs immediate * copying more easily for MAP_PRIVATE, especially for ROM filesystems.
Signature · 1 line
2.25.1
PATCH v6 4/11 vfs: add a vfs helper for io_uring file pos lock
In reply to Hao XuFrom: Hao Xu <[email protected]>
Add a vfs helper file_pos_lock_nowait() for io_uring usage. The function have conditional nowait logic, i.e. if nowait is needed, return -EAGAIN when trylock fails.
--- fs/file.c | 13 +++++++++++++ include/linux/file.h | 2 ++ 2 files changed, 15 insertions(+)
fs/file.c +13 -0
@@ -1053,6 +1053,19 @@ void __f_unlock_pos(struct file *f)mutex_unlock (&f->f_pos_lock); } +int file_pos_lock_nowait (struct file *file,bool nowait) +{ +if (!(file->f_mode &FMODE_ATOMIC_POS )) +return 0 ; + +if (!nowait) +mutex_lock (&file->f_pos_lock); +else if (!mutex_trylock (&file->f_pos_lock)) +return -EAGAIN ; + +return 1 ; +} +/* * We only lock f_pos if we have threads or if the file might be * shared with another process. In both cases we'll have an elevated
include/linux/file.h +2 -0
@@ -81,6 +81,8 @@ static inline void fdput_pos(struct fd f)fdput (f); } +extern int file_pos_lock_nowait (struct file *file,bool nowait); + DEFINE_CLASS(fd, struct fd, fdput(_T), fdget(fd), int fd)extern int f_dupfd (unsigned int from,struct file *file,unsigned flags);
Signature · 1 line
2.25.1
Matthew Wilcox
maintainerRe: [PATCH 04/11] vfs: add a vfs helper for io_uring file pos lock
include/linux/file.h static inline void fdput_pos(struct fd f) · line 84
Quoted 6 lines · Hao Xu
+++
b/include/linux/file.hinclude/linux/file.h +1
-0@@ -81,6 +81,8 @@ static inline void fdput_pos(struct fd f)fdput (f); } +extern int file_pos_lock_nowait (struct file *file,bool nowait);
No extern on function declarations.
PATCH v6 5/11 vfs: add file_pos_unlock() for io_uring usage
In reply to Hao XuFrom: Hao Xu <[email protected]>
Add a helper to unlock f_pos_lock without any condition. Introduce this since io_uring handles f_pos_lock not with a fd struct, thus FDPUT_POS_UNLOCK isn't used.
--- include/linux/file.h | 5 +++++ 1 file changed, 5 insertions(+)
include/linux/file.h +5 -0
@@ -81,6 +81,11 @@ static inline void fdput_pos(struct fd f)fdput (f); } +static inline void file_pos_unlock (struct file *file) +{ +__f_unlock_pos (file); +} +extern int file_pos_lock_nowait (struct file *file,bool nowait); DEFINE_CLASS(fd, struct fd, fdput(_T), fdget(fd), int fd)
Signature · 1 line
2.25.1
PATCH v6 6/11 vfs: add a nowait parameter for touch_atime()
In reply to Hao XuFrom: Hao Xu <[email protected]>
Add a nowait boolean parameter for touch_atime() to support nowait semantics. It is true only when io_uring is the initial caller.
--- fs/cachefiles/namei.c | 2 +- fs/ecryptfs/file.c | 4 ++-- fs/inode.c | 7 ++++--- fs/namei.c | 4 ++-- fs/nfsd/vfs.c | 2 +- fs/overlayfs/file.c | 2 +- fs/overlayfs/inode.c | 2 +- fs/stat.c | 2 +- include/linux/fs.h | 4 ++-- kernel/bpf/inode.c | 4 ++-- net/unix/af_unix.c | 4 ++-- 11 files changed, 19 insertions(+), 18 deletions(-)
fs/cachefiles/namei.c +1 -1
@@ -591,7 +591,7 @@ static bool cachefiles_open_file(struct cachefiles_object *object,* used to keep track of culling, and atimes are only updated by read, * write and readdir but not lookup or open). */ -touch_atime (&file->f_path); +touch_atime (&file->f_path, false);dput (dentry);return true;
fs/ecryptfs/file.c +2 -2
@@ -39,7 +39,7 @@ static ssize_t ecryptfs_read_update_atime(struct kiocb *iocb, rc =generic_file_read_iter (iocb, to);if (rc >=0 ) { path =ecryptfs_dentry_to_lower_path (file->f_path.dentry); -touch_atime (path); +touch_atime (path, false); }return rc; }
@@ -64,7 +64,7 @@ static ssize_t ecryptfs_splice_read_update_atime(struct file *in, loff_t *ppos, rc =filemap_splice_read (in, ppos, pipe, len, flags);if (rc >=0 ) { path =ecryptfs_dentry_to_lower_path (in->f_path.dentry); -touch_atime (path); +touch_atime (path, false); }return rc; }
fs/inode.c +4 -3
@@ -1961,17 +1961,17 @@ bool atime_needs_update(const struct path *path, struct inode *inode)return true; } -void touch_atime (const struct path *path) +int touch_atime (const struct path *path,bool nowait) {struct vfsmount *mnt = path->mnt;struct inode *inode =d_inode (path->dentry);struct timespec64 now;if (!atime_needs_update (path, inode)) -return ; +return 0 ;if (!sb_start_write_trylock (inode->i_sb)) -return ; +return 0 ;if (__mnt_want_write (mnt) !=0 ) goto skip_update;
@@ -1989,6 +1989,7 @@ void touch_atime(const struct path *path)__mnt_drop_write (mnt); skip_update:sb_end_write (inode->i_sb); +return 0 ; }EXPORT_SYMBOL (touch_atime);
fs/namei.c +2 -2
@@ -1776,12 +1776,12 @@ static const char *pick_link(struct nameidata *nd, struct path *link,return ERR_PTR (-ELOOP );if (!(nd->flags &LOOKUP_RCU )) { -touch_atime (&last->link); +touch_atime (&last->link, false);cond_resched (); }else if (atime_needs_update (&last->link, inode)) {if (!try_to_unlazy (nd))return ERR_PTR (-ECHILD ); -touch_atime (&last->link); +touch_atime (&last->link, false); } error = security_inode_follow_link(link->dentry, inode,
fs/nfsd/vfs.c +1 -1
@@ -1569,7 +1569,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)if (unlikely (!d_is_symlink (path.dentry)))return nfserr_inval; -touch_atime (&path); +touch_atime (&path, false); link =vfs_get_link (path.dentry, &done);if (IS_ERR (link))
fs/overlayfs/file.c +1 -1
@@ -255,7 +255,7 @@ static void ovl_file_accessed(struct file *file) inode->i_ctime = upperinode->i_ctime; } -touch_atime (&file->f_path); +touch_atime (&file->f_path, false); }static rwf_t ovl_iocb_to_rwf (int ifl)
fs/overlayfs/inode.c +1 -1
@@ -703,7 +703,7 @@ int ovl_update_time(struct inode *inode, struct timespec64 *ts, int flags) };if (upperpath.dentry) { -touch_atime (&upperpath); +touch_atime (&upperpath, false); inode->i_atime =d_inode (upperpath.dentry)->i_atime; } }
fs/stat.c +1 -1
@@ -485,7 +485,7 @@ static int do_readlinkat(int dfd, const char __user *pathname,if (d_is_symlink (path.dentry) || inode->i_op->readlink) { error =security_inode_readlink (path.dentry);if (!error) { -touch_atime (&path); +touch_atime (&path, false); error =vfs_readlink (path.dentry, buf, bufsiz); } }
include/linux/fs.h +2 -2
@@ -2201,13 +2201,13 @@ enum file_time_flags { };extern bool atime_needs_update (const struct path *,struct inode *); -extern void touch_atime (const struct path *); +extern int touch_atime (const struct path *path,bool nowait);int inode_update_time (struct inode *inode,struct timespec64 *time,int flags);static inline void file_accessed (struct file *file) {if (!(file->f_flags &O_NOATIME )) -touch_atime (&file->f_path); +touch_atime (&file->f_path, false); }extern int file_modified (struct file *file);
kernel/bpf/inode.c +2 -2
@@ -517,7 +517,7 @@ static void *bpf_obj_do_get(int path_fd, const char __user *pathname, raw =bpf_any_get (inode->i_private, *type);if (!IS_ERR (raw)) -touch_atime (&path); +touch_atime (&path, false);path_put (&path);return raw;
@@ -591,7 +591,7 @@ struct bpf_prog *bpf_prog_get_type_path(const char *name, enum bpf_prog_type typreturn ERR_PTR (ret); prog =__get_prog_inode (d_backing_inode (path.dentry), type);if (!IS_ERR (prog)) -touch_atime (&path); +touch_atime (&path, false);path_put (&path);return prog; }
net/unix/af_unix.c +2 -2
@@ -1084,7 +1084,7 @@ static struct sock *unix_find_bsd(struct sockaddr_un *sunaddr, int addr_len, err = -EPROTOTYPE ;if (sk->sk_type == type) -touch_atime (&path); +touch_atime (&path, false);else goto sock_put;
@@ -1114,7 +1114,7 @@ static struct sock *unix_find_abstract(struct net *net, dentry =unix_sk (sk)->path.dentry;if (dentry) -touch_atime (&unix_sk (sk)->path); +touch_atime (&unix_sk (sk)->path, false);return sk; }
Signature · 1 line
2.25.1
PATCH v6 7/11 vfs: add nowait parameter for file_accessed()
In reply to Hao XuFrom: Hao Xu <[email protected]>
Add a boolean parameter for file_accessed() to support nowait semantics. Currently it is true only with io_uring as its initial caller.
--- arch/s390/hypfs/inode.c | 2 +- block/fops.c | 2 +- fs/btrfs/file.c | 2 +- fs/btrfs/inode.c | 2 +- fs/coda/dir.c | 4 ++-- fs/ext2/file.c | 4 ++-- fs/ext4/file.c | 6 +++--- fs/f2fs/file.c | 4 ++-- fs/fuse/dax.c | 2 +- fs/fuse/file.c | 4 ++-- fs/gfs2/file.c | 2 +- fs/hugetlbfs/inode.c | 2 +- fs/nilfs2/file.c | 2 +- fs/orangefs/file.c | 2 +- fs/orangefs/inode.c | 2 +- fs/pipe.c | 2 +- fs/ramfs/file-nommu.c | 2 +- fs/readdir.c | 2 +- fs/smb/client/cifsfs.c | 2 +- fs/splice.c | 2 +- fs/ubifs/file.c | 2 +- fs/udf/file.c | 2 +- fs/xfs/xfs_file.c | 6 +++--- fs/zonefs/file.c | 4 ++-- include/linux/fs.h | 5 +++-- mm/filemap.c | 8 ++++---- mm/shmem.c | 6 +++--- 27 files changed, 43 insertions(+), 42 deletions(-)
arch/s390/hypfs/inode.c +1 -1
@@ -157,7 +157,7 @@ static ssize_t hypfs_read_iter(struct kiocb *iocb, struct iov_iter *to)if (!count)return -EFAULT ; iocb->ki_pos = pos + count; -file_accessed (file); +file_accessed (file, false);return count; }
block/fops.c +1 -1
@@ -601,7 +601,7 @@ static ssize_t blkdev_read_iter(struct kiocb *iocb, struct iov_iter *to) ret =kiocb_write_and_wait (iocb, count);if (ret <0 ) goto reexpand; -file_accessed (iocb->ki_filp); +file_accessed (iocb->ki_filp, false); ret =blkdev_direct_IO (iocb, to);if (ret >=0 ) {
fs/btrfs/file.c +1 -1
@@ -2013,7 +2013,7 @@ static int btrfs_file_mmap(struct file *filp, struct vm_area_struct *vma)if (!mapping->a_ops->read_folio)return -ENOEXEC ; -file_accessed (filp); +file_accessed (filp, false); vma->vm_ops = &btrfs_file_vm_ops;return 0 ;
fs/btrfs/inode.c +1 -1
@@ -10153,7 +10153,7 @@ ssize_t btrfs_encoded_read(struct kiocb *iocb, struct iov_iter *iter,struct extent_map *em;bool unlocked = false; -file_accessed (iocb->ki_filp); +file_accessed (iocb->ki_filp, false);btrfs_inode_lock (inode,BTRFS_ILOCK_SHARED );
fs/coda/dir.c +2 -2
@@ -436,12 +436,12 @@ static int coda_readdir(struct file *coda_file, struct dir_context *ctx)if (host_file->f_op->iterate_shared) {inode_lock_shared (host_inode); ret = host_file->f_op->iterate_shared (host_file, ctx); -file_accessed (host_file); +file_accessed (host_file, false);inode_unlock_shared (host_inode); }else {inode_lock (host_inode); ret = host_file->f_op->iterate (host_file, ctx); -file_accessed (host_file); +file_accessed (host_file, false);inode_unlock (host_inode); } }
fs/ext2/file.c +2 -2
@@ -44,7 +44,7 @@ static ssize_t ext2_dax_read_iter(struct kiocb *iocb, struct iov_iter *to) ret =dax_iomap_rw (iocb, to, &ext2_iomap_ops);inode_unlock_shared (inode); -file_accessed (iocb->ki_filp); +file_accessed (iocb->ki_filp, false);return ret; }
@@ -127,7 +127,7 @@ static int ext2_file_mmap(struct file *file, struct vm_area_struct *vma)if (!IS_DAX (file_inode (file)))return generic_file_mmap (file, vma); -file_accessed (file); +file_accessed (file, false); vma->vm_ops = &ext2_dax_vm_ops;return 0 ; }
fs/ext4/file.c +3 -3
@@ -94,7 +94,7 @@ static ssize_t ext4_dio_read_iter(struct kiocb *iocb, struct iov_iter *to) ret =iomap_dio_rw (iocb, to, &ext4_iomap_ops,NULL ,0 ,NULL ,0 );inode_unlock_shared (inode); -file_accessed (iocb->ki_filp); +file_accessed (iocb->ki_filp, false);return ret; }
@@ -122,7 +122,7 @@ static ssize_t ext4_dax_read_iter(struct kiocb *iocb, struct iov_iter *to) ret =dax_iomap_rw (iocb, to, &ext4_iomap_ops);inode_unlock_shared (inode); -file_accessed (iocb->ki_filp); +file_accessed (iocb->ki_filp, false); return ret; }#endif
@@ -820,7 +820,7 @@ static int ext4_file_mmap(struct file *file, struct vm_area_struct *vma)if (!daxdev_mapping_supported (vma, dax_dev))return -EOPNOTSUPP ; -file_accessed (file); +file_accessed (file, false);if (IS_DAX (file_inode (file))) { vma->vm_ops = &ext4_dax_vm_ops;vm_flags_set (vma,VM_HUGEPAGE );
fs/f2fs/file.c +2 -2
@@ -524,7 +524,7 @@ static int f2fs_file_mmap(struct file *file, struct vm_area_struct *vma)if (!f2fs_is_compress_backend_ready (inode))return -EOPNOTSUPP ; -file_accessed (file); +file_accessed (file, false); vma->vm_ops = &f2fs_file_vm_ops;set_inode_flag (inode,FI_MMAP_FILE );return 0 ;
@@ -4380,7 +4380,7 @@ static ssize_t f2fs_dio_read_iter(struct kiocb *iocb, struct iov_iter *to)f2fs_up_read (&fi->i_gc_rwsem[READ ]); -file_accessed (file); +file_accessed (file, false); out:trace_f2fs_direct_IO_exit (inode, pos, count,READ , ret);return ret;
fs/fuse/dax.c +1 -1
@@ -858,7 +858,7 @@ static const struct vm_operations_struct fuse_dax_vm_ops = {int fuse_dax_mmap (struct file *file,struct vm_area_struct *vma) { -file_accessed (file); +file_accessed (file, false); vma->vm_ops = &fuse_dax_vm_ops;vm_flags_set (vma,VM_MIXEDMAP |VM_HUGEPAGE );return 0 ;
fs/fuse/file.c +2 -2
@@ -2496,7 +2496,7 @@ static int fuse_file_mmap(struct file *file, struct vm_area_struct *vma)if ((vma->vm_flags &VM_SHARED ) && (vma->vm_flags &VM_MAYWRITE ))fuse_link_write_file (file); -file_accessed (file); +file_accessed (file, false); vma->vm_ops = &fuse_file_vm_ops;return 0 ; }
@@ -3193,7 +3193,7 @@ static ssize_t __fuse_copy_file_range(struct file *file_in, loff_t pos_in,clear_bit (FUSE_I_SIZE_UNSTABLE , &fi_out->state);inode_unlock (inode_out); -file_accessed (file_in); +file_accessed (file_in, false);fuse_flush_time_update (inode_out);
fs/gfs2/file.c +1 -1
@@ -601,7 +601,7 @@ static int gfs2_mmap(struct file *file, struct vm_area_struct *vma)return error;/* grab lock to update inode */ gfs2_glock_dq_uninit (&i_gh); -file_accessed (file); +file_accessed (file, false); } vma->vm_ops = &gfs2_vm_ops;
fs/hugetlbfs/inode.c +1 -1
@@ -161,7 +161,7 @@ static int hugetlbfs_file_mmap(struct file *file, struct vm_area_struct *vma)return -EINVAL ;inode_lock (inode); -file_accessed (file); +file_accessed (file, false); ret = -ENOMEM ; if (!hugetlb_reserve_pages(inode,
fs/nilfs2/file.c +1 -1
@@ -119,7 +119,7 @@ static const struct vm_operations_struct nilfs_file_vm_ops = {static int nilfs_file_mmap (struct file *file,struct vm_area_struct *vma) { -file_accessed (file); +file_accessed (file, false); vma->vm_ops = &nilfs_file_vm_ops;return 0 ; }
fs/orangefs/file.c +1 -1
@@ -412,7 +412,7 @@ static int orangefs_file_mmap(struct file *file, struct vm_area_struct *vma)/* set the sequential readahead hint */ vm_flags_mod (vma,VM_SEQ_READ ,VM_RAND_READ ); -file_accessed (file); +file_accessed (file, false); vma->vm_ops = &orangefs_file_vm_ops;return 0 ; }
fs/orangefs/inode.c +1 -1
@@ -597,7 +597,7 @@ static ssize_t orangefs_direct_IO(struct kiocb *iocb, ret = total_count;if (ret >0 ) {if (type ==ORANGEFS_IO_READ ) { -file_accessed (file); +file_accessed (file, false); }else {file_update_time (file);if (*offset >i_size_read (inode))
fs/pipe.c +1 -1
@@ -393,7 +393,7 @@ pipe_read(struct kiocb *iocb, struct iov_iter *to)wake_up_interruptible_sync_poll (&pipe->rd_wait,EPOLLIN |EPOLLRDNORM );kill_fasync (&pipe->fasync_writers,SIGIO ,POLL_OUT );if (ret >0 ) -file_accessed (filp); +file_accessed (filp, false);return ret; }
fs/ramfs/file-nommu.c +1 -1
@@ -267,7 +267,7 @@ static int ramfs_nommu_mmap(struct file *file, struct vm_area_struct *vma)if (!is_nommu_shared_mapping (vma->vm_flags))return -ENOSYS ; -file_accessed (file); +file_accessed (file, false); vma->vm_ops = &generic_file_vm_ops;return 0 ; }
fs/readdir.c +1 -1
@@ -68,7 +68,7 @@ int iterate_dir(struct file *file, struct dir_context *ctx) res = file->f_op->iterate (file, ctx); file->f_pos = ctx->pos;fsnotify_access (file); -file_accessed (file); +file_accessed (file, ctx->flags &DIR_CONTEXT_F_NOWAIT ); }if (shared)inode_unlock_shared (inode);
fs/smb/client/cifsfs.c +1 -1
@@ -1307,7 +1307,7 @@ ssize_t cifs_file_copychunk_range(unsigned int xid, rc = target_tcon->ses->server->ops->copychunk_range (xid, smb_file_src, smb_file_target, off, len, destoff); -file_accessed (src_file); +file_accessed (src_file, false);/* force revalidate of size and timestamps of target file now * that target is updated on the server
fs/splice.c +1 -1
@@ -1104,7 +1104,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd, done: pipe->tail = pipe->head =0 ; -file_accessed (in); +file_accessed (in, false);return bytes; read_failure:
fs/ubifs/file.c +1 -1
@@ -1603,7 +1603,7 @@ static int ubifs_file_mmap(struct file *file, struct vm_area_struct *vma) vma->vm_ops = &ubifs_file_vm_ops;if (IS_ENABLED (CONFIG_UBIFS_ATIME_SUPPORT )) -file_accessed (file); +file_accessed (file, false);return 0 ; }
fs/udf/file.c +1 -1
@@ -191,7 +191,7 @@ static int udf_release_file(struct inode *inode, struct file *filp)static int udf_file_mmap (struct file *file,struct vm_area_struct *vma) { -file_accessed (file); +file_accessed (file, false); vma->vm_ops = &udf_file_vm_ops;return 0 ;
fs/xfs/xfs_file.c +3 -3
@@ -227,7 +227,7 @@ xfs_file_dio_read(if (!iov_iter_count (to))return 0 ;/* skip atime */ -file_accessed (iocb->ki_filp); +file_accessed (iocb->ki_filp, false); ret =xfs_ilock_iocb (iocb,XFS_IOLOCK_SHARED );if (ret)
@@ -257,7 +257,7 @@ xfs_file_dax_read( ret =dax_iomap_rw (iocb, to, &xfs_read_iomap_ops);xfs_iunlock (ip,XFS_IOLOCK_SHARED ); -file_accessed (iocb->ki_filp); +file_accessed (iocb->ki_filp, false);return ret; }
@@ -1434,7 +1434,7 @@ xfs_file_mmap(if (!daxdev_mapping_supported (vma, target->bt_daxdev))return -EOPNOTSUPP ; -file_accessed (file); +file_accessed (file, false); vma->vm_ops = &xfs_file_vm_ops;if (IS_DAX (inode))vm_flags_set (vma,VM_HUGEPAGE );
fs/zonefs/file.c +2 -2
@@ -323,7 +323,7 @@ static int zonefs_file_mmap(struct file *file, struct vm_area_struct *vma) (vma->vm_flags & VM_SHARED) && (vma->vm_flags & VM_MAYWRITE))return -EINVAL ; -file_accessed (file); +file_accessed (file, false); vma->vm_ops = &zonefs_file_vm_ops;return 0 ;
@@ -736,7 +736,7 @@ static ssize_t zonefs_file_read_iter(struct kiocb *iocb, struct iov_iter *to) ret = -EINVAL ; goto inode_unlock; } -file_accessed (iocb->ki_filp); +file_accessed (iocb->ki_filp, false); ret =iomap_dio_rw (iocb, to, &zonefs_read_iomap_ops, &zonefs_read_dio_ops,0 ,NULL ,0 ); }else {
include/linux/fs.h +3 -2
@@ -2204,10 +2204,11 @@ extern bool atime_needs_update(const struct path *, struct inode *);extern int touch_atime (const struct path *path,bool nowait);int inode_update_time (struct inode *inode,struct timespec64 *time,int flags); -static inline void file_accessed (struct file *file) +static inline int file_accessed (struct file *file,bool nowait) {if (!(file->f_flags &O_NOATIME )) -touch_atime (&file->f_path, false); +return touch_atime (&file->f_path, nowait); +return 0 ; }extern int file_modified (struct file *file);
mm/filemap.c +4 -4
@@ -2723,7 +2723,7 @@ ssize_t filemap_read(struct kiocb *iocb, struct iov_iter *iter,folio_batch_init (&fbatch); }while (iov_iter_count (iter) && iocb->ki_pos < isize && !error); -file_accessed (filp); +file_accessed (filp, false);return already_read ? already_read : error; }
@@ -2809,7 +2809,7 @@ generic_file_read_iter(struct kiocb *iocb, struct iov_iter *iter) retval =kiocb_write_and_wait (iocb, count);if (retval <0 )return retval; -file_accessed (file); +file_accessed (file, false); retval = mapping->a_ops->direct_IO (iocb, iter);if (retval >=0 ) {
@@ -2978,7 +2978,7 @@ ssize_t filemap_splice_read(struct file *in, loff_t *ppos, out:folio_batch_release (&fbatch); -file_accessed (in); +file_accessed (in, false);return total_spliced ? total_spliced : error; }
@@ -3613,7 +3613,7 @@ int generic_file_mmap(struct file *file, struct vm_area_struct *vma)if (!mapping->a_ops->read_folio)return -ENOEXEC ; -file_accessed (file); +file_accessed (file, false); vma->vm_ops = &generic_file_vm_ops;return 0 ; }
mm/shmem.c +3 -3
@@ -2317,7 +2317,7 @@ static int shmem_mmap(struct file *file, struct vm_area_struct *vma)/* arm64 - allow memory tagging on RAM-based files */ vm_flags_set (vma,VM_MTE_ALLOWED ); -file_accessed (file); +file_accessed (file, false);/* This is anonymous shared memory if it is unlinked at the time of mmap */ if (inode->i_nlink) vma->vm_ops = &shmem_vm_ops;
@@ -2727,7 +2727,7 @@ static ssize_t shmem_file_read_iter(struct kiocb *iocb, struct iov_iter *to) } *ppos = ((loff_t ) index <<PAGE_SHIFT ) + offset; -file_accessed (file); +file_accessed (file, false);return retval ? retval : error; }
@@ -2859,7 +2859,7 @@ static ssize_t shmem_file_splice_read(struct file *in, loff_t *ppos,if (folio)folio_put (folio); -file_accessed (in); +file_accessed (in, false);return total_spliced ? total_spliced : error; }
Signature · 1 line
2.25.1
Matthew Wilcox
maintainerRe: [PATCH 07/11] vfs: add nowait parameter for file_accessed()
Quoted 4 lines · Hao Xu
From: Hao Xu <[email protected]>
Add a boolean parameter for
file_accessed()to support nowait semantics. Currently it is true only withio_uringas its initial caller.
So why do we need to do this as part of this series? Apparently it hasn't caused any problems for filemap_read().
Quoted 28 lines
+++
b/mm/filemap.cmm/filemap.c +3
-3@@ -2723,7 +2723,7 @@ ssize_t filemap_read(struct kiocb *iocb, struct iov_iter *iter,folio_batch_init (&fbatch); }while (iov_iter_count (iter) && iocb->ki_pos < isize && !error); -file_accessed (filp); +file_accessed (filp, false);return already_read ? already_read : error; }@@ -2809,7 +2809,7 @@ generic_file_read_iter(struct kiocb *iocb, struct iov_iter *iter) retval =kiocb_write_and_wait (iocb, count);if (retval <0 )return retval; -file_accessed (file); +file_accessed (file, false); retval = mapping->a_ops->direct_IO (iocb, iter);if (retval >=0 ) {@@ -2978,7 +2978,7 @@ ssize_t filemap_splice_read(struct file *in, loff_t *ppos, out:folio_batch_release (&fbatch); -file_accessed (in); +file_accessed (in, false);return total_spliced ? total_spliced : error; }
Re: [PATCH 07/11] vfs: add nowait parameter for file_accessed()
Quoted 9 lines · Matthew Wilcox
Quoted 4 lines · Hao Xu
From: Hao Xu <[email protected]>
Add a boolean parameter for
file_accessed()to support nowait semantics. Currently it is true only withio_uringas its initial caller.So why do we need to do this as part of this series? Apparently it hasn't caused any problems for
filemap_read().
We need this parameter to indicate if nowait semantics should be enforced in touch_atime(), There are locks and maybe IOs in it.
Matthew Wilcox
maintainerRe: [PATCH 07/11] vfs: add nowait parameter for file_accessed()
Quoted 7 lines · Hao Xu
Quoted 6 lines · Matthew Wilcox
Quoted 4 lines · Hao Xu
From: Hao Xu <[email protected]>
Add a boolean parameter for
file_accessed()to support nowait semantics. Currently it is true only withio_uringas its initial caller.
Quoted 6 lines
Quoted 3 lines
So why do we need to do this as part of this series? Apparently it hasn't caused any problems for
filemap_read().We need this parameter to indicate if nowait semantics should be enforced in
touch_atime(), There are locks and maybe IOs in it.
That's not my point. We currently call file_accessed() and touch_atime() for nowait reads and nowait writes. You haven't done anything to fix those.
I suspect you can trim this patchset down significantly by avoiding fixing the file_accessed() problem. And then come back with a later patchset that fixes it for all nowait i/o. Or do a separate prep series first that fixes it for the existing nowait users, and then a second series to do all the directory stuff.
I'd do the first thing. Just ignore the problem. Directory atime updates cause I/O so rarely that you can afford to ignore it. Almost everyone uses relatime or nodiratime.
Re: [PATCH 07/11] vfs: add nowait parameter for file_accessed()
Quoted 15 lines · Matthew Wilcox
Quoted 7 lines · Hao Xu
Quoted 6 lines · Matthew Wilcox
Quoted 4 lines · Hao Xu
From: Hao Xu <[email protected]>
Add a boolean parameter for
file_accessed()to support nowait semantics. Currently it is true only withio_uringas its initial caller.Quoted 6 lines
Quoted 3 lines
So why do we need to do this as part of this series? Apparently it hasn't caused any problems for
filemap_read().We need this parameter to indicate if nowait semantics should be enforced in
touch_atime(), There are locks and maybe IOs in it.
Quoted 7 lines
That's not my point. We currently call
file_accessed()andtouch_atime()for nowait reads and nowait writes. You haven't done anything to fix those.I suspect you can trim this patchset down significantly by avoiding fixing the
file_accessed()problem. And then come back with a later patchset that fixes it for all nowait i/o. Or do a separate prep series
I'm ok to do that.
Quoted 6 lines
first that fixes it for the existing nowait users, and then a second series to do all the directory stuff.
I'd do the first thing. Just ignore the problem. Directory atime updates cause I/O so rarely that you can afford to ignore it. Almost everyone uses relatime or nodiratime.
Hi Matthew,
The previous discussion shows this does cause issues in real
producations: https://lore.kernel.org/io-uring/[email protected]/#:~:text=fwiw%2C%20we%27ve%20just%20recently%20had%20similar%20problems%20with%20io_uring%20read/write
Re: [PATCH 07/11] vfs: add nowait parameter for file_accessed()
Quoted 29 lines · Hao Xu
Quoted 15 lines · Matthew Wilcox
Quoted 7 lines · Hao Xu
Quoted 6 lines · Matthew Wilcox
Quoted 4 lines · Hao Xu
From: Hao Xu <[email protected]>
Add a boolean parameter for
file_accessed()to support nowait semantics. Currently it is true only withio_uringas its initial caller.Quoted 6 lines
Quoted 3 lines
So why do we need to do this as part of this series? Apparently it hasn't caused any problems for
filemap_read().We need this parameter to indicate if nowait semantics should be enforced in
touch_atime(), There are locks and maybe IOs in it.Quoted 7 lines
That's not my point. We currently call
file_accessed()andtouch_atime()for nowait reads and nowait writes. You haven't done anything to fix those.I suspect you can trim this patchset down significantly by avoiding fixing the
file_accessed()problem. And then come back with a later patchset that fixes it for all nowait i/o. Or do a separate prep seriesI'm ok to do that.
Quoted 3 lines
first that fixes it for the existing nowait users, and then a second series to do all the directory stuff.
Quoted 8 lines
Quoted 3 lines
I'd do the first thing. Just ignore the problem. Directory atime updates cause I/O so rarely that you can afford to ignore it. Almost everyone uses relatime or nodiratime.
Hi Matthew,
The previous discussion shows this does cause issues in real
producations: https://lore.kernel.org/io-uring/[email protected]/#:~:text=fwiw%2C%20we%27ve%20just%20recently%20had%20similar%20problems%20with%20io_uring%20read/write
Then separate it out into it's own patch set so we can have a discussion on the merits of requiring using noatime, relatime or lazytime for really latency sensitive IO applications. Changing code is not always the right solution...
-Dave.
Signature · 2 lines
Dave Chinner [email protected]
Re: [PATCH 07/11] vfs: add nowait parameter for file_accessed()
Quoted 39 lines · Dave Chinner
Quoted 29 lines · Hao Xu
Quoted 15 lines · Matthew Wilcox
Quoted 7 lines · Hao Xu
Quoted 6 lines · Matthew Wilcox
Quoted 4 lines · Hao Xu
From: Hao Xu <[email protected]>
Add a boolean parameter for
file_accessed()to support nowait semantics. Currently it is true only withio_uringas its initial caller.Quoted 6 lines
Quoted 3 lines
So why do we need to do this as part of this series? Apparently it hasn't caused any problems for
filemap_read().We need this parameter to indicate if nowait semantics should be enforced in
touch_atime(), There are locks and maybe IOs in it.Quoted 7 lines
That's not my point. We currently call
file_accessed()andtouch_atime()for nowait reads and nowait writes. You haven't done anything to fix those.I suspect you can trim this patchset down significantly by avoiding fixing the
file_accessed()problem. And then come back with a later patchset that fixes it for all nowait i/o. Or do a separate prep seriesI'm ok to do that.
Quoted 3 lines
first that fixes it for the existing nowait users, and then a second series to do all the directory stuff.
Quoted 8 lines
Quoted 3 lines
I'd do the first thing. Just ignore the problem. Directory atime updates cause I/O so rarely that you can afford to ignore it. Almost everyone uses relatime or nodiratime.
Hi Matthew,
The previous discussion shows this does cause issues in real
producations: https://lore.kernel.org/io-uring/[email protected]/#:~:text=fwiw%2C%20we%27ve%20just%20recently%20had%20similar%20problems%20with%20io_uring%20read/write
Quoted 4 lines
Then separate it out into it's own patch set so we can have a discussion on the merits of requiring using noatime, relatime or lazytime for really latency sensitive IO applications. Changing code is not always the right solution...
Separation sounds reasonable, but it can hardly be said that only latency sensitive apps would care about >1s nowait/async submission delays. Presumably, btrfs can improve on that, but it still looks like it's perfectly legit for filesystems do heavy stuff in timestamping like waiting for IO. Right?
Signature · 1 line
Pavel Begunkov
Re: [PATCH 07/11] vfs: add nowait parameter for file_accessed()
Quoted 45 lines · Pavel Begunkov
Quoted 39 lines · Dave Chinner
Quoted 29 lines · Hao Xu
Quoted 15 lines · Matthew Wilcox
Quoted 7 lines · Hao Xu
Quoted 6 lines · Matthew Wilcox
Quoted 4 lines · Hao Xu
From: Hao Xu <[email protected]>
Add a boolean parameter for
file_accessed()to support nowait semantics. Currently it is true only withio_uringas its initial caller.Quoted 6 lines
Quoted 3 lines
So why do we need to do this as part of this series? Apparently it hasn't caused any problems for
filemap_read().We need this parameter to indicate if nowait semantics should be enforced in
touch_atime(), There are locks and maybe IOs in it.Quoted 7 lines
That's not my point. We currently call
file_accessed()andtouch_atime()for nowait reads and nowait writes. You haven't done anything to fix those.I suspect you can trim this patchset down significantly by avoiding fixing the
file_accessed()problem. And then come back with a later patchset that fixes it for all nowait i/o. Or do a separate prep seriesI'm ok to do that.
Quoted 3 lines
first that fixes it for the existing nowait users, and then a second series to do all the directory stuff.
Quoted 8 lines
Quoted 3 lines
I'd do the first thing. Just ignore the problem. Directory atime updates cause I/O so rarely that you can afford to ignore it. Almost everyone uses relatime or nodiratime.
Hi Matthew,
The previous discussion shows this does cause issues in real
producations: https://lore.kernel.org/io-uring/[email protected]/#:~:text=fwiw%2C%20we%27ve%20just%20recently%20had%20similar%20problems%20with%20io_uring%20read/writeQuoted 4 lines
Then separate it out into it's own patch set so we can have a discussion on the merits of requiring using noatime, relatime or lazytime for really latency sensitive IO applications. Changing code is not always the right solution...
Quoted 5 lines
Separation sounds reasonable, but it can hardly be said that only latency sensitive apps would care about >1s nowait/async submission delays. Presumably, btrfs can improve on that, but it still looks like it's perfectly legit for filesystems do heavy stuff in timestamping like waiting for IO. Right?
Yes, it is, no-one is denying that. And some filesystems are worse than others, but none of that means it has to be fixed so getdents can be converted to NOWAIT semantics.
ie. this patchset is about the getdents NOWAIT machinery, and fiddling around with timestamps has much, much wider scope than just NOWAIT getdents machinery. We'll have this discussion about NOWAIT timestamp updates when a RFC is proposed to address the wider problem of how timestamp updates should behave in NOWAIT context.
-Dave.
Signature · 2 lines
Dave Chinner [email protected]
Christian Brauner
maintainerRe: [PATCH 07/11] vfs: add nowait parameter for file_accessed()
In reply to Hao XuQuoted 41 lines · Hao Xu
From: Hao Xu <[email protected]>
Add a boolean parameter for
file_accessed()to support nowait semantics. Currently it is true only withio_uringas its initial caller.Signed-off-by Hao Xu <[email protected]>--- arch/s390/hypfs/inode.c | 2 +- block/fops.c | 2 +- fs/btrfs/file.c | 2 +- fs/btrfs/inode.c | 2 +- fs/coda/dir.c | 4 ++-- fs/ext2/file.c | 4 ++-- fs/ext4/file.c | 6 +++--- fs/f2fs/file.c | 4 ++-- fs/fuse/dax.c | 2 +- fs/fuse/file.c | 4 ++-- fs/gfs2/file.c | 2 +- fs/hugetlbfs/inode.c | 2 +- fs/nilfs2/file.c | 2 +- fs/orangefs/file.c | 2 +- fs/orangefs/inode.c | 2 +- fs/pipe.c | 2 +- fs/ramfs/file-nommu.c | 2 +- fs/readdir.c | 2 +- fs/smb/client/cifsfs.c | 2 +- fs/splice.c | 2 +- fs/ubifs/file.c | 2 +- fs/udf/file.c | 2 +- fs/xfs/xfs_file.c | 6 +++--- fs/zonefs/file.c | 4 ++-- include/linux/fs.h | 5 +++-- mm/filemap.c | 8 ++++---- mm/shmem.c | 6 +++--- 27 files changed, 43 insertions(+), 42 deletions(-)arch/s390/hypfs/inode.c +0
-0
arch/s390/hypfs/inode.c static ssize_t hypfs_read_iter(struct kiocb *iocb, struct iov_iter *to) · line 160
Quoted 5 lines
arch/s390/hypfs/inode.c +1
-1@@ -157,7 +157,7 @@ static ssize_t hypfs_read_iter(struct kiocb *iocb, struct iov_iter *to)if (!count)return -EFAULT ; iocb->ki_pos = pos + count; -file_accessed (file); +file_accessed (file, false);
Why? If all you do is skip atime update anyway then just add something like:
bool file_needs_atime(struct file *file)
{
return !(file->f_flags & O_NOATIME) &&
atime_needs_update(&file->f_path, d_inode(path->dentry));
}and then
if (file_needs_atime(file) && IOURING_WANTS_ASYNC)
return -EAGAIN;
instead of touching all this code.
PATCH v6 8/11 vfs: move file_accessed() to the beginning of iterate_dir()
In reply to Hao XuFrom: Hao Xu <[email protected]>
Move file_accessed() to the beginning of iterate_dir() so that we don't need to rollback all the work done when file_accessed() returns -EAGAIN at the end of getdents.
--- fs/readdir.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
fs/readdir.c +6 -1
@@ -61,6 +61,10 @@ int iterate_dir(struct file *file, struct dir_context *ctx) res = -ENOENT ;if (!IS_DEADDIR (inode)) { + res =file_accessed (file, ctx->flags &DIR_CONTEXT_F_NOWAIT ); +if (res == -EAGAIN ) + goto out_unlock; + ctx->pos = file->f_pos;if (shared) res = file->f_op->iterate_shared (file, ctx);
@@ -68,8 +72,9 @@ int iterate_dir(struct file *file, struct dir_context *ctx) res = file->f_op->iterate (file, ctx); file->f_pos = ctx->pos;fsnotify_access (file); -file_accessed (file, ctx->flags &DIR_CONTEXT_F_NOWAIT ); } + +out_unlock:if (shared)inode_unlock_shared (inode);else
Signature · 1 line
2.25.1
PATCH v6 9/11 vfs: error out -EAGAIN if atime needs to be updated
In reply to Hao XuFrom: Hao Xu <[email protected]>
To enforce nowait semantics, error out -EAGAIN if atime needs to be updated.
--- fs/inode.c | 3 +++ 1 file changed, 3 insertions(+)
fs/inode.c +3 -0
@@ -1970,6 +1970,9 @@ int touch_atime(const struct path *path, bool nowait)if (!atime_needs_update (path, inode))return 0 ; +if (nowait) +return -EAGAIN ; +if (!sb_start_write_trylock (inode->i_sb))return 0 ;
Signature · 1 line
2.25.1
Matthew Wilcox
maintainerRe: [PATCH 09/11] vfs: error out -EAGAIN if atime needs to be updated
Quoted 4 lines · Hao Xu
From: Hao Xu <[email protected]>
To enforce nowait semantics, error out
-EAGAINif atime needs to be updated.
Squash this into patch 6. Otherwise patch 6 makes no sense.
PATCH v6 10/11 vfs: trylock inode->i_rwsem in iterate_dir() to support nowait
In reply to Hao XuFrom: Hao Xu <[email protected]>
Trylock inode->i_rwsem in iterate_dir() to support nowait semantics and error out -EAGAIN when there is contention.
--- fs/readdir.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-)
fs/readdir.c +14 -6
@@ -43,6 +43,8 @@ int iterate_dir(struct file *file, struct dir_context *ctx)struct inode *inode =file_inode (file);bool shared = false;int res = -ENOTDIR ; +bool nowait; +if (file->f_op->iterate_shared) shared = true;else if (!file->f_op->iterate)
@@ -52,16 +54,22 @@ int iterate_dir(struct file *file, struct dir_context *ctx)if (res) goto out; -if (shared) - res =down_read_killable (&inode->i_rwsem); -else - res =down_write_killable (&inode->i_rwsem); -if (res) + nowait = ctx->flags &DIR_CONTEXT_F_NOWAIT ; +if (nowait) { + res = shared ?down_read_trylock (&inode->i_rwsem) : +down_write_trylock (&inode->i_rwsem); +if (!res) + res = -EAGAIN ; + }else { + res = shared ?down_read_killable (&inode->i_rwsem) : +down_write_killable (&inode->i_rwsem); + } +if (res <0 ) goto out; res = -ENOENT ;if (!IS_DEADDIR (inode)) { - res =file_accessed (file, ctx->flags &DIR_CONTEXT_F_NOWAIT ); + res =file_accessed (file, nowait);if (res == -EAGAIN ) goto out_unlock;
Signature · 1 line
2.25.1
Christian Brauner
maintainerRe: [PATCH 10/11] vfs: trylock inode->i_rwsem in iterate_dir() to support nowait
Quoted 7 lines · Hao Xu
From: Hao Xu <[email protected]>
Trylock
inode->i_rwseminiterate_dir()to support nowait semantics and error out-EAGAINwhen there is contention.Signed-off-by Hao Xu <[email protected]>---
Unreviewable until you rebased on -rc1 as far as I'm concerned because the code in here changed a lot.
PATCH v6 11/11 io_uring: add support for getdents
In reply to Hao XuFrom: Hao Xu <[email protected]>
This add support for getdents64 to io_uring, acting exactly like the
syscall: the directory is iterated from it's current's position as stored in the file struct, and the file's position is updated exactly as if getdents64 had been called.
For filesystems that support NOWAIT in iterate_shared(), try to use it first; if a user already knows the filesystem they use do not support nowait they can force async through IOSQE_ASYNC in the sqe flags, avoiding the need to bounce back through a useless EAGAIN return.
--- include/uapi/linux/io_uring.h | 1 + io_uring/fs.c | 53 +++++++++++++++++++++++++++++++++++ io_uring/fs.h | 3 ++ io_uring/opdef.c | 8 ++++++ 4 files changed, 65 insertions(+)
include/uapi/linux/io_uring.h +1 -0
@@ -240,6 +240,7 @@ enum io_uring_op {IORING_OP_URING_CMD ,IORING_OP_SEND_ZC ,IORING_OP_SENDMSG_ZC , +IORING_OP_GETDENTS ,/* this goes last, obviously */ IORING_OP_LAST,
io_uring/fs.c +53 -0
62 lines not on this page · raw message
io_uring/fs.h +3 -0
@@ -18,3 +18,6 @@ int io_symlinkat(struct io_kiocb *req, unsigned int issue_flags);int io_linkat_prep (struct io_kiocb *req,const struct io_uring_sqe *sqe);int io_linkat (struct io_kiocb *req,unsigned int issue_flags);void io_link_cleanup (struct io_kiocb *req); + +int io_getdents_prep (struct io_kiocb *req,const struct io_uring_sqe *sqe); +int io_getdents (struct io_kiocb *req,unsigned int issue_flags);
io_uring/opdef.c +8 -0
@@ -428,6 +428,11 @@ const struct io_issue_def io_issue_defs[] = { .prep = io_eopnotsupp_prep, #endif }, + [IORING_OP_GETDENTS ] = { + .needs_file =1 , + .prep = io_getdents_prep, + .issue = io_getdents, + }, };
@@ -648,6 +653,9 @@ const struct io_cold_def io_cold_defs[] = { .fail = io_sendrecv_fail,#endif }, + [IORING_OP_GETDENTS] = { + .name = "GETDENTS", + }, };const char *io_uring_get_opcode (u8 opcode)
Signature · 1 line
2.25.1
Christian Brauner
maintainerOn Sun, Aug 27, 2023 at 09:28:24PM +0800, Hao Xu wrote:
For the future it would be helpful to hold of on sending larger series that like this until a stable tag is out.
Right now this series is generating a bunch of merge conflicts because of all the changes to relevant codepaths that got merged. So either we have to resolve them to see whether things still make sense within the context of all the changed code or risk that stuff we comment is outdated.