btrfs direct-io using iomap
Subsystems (5)
v8 cover btrfs direct-io using iomap
This is an effort to use iomap for direct I/O in btrfs. This would change the call from __blockdev_direct_io() to iomap_dio_rw().
The main objective is to lose the buffer head and use bio defined by iomap code, and hopefully to use more of generic-FS codebase.
These patches are based and tested on kdave/for-next-20200511. I have tested it against xfstests/btrfs.
The tree is available at
https://github.com/goldwynr/linux/tree/dio-merge
Changes since v1
- Incorporated back the efficiency change for inode locking
- Review comments about coding style and git comments
- Merge related patches into one
- Direct read to go through btrfs_direct_IO()
- Removal of no longer used function dio_end_io()
Changes since v2
- aligning iomap offset/length to the position/length of I/O
- Removed btrfs_dio_data
- Removed BTRFS_INODE_READDIO_NEED_LOCK
- Re-incorporating write efficiency changes caused lockdep_assert() in iomap to be triggered, remove that code.
Changes since v3
- Fixed freeze on generic/095. Use iomap_end() to account for failed/incomplete dio instead of btrfs_dio_data
Changes since v4
- moved lockdep_assert_held() to functions calling iomap_dio_rw() This may be called immidiately after calling inode lock and may feel not required, but it seems important.
- Removed comments which are no longer required
- Changed commit comments to make them more appropriate
Changes since v5
- restore inode_dio_wait() in truncate
- Removed lockdep_assert_held() near callers
Changes since v6
- Fixed hangs due to underlying device failures
- Removed the patch to wait while releasing pages
Changes since v7
- Moved reservation into btrfs iomap begin()/end() for correct reservation cleanup in case of device error.
- Merged patches switch to iomap, and adding btrfs_iomap_end() for easier bisection. The switch to iomap would fail in case of dio after buffered writes.
PATCH v8 1/7 fs: Export generic_file_buffered_read()
From: Goldwyn Rodrigues <[email protected]>
Export generic_file_buffered_read() to be used to supplement incomplete direct reads.
While we are at it, correct the comments and variable names.
--- include/linux/fs.h | 2 ++ mm/filemap.c | 13 +++++++------ 2 files changed, 9 insertions(+), 6 deletions(-)
include/linux/fs.h +2 -0
@@ -3124,6 +3124,8 @@ extern int generic_file_rw_checks(struct file *file_in, struct file *file_out);extern int generic_copy_file_checks (struct file *file_in,loff_t pos_in,struct file *file_out,loff_t pos_out,size_t *count,unsigned int flags); +extern ssize_t generic_file_buffered_read (struct kiocb *iocb, +struct iov_iter *to,ssize_t already_read);extern ssize_t generic_file_read_iter (struct kiocb *,struct iov_iter *);extern ssize_t __generic_file_write_iter (struct kiocb *,struct iov_iter *);extern ssize_t generic_file_write_iter (struct kiocb *,struct iov_iter *);
mm/filemap.c +7 -6
@@ -1979,7 +1979,7 @@ static void shrink_readahead_size_eio(struct file_ra_state *ra)* generic_file_buffered_read - generic file read routine * @iocb: the iocb to read * @iter: data destination -* @written: already copied +* @copied: already copied * * This is a generic file read routine, and uses the * mapping->a_ops->readpage() function for the actual low-level stuff.
@@ -1988,11 +1988,11 @@ static void shrink_readahead_size_eio(struct file_ra_state *ra)* of the logic when it comes to error handling etc. * * Return: -* * total number of bytes copied, including those the were already @written +* * total number of bytes copied, including those that were @copied * * negative error code if nothing was copied */ -static ssize_t generic_file_buffered_read (struct kiocb *iocb, -struct iov_iter *iter,ssize_t written) +ssize_t generic_file_buffered_read (struct kiocb *iocb, +struct iov_iter *iter,ssize_t copied) {struct file *filp = iocb->ki_filp;struct address_space *mapping = filp->f_mapping;
@@ -2133,7 +2133,7 @@ static ssize_t generic_file_buffered_read(struct kiocb *iocb, prev_offset = offset;put_page (page); - written += ret; + copied += ret;if (!iov_iter_count (iter)) goto out;if (ret < nr) {
@@ -2241,8 +2241,9 @@ static ssize_t generic_file_buffered_read(struct kiocb *iocb, *ppos = ((loff_t )index <<PAGE_SHIFT ) + offset;file_accessed (filp); -return written ? written : error; +return copied ? copied : error; } +EXPORT_SYMBOL_GPL (generic_file_buffered_read);/** * generic_file_read_iter - generic filesystem read routine
Signature · 1 line
2.25.0
Re: [PATCH 1/7] fs: Export generic_file_buffered_read()
Quoted 66 lines · Goldwyn Rodrigues
From: Goldwyn Rodrigues <[email protected]>
Export
generic_file_buffered_read()to be used to supplement incomplete direct reads.While we are at it, correct the comments and variable names.
Signed-off-by Goldwyn Rodrigues <[email protected]>Reviewed-by Johannes Thumshirn <[email protected]>Reviewed-by Christoph Hellwig <[email protected]>--- include/linux/fs.h | 2 ++ mm/filemap.c | 13 +++++++------ 2 files changed, 9 insertions(+), 6 deletions(-)include/linux/fs.h +2
-0@@ -3124,6 +3124,8 @@ extern int generic_file_rw_checks(struct file *file_in, struct file *file_out);extern int generic_copy_file_checks (struct file *file_in,loff_t pos_in,struct file *file_out,loff_t pos_out,size_t *count,unsigned int flags); +extern ssize_t generic_file_buffered_read (struct kiocb *iocb, +struct iov_iter *to,ssize_t already_read);extern ssize_t generic_file_read_iter (struct kiocb *,struct iov_iter *);extern ssize_t __generic_file_write_iter (struct kiocb *,struct iov_iter *);extern ssize_t generic_file_write_iter (struct kiocb *,struct iov_iter *);mm/filemap.c +5
-5@@ -1979,7 +1979,7 @@ static void shrink_readahead_size_eio(struct file_ra_state *ra)* generic_file_buffered_read - generic file read routine * @iocb: the iocb to read * @iter: data destination -* @written: already copied +* @copied: already copied * * This is a generic file read routine, and uses the * mapping->a_ops->readpage() function for the actual low-level stuff. @@ -1988,11 +1988,11 @@ static void shrink_readahead_size_eio(struct file_ra_state *ra)* of the logic when it comes to error handling etc. * * Return: -* * total number of bytes copied, including those the were already @written +* * total number of bytes copied, including those that were @copied * * negative error code if nothing was copied */ -static ssize_t generic_file_buffered_read (struct kiocb *iocb, -struct iov_iter *iter,ssize_t written) +ssize_t generic_file_buffered_read (struct kiocb *iocb, +struct iov_iter *iter,ssize_t copied) {struct file *filp = iocb->ki_filp;struct address_space *mapping = filp->f_mapping;@@ -2133,7 +2133,7 @@ static ssize_t generic_file_buffered_read(struct kiocb *iocb, prev_offset = offset;put_page (page); - written += ret; + copied += ret;if (!iov_iter_count (iter)) goto out;if (ret < nr) {
mm/filemap.c static ssize_t generic_file_buffered_read(struct kiocb *iocb, · line 2246
Quoted 7 lines
mm/filemap.c +2
-1@@ -2241,8 +2241,9 @@ static ssize_t generic_file_buffered_read(struct kiocb *iocb, *ppos = ((loff_t )index <<PAGE_SHIFT ) + offset;file_accessed (filp); -return written ? written : error; +return copied ? copied : error; } +EXPORT_SYMBOL_GPL (generic_file_buffered_read);
The renamed variable causes build issues with block tree so I've s/copied/written/ back as we want only the function export.
PATCH v8 2/7 iomap: add a filesystem hook for direct I/O bio submission
In reply to Goldwyn RodriguesFrom: Goldwyn Rodrigues <[email protected]>
This helps filesystems to perform tasks on the bio while submitting for I/O. This could be post-write operations such as data CRC or data replication for fs-handled RAID.
--- fs/iomap/direct-io.c | 15 ++++++++++----- include/linux/iomap.h | 2 ++ 2 files changed, 12 insertions(+), 5 deletions(-)
fs/iomap/direct-io.c +10 -5
@@ -59,7 +59,7 @@ int iomap_dio_iopoll(struct kiocb *kiocb, bool spin)EXPORT_SYMBOL_GPL (iomap_dio_iopoll);static void iomap_dio_submit_bio (struct iomap_dio *dio,struct iomap *iomap, -struct bio *bio) +struct bio *bio,loff_t pos) {atomic_inc (&dio->ref);
@@ -67,7 +67,12 @@ static void iomap_dio_submit_bio(struct iomap_dio *dio, struct iomap *iomap,bio_set_polled (bio, dio->iocb); dio->submit.last_queue =bdev_get_queue (iomap->bdev); - dio->submit.cookie =submit_bio (bio); +if (dio->dops && dio->dops->submit_io) + dio->submit.cookie = dio->dops->submit_io ( +file_inode (dio->iocb->ki_filp), + iomap, bio, pos); +else + dio->submit.cookie =submit_bio (bio); }static ssize_t iomap_dio_complete (struct iomap_dio *dio)
@@ -191,7 +196,7 @@ iomap_dio_zero(struct iomap_dio *dio, struct iomap *iomap, loff_t pos,get_page (page);__bio_add_page (bio, page, len,0 );bio_set_op_attrs (bio,REQ_OP_WRITE , flags); -iomap_dio_submit_bio (dio, iomap, bio); +iomap_dio_submit_bio (dio, iomap, bio, pos); } static loff_t
@@ -299,11 +304,11 @@ iomap_dio_bio_actor(struct inode *inode, loff_t pos, loff_t length, } dio->size += n; - pos += n; copied += n; nr_pages =iov_iter_npages (dio->submit.iter,BIO_MAX_PAGES ); -iomap_dio_submit_bio (dio, iomap, bio); +iomap_dio_submit_bio (dio, iomap, bio, pos); + pos += n; }while (nr_pages);/*
include/linux/iomap.h +2 -0
@@ -252,6 +252,8 @@ int iomap_writepages(struct address_space *mapping,struct iomap_dio_ops {int (*end_io)(struct kiocb *iocb,ssize_t size,int error,unsigned flags); +blk_qc_t (*submit_io)(struct inode *inode,struct iomap *iomap, +struct bio *bio,loff_t file_offset); }; ssize_t iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter,
Signature · 1 line
2.25.0
PATCH v8 3/7 iomap: Remove lockdep_assert_held()
In reply to Goldwyn RodriguesFrom: Goldwyn Rodrigues <[email protected]>
Filesystems such as btrfs can perform direct I/O without holding the inode->i_rwsem in some of the cases like writing within i_size. So, remove the check for lockdep_assert_held() in iomap_dio_rw()
--- fs/iomap/direct-io.c | 2 -- 1 file changed, 2 deletions(-)
fs/iomap/direct-io.c +0 -2
@@ -416,8 +416,6 @@ iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter,struct blk_plug plug;struct iomap_dio *dio; -lockdep_assert_held (&inode->i_rwsem); -if (!count)return 0 ;
Signature · 1 line
2.25.0
Re: [PATCH 3/7] iomap: Remove lockdep_assert_held()
Quoted 17 lines · Goldwyn Rodrigues
From: Goldwyn Rodrigues <[email protected]>
Filesystems such as btrfs can perform direct I/O without holding the
inode->i_rwsemin some of the cases like writing withini_size. So, remove the check forlockdep_assert_held()iniomap_dio_rw()Signed-off-by Goldwyn Rodrigues <[email protected]>Reviewed-by Darrick J. Wong <[email protected]>--- fs/iomap/direct-io.c | 2 -- 1 file changed, 2 deletions(-)fs/iomap/direct-io.c +0
-0
fs/iomap/direct-io.c iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter, · line 420
Quoted 5 lines
fs/iomap/direct-io.c +0
-2@@ -416,8 +416,6 @@ iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter,struct blk_plug plug;struct iomap_dio *dio; -lockdep_assert_held (&inode->i_rwsem); -
I could've sworn that I saw a reply from Dave asking to hoist this check into all the /other/ iomap_dio_rw callers, but I can't find it and maybe I just dreamed the whole thing.
Also, please cc fsdevel any time you make change to fs/iomap/, even if we've already reviewed the patches.
--D
Quoted 6 lines
fs/iomap/direct-io.c +0
-0if (!count)return 0 ;Signature · 1 line
2.25.0
Re: [PATCH 3/7] iomap: Remove lockdep_assert_held()
Quoted 21 lines · Darrick J. Wong
Quoted 20 lines · Goldwyn Rodrigues
From: Goldwyn Rodrigues <[email protected]>
Filesystems such as btrfs can perform direct I/O without holding the
inode->i_rwsemin some of the cases like writing withini_size. So, remove the check forlockdep_assert_held()iniomap_dio_rw()Signed-off-by Goldwyn Rodrigues <[email protected]>Reviewed-by Darrick J. Wong <[email protected]>--- fs/iomap/direct-io.c | 2 -- 1 file changed, 2 deletions(-)fs/iomap/direct-io.c +0
-0@@ -416,8 +416,6 @@ iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter,struct blk_plug plug;struct iomap_dio *dio;
Quoted 6 lines
fs/iomap/direct-io.c iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter, · line 420
Quoted 2 lines
fs/iomap/direct-io.c +0
-2-lockdep_assert_held (&inode->i_rwsem); -I could've sworn that I saw a reply from Dave asking to hoist this check into all the /other/
iomap_dio_rwcallers, but I can't find it and maybe I just dreamed the whole thing.
It did happen! However, hch mentioned it is not required [1]. I did promise him to remove the entire concept of dio_sem locking in btrfs, and just rely on inode->i_mutex. It is still a work in progress.
Quoted 4 lines
Also, please cc fsdevel any time you make change to
fs/iomap/, even if we've already reviewed the patches.
Yes, missed that. Sorry.
[1] https://www.spinics.net/lists/linux-btrfs/msg96016.html
Signature · 1 line
Goldwyn
PATCH v8 4/7 btrfs: Switch to iomap_dio_rw() for dio
In reply to Goldwyn RodriguesFrom: Goldwyn Rodrigues <[email protected]>
Switch from __blockdev_direct_IO() to iomap_dio_rw(). Rename btrfs_get_blocks_direct() to btrfs_dio_iomap_begin() and use it as iomap_begin() for iomap direct I/O functions. This function allocates and locks all the blocks required for the I/O. btrfs_submit_direct() is used as the submit_io() hook for direct I/O ops.
Since we need direct I/O reads to go through iomap_dio_rw(), we change file_operations.read_iter() to a btrfs_file_read_iter() which calls btrfs_direct_IO() for direct reads and falls back to generic_file_buffered_read() for incomplete reads and buffered reads.
We don't need address_space.direct_IO() anymore so set it to noop. Similarly, we don't need flags used in __blockdev_direct_IO(). iomap is capable of direct I/O reads from a hole, so we don't need to return -ENOENT.
BTRFS direct I/O is now done under i_rwsem, shared in case of reads and exclusive in case of writes. This guards against simultaneous truncates.
Use iomap->iomap_end() to check for failed or incomplete direct I/O:
For writes, call __endio_write_update_ordered()
For reads, Unlock extents
btrfs_dio_data is now hooked in iomap->private and not current->journal_info. It carries the reservation variable and the amount of data submitted, so we can calculate the amount of data to call __endio_write_update_ordered in case of an error.
--- fs/btrfs/ctree.h | 1 + fs/btrfs/file.c | 21 +++- fs/btrfs/inode.c | 313 ++++++++++++++++++++++------------------------- 3 files changed, 169 insertions(+), 166 deletions(-)
fs/btrfs/ctree.h +1 -0
@@ -2911,6 +2911,7 @@ int btrfs_writepage_cow_fixup(struct page *page, u64 start, u64 end);void btrfs_writepage_endio_finish_ordered (struct page *page,u64 start,u64 end,int uptodate);extern const struct dentry_operations btrfs_dentry_operations; +ssize_t btrfs_direct_IO (struct kiocb *iocb,struct iov_iter *iter);/* ioctl.c */ long btrfs_ioctl (struct file *file,unsigned int cmd,unsigned long arg);
fs/btrfs/file.c +19 -2
@@ -1827,7 +1827,7 @@ static ssize_t __btrfs_direct_write(struct kiocb *iocb, struct iov_iter *from)loff_t endbyte;int err; - written =generic_file_direct_write (iocb, from); + written =btrfs_direct_IO (iocb, from);if (written <0 || !iov_iter_count (from))return written;
@@ -3484,9 +3484,26 @@ static int btrfs_file_open(struct inode *inode, struct file *filp)return generic_file_open (inode, filp); } +static ssize_t btrfs_file_read_iter (struct kiocb *iocb,struct iov_iter *to) +{ +ssize_t ret =0 ; + +if (iocb->ki_flags &IOCB_DIRECT ) { +struct inode *inode =file_inode (iocb->ki_filp); + +inode_lock_shared (inode); + ret =btrfs_direct_IO (iocb, to); +inode_unlock_shared (inode); +if (ret <0 ) +return ret; + } + +return generic_file_buffered_read (iocb, to, ret); +} +const struct file_operations btrfs_file_operations = { .llseek = btrfs_file_llseek, - .read_iter = generic_file_read_iter, + .read_iter = btrfs_file_read_iter, .splice_read = generic_file_splice_read, .write_iter = btrfs_file_write_iter, .mmap = btrfs_file_mmap,
fs/btrfs/inode.c +149 -164
493 lines not on this page · raw message
Signature · 1 line
2.25.0
Re: [PATCH 4/7] btrfs: Switch to iomap_dio_rw() for dio
Just as a heads up, this one gives me lot's of Page cache invalidation failure prints from dio_warn_stale_pagecache() on btrfs/004 with current misc-next:
[ 16.607545] Page cache invalidation failure on direct I/O. Possible data corruption due to collision with buffered I/O! [ 16.609328] File: /mnt/scratch/next/p0/d0/d77/de2/d5c/dc9/fee PID: 766 Comm: fsstress [ 16.743572] BTRFS info (device zram1): disk space caching is enabled [ 16.744620] BTRFS info (device zram1): has skinny extents [ 16.747458] BTRFS info (device zram1): enabling ssd optimizations [ 18.303877] Page cache invalidation failure on direct I/O. Possible data corruption due to collision with buffered I/O! [ 18.305476] File: /mnt/scratch/bgnoise/p0/d5/d53/d21/f27 PID: 2064 Comm: fsstress [ 18.768426] Page cache invalidation failure on direct I/O. Possible data corruption due to collision with buffered I/O! [ 18.770074] File: /mnt/scratch/bgnoise/p0/d9/de/f15 PID: 2490 Comm: fsstress [ 18.916118] Page cache invalidation failure on direct I/O. Possible data corruption due to collision with buffered I/O! [ 18.917843] File: /mnt/scratch/bgnoise/p0/f0 PID: 2694 Comm: fsstress [ 21.170384] Page cache invalidation failure on direct I/O. Possible data corruption due to collision with buffered I/O! [ 21.172375] File: /mnt/scratch/bgnoise/p0/f3 PID: 4325 Comm: fsstress [ 21.812452] Page cache invalidation failure on direct I/O. Possible data corruption due to collision with buffered I/O! [ 21.814232] File: /mnt/scratch/bgnoise/p0/fb PID: 5000 Comm: fsstress [ 21.826027] Page cache invalidation failure on direct I/O. Possible data corruption due to collision with buffered I/O! [ 21.827741] File: /mnt/scratch/bgnoise/p0/fb PID: 5000 Comm: fsstress [ 22.127966] Page cache invalidation failure on direct I/O. Possible data corruption due to collision with buffered I/O! [ 22.129413] File: /mnt/scratch/bgnoise/p0/df/d28/d26/f3b PID: 5196 Comm: fsstress [ 22.160542] Page cache invalidation failure on direct I/O. Possible data corruption due to collision with buffered I/O! [ 22.161972] File: /mnt/scratch/bgnoise/p0/df/d10/d5f/f64 PID: 5196 Comm: fsstress [ 23.696400] Page cache invalidation failure on direct I/O. Possible data corruption due to collision with buffered I/O! [ 23.698115] File: /mnt/scratch/bgnoise/p0/f0 PID: 6562 Comm: fsstress
I have no idea yet why but I'm investigating.
Re: [PATCH 4/7] btrfs: Switch to iomap_dio_rw() for dio
Quoted 4 lines · Johannes Thumshirn
Just as a heads up, this one gives me lot's of Page cache invalidation failure prints from
dio_warn_stale_pagecache()on btrfs/004 with current misc-next:
<snip>
Quoted 4 lines
[ 23.696400] Page cache invalidation failure on direct I/O. Possible data corruption due to collision with buffered I/O! [ 23.698115] File: /mnt/scratch/bgnoise/p0/f0 PID: 6562 Comm: fsstressI have no idea yet why but I'm investigating.
This is caused because we are trying to release a page when the extent has locked the page and release page returns false. To minimize the effect, I had proposed a patch [1] in v6. However, this created more extent locking issues and so was dropped.
[1] https://patchwork.kernel.org/patch/11275063/
Signature · 1 line
Goldwyn
Re: [PATCH 4/7] btrfs: Switch to iomap_dio_rw() for dio
Quoted 8 lines · Goldwyn Rodrigues
Quoted 4 lines · Johannes Thumshirn
Just as a heads up, this one gives me lot's of Page cache invalidation failure prints from
dio_warn_stale_pagecache()on btrfs/004 with current misc-next:<snip>
Quoted 7 lines
Quoted 4 lines
[ 23.696400] Page cache invalidation failure on direct I/O. Possible data corruption due to collision with buffered I/O! [ 23.698115] File: /mnt/scratch/bgnoise/p0/f0 PID: 6562 Comm: fsstressI have no idea yet why but I'm investigating.
This is caused because we are trying to release a page when the extent has locked the page and release page returns false.
By "we" you mean what exaclty, a direct IO read, a direct IO write?
And who locked the extent range before?
That seems alarming to me, specially if it's a direct IO write failing to invalidate the page cache, since a subsequent buffered read could get stale data (what's in the page cache), and not what the direct IO write wrote.
Can you elaborate more on all those details?
Thanks.
Quoted 8 lines
To minimize the
effect, I had proposed a patch [1] in v6. However, this created more extent locking issues and so was dropped.[1] https://patchwork.kernel.org/patch/11275063/
--
Goldwyn
Signature · 3 lines
Filipe David Manana, “Whether you think you can, or you think you can't — you're right.”
Re: [PATCH 4/7] btrfs: Switch to iomap_dio_rw() for dio
Quoted 12 lines · Filipe Manana
Quoted 11 lines · Goldwyn Rodrigues
Quoted 4 lines · Johannes Thumshirn
Just as a heads up, this one gives me lot's of Page cache invalidation failure prints from
dio_warn_stale_pagecache()on btrfs/004 with current misc-next:<snip>
Quoted 3 lines
[ 23.696400] Page cache invalidation failure on direct I/O. Possible data corruption due to collision with buffered I/O! [ 23.698115] File: /mnt/scratch/bgnoise/p0/f0 PID: 6562 Comm: fsstress
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
I have no idea yet why but I'm investigating.
This is caused because we are trying to release a page when the extent has locked the page and release page returns false.
By "we" you mean what exaclty, a direct IO read, a direct IO write?
And who locked the extent range before?
This is usually locked by a previous buffered write or read.
Quoted 7 lines
That seems alarming to me, specially if it's a direct IO write failing to invalidate the page cache, since a subsequent buffered read could get stale data (what's in the page cache), and not what the direct IO write wrote.
Can you elaborate more on all those details?
The origin of the message is when iomap_dio_rw() tries to invalidate the inode pages, but fails and calls dio_warn_stale_pagecache().
In the vanilla code, generic_file_direct_write() aborts direct writes and returns 0 so that it may fallback to buffered I/O. Perhaps this should be changed in iomap_dio_rw() as well. I will write a patch to accomodate that.
Signature · 1 line
Goldwyn
Re: [PATCH 4/7] btrfs: Switch to iomap_dio_rw() for dio
Quoted 16 lines · Goldwyn Rodrigues
Quoted 14 lines · Filipe Manana
Quoted 13 lines · Goldwyn Rodrigues
Quoted 4 lines · Johannes Thumshirn
Just as a heads up, this one gives me lot's of Page cache invalidation failure prints from
dio_warn_stale_pagecache()on btrfs/004 with current misc-next:<snip>
Quoted 4 lines
[ 23.696400] Page cache invalidation failure on direct I/O. Possible data corruption due to collision with buffered I/O! [ 23.698115] File: /mnt/scratch/bgnoise/p0/f0 PID: 6562 Comm: fsstressI have no idea yet why but I'm investigating.
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
This is caused because we are trying to release a page when the extent has locked the page and release page returns false.
By "we" you mean what exaclty, a direct IO read, a direct IO write?
And who locked the extent range before?
This is usually locked by a previous buffered write or read.
A previous buffered write/read that has already finished or is still in progress?
Because if it has finished we're not supposed to have the file range locked anymore.
Quoted 9 lines
Quoted 8 lines
That seems alarming to me, specially if it's a direct IO write failing to invalidate the page cache, since a subsequent buffered read could get stale data (what's in the page cache), and not what the direct IO write wrote.
Can you elaborate more on all those details?
Quoted 7 lines
The origin of the message is when
iomap_dio_rw()tries to invalidate the inode pages, but fails and callsdio_warn_stale_pagecache().In the vanilla code,
generic_file_direct_write()aborts direct writes and returns 0 so that it may fallback to buffered I/O. Perhaps this should be changed iniomap_dio_rw()as well. I will write a patch to accomodate that.
On vanilla we have no problems of mixing buffered and direct operations as long as they are done sequentially at least. And even if done concurrently we take several measures to ensure that are no surprises (locking ranges, waiting for any ordered extents in progress, etc).
Thanks.
Quoted 3 lines
--
Goldwyn
Signature · 3 lines
Filipe David Manana, “Whether you think you can, or you think you can't — you're right.”
Re: [PATCH 4/7] btrfs: Switch to iomap_dio_rw() for dio
Quoted 10 lines · Filipe Manana
Quoted 3 lines · Goldwyn Rodrigues
Quoted 1 line
And who locked the extent range before?
This is usually locked by a previous buffered write or read.
A previous buffered write/read that has already finished or is still in progress?
Because if it has finished we're not supposed to have the file range locked anymore.
In progress. Mixing buffered I/O with direct writes.
Quoted 18 lines
Quoted 10 lines
Quoted 9 lines
That seems alarming to me, specially if it's a direct IO write failing to invalidate the page cache, since a subsequent buffered read could get stale data (what's in the page cache), and not what the direct IO write wrote.
Can you elaborate more on all those details?
Quoted 7 lines
The origin of the message is when
iomap_dio_rw()tries to invalidate the inode pages, but fails and callsdio_warn_stale_pagecache().In the vanilla code,
generic_file_direct_write()aborts direct writes and returns 0 so that it may fallback to buffered I/O. Perhaps this should be changed iniomap_dio_rw()as well. I will write a patch to accomodate that.
Quoted 5 lines
On vanilla we have no problems of mixing buffered and direct operations as long as they are done sequentially at least. And even if done concurrently we take several measures to ensure that are no surprises (locking ranges, waiting for any ordered extents in progress, etc).
Yes, it is because of the code in generic_file_direct_write(). Anyways, I did some tests with the following patch, and it seems to work. I will send a formal patch to so that it gets incorporated in iomap sequence as well.
fs/iomap/direct-io.c +9 -3
@@ -483,9 +483,15 @@ iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter,*/ ret =invalidate_inode_pages2_range (mapping, pos >>PAGE_SHIFT , end >>PAGE_SHIFT ); -if (ret) -dio_warn_stale_pagecache (iocb->ki_filp); - ret =0 ; +/* +* If a page can not be invalidated, return 0 to fall back +* to buffered write. +*/ +if (ret) { +if (ret == -EBUSY ) + ret =0 ; + goto out_free_dio; + }if (iov_iter_rw (iter) ==WRITE && !wait_for_completion && !inode->i_sb->s_dio_done_wq) {
Signature · 1 line
Goldwyn
Re: [PATCH 4/7] btrfs: Switch to iomap_dio_rw() for dio
Quoted 59 lines · Goldwyn Rodrigues
Quoted 10 lines · Filipe Manana
Quoted 3 lines · Goldwyn Rodrigues
Quoted 1 line
And who locked the extent range before?
This is usually locked by a previous buffered write or read.
A previous buffered write/read that has already finished or is still in progress?
Because if it has finished we're not supposed to have the file range locked anymore.
In progress. Mixing buffered I/O with direct writes.
Quoted 18 lines
Quoted 10 lines
Quoted 9 lines
That seems alarming to me, specially if it's a direct IO write failing to invalidate the page cache, since a subsequent buffered read could get stale data (what's in the page cache), and not what the direct IO write wrote.
Can you elaborate more on all those details?
Quoted 7 lines
The origin of the message is when
iomap_dio_rw()tries to invalidate the inode pages, but fails and callsdio_warn_stale_pagecache().In the vanilla code,
generic_file_direct_write()aborts direct writes and returns 0 so that it may fallback to buffered I/O. Perhaps this should be changed iniomap_dio_rw()as well. I will write a patch to accomodate that.Quoted 5 lines
On vanilla we have no problems of mixing buffered and direct operations as long as they are done sequentially at least. And even if done concurrently we take several measures to ensure that are no surprises (locking ranges, waiting for any ordered extents in progress, etc).
Yes, it is because of the code in
generic_file_direct_write(). Anyways, I did some tests with the following patch, and it seems to work. I will send a formal patch to so that it gets incorporated in iomap sequence as well.fs/iomap/direct-io.c +2
-3@@ -483,9 +483,15 @@ iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter,*/ ret =invalidate_inode_pages2_range (mapping, pos >>PAGE_SHIFT , end >>PAGE_SHIFT ); -if (ret) -dio_warn_stale_pagecache (iocb->ki_filp); - ret =0 ; +/* +* If a page can not be invalidated, return 0 to fall back
fs/iomap/direct-io.c iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter, · line 497
Quoted 10 lines
fs/iomap/direct-io.c +7
-0+* to buffered write. +*/ +if (ret) { +if (ret == -EBUSY ) + ret =0 ; + goto out_free_dio; + }if (iov_iter_rw (iter) ==WRITE && !wait_for_completion && !inode->i_sb->s_dio_done_wq) {
Thanks. As I just replied on another thread for that patch, we actually have a regression.
There's more than the annoying warning in dmesg, it also sets -EIO on the inode's mapping and makes future fsyncs return that error despite the fact that no actual errors or corruptions happened:
Quoted 3 lines
--
Goldwyn
Signature · 3 lines
Filipe David Manana, “Whether you think you can, or you think you can't — you're right.”
Re: [PATCH 4/7] btrfs: Switch to iomap_dio_rw() for dio
Quoted 78 lines · Filipe Manana
Quoted 59 lines · Goldwyn Rodrigues
Quoted 10 lines · Filipe Manana
Quoted 3 lines · Goldwyn Rodrigues
Quoted 1 line
And who locked the extent range before?
This is usually locked by a previous buffered write or read.
A previous buffered write/read that has already finished or is still in progress?
Because if it has finished we're not supposed to have the file range locked anymore.
In progress. Mixing buffered I/O with direct writes.
Quoted 18 lines
Quoted 10 lines
Quoted 9 lines
That seems alarming to me, specially if it's a direct IO write failing to invalidate the page cache, since a subsequent buffered read could get stale data (what's in the page cache), and not what the direct IO write wrote.
Can you elaborate more on all those details?
Quoted 7 lines
The origin of the message is when
iomap_dio_rw()tries to invalidate the inode pages, but fails and callsdio_warn_stale_pagecache().In the vanilla code,
generic_file_direct_write()aborts direct writes and returns 0 so that it may fallback to buffered I/O. Perhaps this should be changed iniomap_dio_rw()as well. I will write a patch to accomodate that.Quoted 5 lines
On vanilla we have no problems of mixing buffered and direct operations as long as they are done sequentially at least. And even if done concurrently we take several measures to ensure that are no surprises (locking ranges, waiting for any ordered extents in progress, etc).
Yes, it is because of the code in
generic_file_direct_write(). Anyways, I did some tests with the following patch, and it seems to work. I will send a formal patch to so that it gets incorporated in iomap sequence as well.fs/iomap/direct-io.c +2
-3@@ -483,9 +483,15 @@ iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter,*/ ret =invalidate_inode_pages2_range (mapping, pos >>PAGE_SHIFT , end >>PAGE_SHIFT ); -if (ret) -dio_warn_stale_pagecache (iocb->ki_filp); - ret =0 ; +/* +* If a page can not be invalidated, return 0 to fall back fs/iomap/direct-io.c iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter, · line 497
Quoted 10 lines
fs/iomap/direct-io.c +7
-0+* to buffered write. +*/ +if (ret) { +if (ret == -EBUSY ) + ret =0 ; + goto out_free_dio; + }if (iov_iter_rw (iter) ==WRITE && !wait_for_completion && !inode->i_sb->s_dio_done_wq) {Thanks. As I just replied on another thread for that patch, we actually have a regression.
There's more than the annoying warning in dmesg, it also sets-EIOon the inode's mapping and makes future fsyncs return that error despite the fact that no actual errors or corruptions happened:
Quoted 2 lines
There's also some deadlock/hang, I have triggered it twice today with generic/113 on two different VMs:
[14621.297370] INFO: task kworker/1:117:15962 blocked for more than 120 seconds. [14621.298491] Not tainted 5.7.0-rc7-btrfs-next-59 #1 [14621.299231] "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message. [14621.300523] kworker/1:117 D 0 15962 2 0x80004000 [14621.301558] Workqueue: dio/sdb iomap_dio_complete_work [14621.302389] Call Trace: [14621.302877] __schedule+0x384/0xa30 [14621.303555] schedule+0x33/0xe0 [14621.304167] rwsem_down_write_slowpath+0x2c2/0x750 [14621.305121] ? btrfs_sync_file+0x1fe/0x4d0 [btrfs] [14621.306217] btrfs_sync_file+0x1fe/0x4d0 [btrfs] [14621.307113] iomap_dio_complete+0x11b/0x260 [14621.307888] ? aio_fsync_work+0x5b0/0x5b0 [14621.308585] iomap_dio_complete_work+0x17/0x30 [14621.309476] process_one_work+0x275/0x6b0 [14621.310275] worker_thread+0x4f/0x3e0 [14621.310869] ? process_one_work+0x6b0/0x6b0 [14621.311403] kthread+0x12a/0x170 [14621.311819] ? kthread_create_worker_on_cpu+0x70/0x70 [14621.312460] ret_from_fork+0x3a/0x50 [14621.312983] INFO: task kworker/1:199:16063 blocked for more than 120 seconds. [14621.313921] Not tainted 5.7.0-rc7-btrfs-next-59 #1 [14621.314680] "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message. [14621.315724] kworker/1:199 D 0 16063 2 0x80004000 [14621.316445] Workqueue: dio/sdb iomap_dio_complete_work [14621.317101] Call Trace: [14621.317437] __schedule+0x384/0xa30 [14621.317928] schedule+0x33/0xe0 [14621.318339] rwsem_down_write_slowpath+0x2c2/0x750 [14621.318981] ? btrfs_sync_file+0x1fe/0x4d0 [btrfs] [14621.319609] btrfs_sync_file+0x1fe/0x4d0 [btrfs] [14621.320203] iomap_dio_complete+0x11b/0x260 [14621.320721] ? aio_fsync_work+0x5b0/0x5b0 [14621.321249] iomap_dio_complete_work+0x17/0x30 [14621.321844] process_one_work+0x275/0x6b0 [14621.322376] worker_thread+0x4f/0x3e0 [14621.322871] ? process_one_work+0x6b0/0x6b0 [14621.323408] kthread+0x12a/0x170 [14621.323827] ? kthread_create_worker_on_cpu+0x70/0x70 [14621.324473] ret_from_fork+0x3a/0x50 [14621.324983] INFO: task aio-stress:16274 blocked for more than 120 seconds. [14621.325896] Not tainted 5.7.0-rc7-btrfs-next-59 #1 [14621.326579] "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message. [14621.327580] aio-stress D 0 16274 14855 0x00004000 [14621.328280] Call Trace: [14621.328602] __schedule+0x384/0xa30 [14621.329056] schedule+0x33/0xe0 [14621.329478] rwsem_down_write_slowpath+0x2c2/0x750 [14621.330118] ? btrfs_sync_file+0x219/0x4d0 [btrfs] [14621.330747] btrfs_sync_file+0x219/0x4d0 [btrfs] [14621.331346] iomap_dio_complete+0x11b/0x260 [14621.331886] iomap_dio_rw+0x3bc/0x4c0 [14621.332372] ? btrfs_file_write_iter+0x645/0x870 [btrfs] [14621.333076] btrfs_file_write_iter+0x645/0x870 [btrfs] [14621.333749] aio_write+0x148/0x1d0 [14621.334196] ? lock_acquire+0xb1/0x4a0 [14621.334682] ? __might_fault+0x3e/0x90 [14621.335172] ? __fget_files+0x132/0x270 [14621.335668] ? io_submit_one+0x946/0x1630 [14621.336184] io_submit_one+0x946/0x1630 [14621.336680] ? lock_acquire+0xb1/0x4a0 [14621.337175] ? __might_fault+0x3e/0x90 [14621.337707] ? __x64_sys_io_submit+0x9c/0x330 [14621.338269] __x64_sys_io_submit+0x9c/0x330 [14621.338812] ? do_syscall_64+0x5c/0x280 [14621.339303] do_syscall_64+0x5c/0x280 [14621.339774] entry_SYSCALL_64_after_hwframe+0x49/0xb3 [14621.340416] RIP: 0033:0x7fb6cd395717 [14621.340875] Code: Bad RIP value. [14621.341304] RSP: 002b:00007fb6bf7e1de8 EFLAGS: 00000202 ORIG_RAX: 00000000000000d1 [14621.342262] RAX: ffffffffffffffda RBX: 0000560d3d92ea60 RCX: 00007fb6cd395717 [14621.343180] RDX: 0000560d3d92ea60 RSI: 0000000000000008 RDI: 00007fb6cdb32000 [14621.344081] RBP: 0000000000000008 R08: 0000150e50ac6651 R09: 00000000003081a8 [14621.344981] R10: 00007fb6bf7e1df0 R11: 0000000000000202 R12: 0000560d3d8fe110 [14621.345897] R13: 00007fb6bf7e1e10 R14: 00007fb6bf7e1e00 R15: 0000560d3d8fe110 [14621.346820] INFO: lockdep is turned off. [14742.125500] INFO: task kworker/1:117:15962 blocked for more than 241 seconds. [14742.126456] Not tainted 5.7.0-rc7-btrfs-next-59 #1 [14742.127156] "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message. [14742.128156] kworker/1:117 D 0 15962 2 0x80004000 [14742.128875] Workqueue: dio/sdb iomap_dio_complete_work [14742.129633] Call Trace: [14742.130010] __schedule+0x384/0xa30 [14742.130494] schedule+0x33/0xe0 [14742.131068] rwsem_down_write_slowpath+0x2c2/0x750 [14742.131956] ? btrfs_sync_file+0x1fe/0x4d0 [btrfs] [14742.132834] btrfs_sync_file+0x1fe/0x4d0 [btrfs] [14742.133712] iomap_dio_complete+0x11b/0x260 [14742.134475] ? aio_fsync_work+0x5b0/0x5b0 [14742.135205] iomap_dio_complete_work+0x17/0x30 [14742.136018] process_one_work+0x275/0x6b0 [14742.136677] worker_thread+0x4f/0x3e0 [14742.137154] ? process_one_work+0x6b0/0x6b0 [14742.137805] kthread+0x12a/0x170 [14742.138236] ? kthread_create_worker_on_cpu+0x70/0x70 [14742.138901] ret_from_fork+0x3a/0x50 [14742.139389] INFO: task kworker/1:199:16063 blocked for more than 241 seconds. [14742.140305] Not tainted 5.7.0-rc7-btrfs-next-59 #1 [14742.140998] "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message. [14742.142056] kworker/1:199 D 0 16063 2 0x80004000 [14742.142877] Workqueue: dio/sdb iomap_dio_complete_work [14742.143397] Call Trace: [14742.143654] __schedule+0x384/0xa30 [14742.144017] schedule+0x33/0xe0 [14742.144352] rwsem_down_write_slowpath+0x2c2/0x750 [14742.144859] ? btrfs_sync_file+0x1fe/0x4d0 [btrfs] [14742.145386] btrfs_sync_file+0x1fe/0x4d0 [btrfs] [14742.145863] iomap_dio_complete+0x11b/0x260 [14742.146289] ? aio_fsync_work+0x5b0/0x5b0 [14742.146701] iomap_dio_complete_work+0x17/0x30 [14742.147168] process_one_work+0x275/0x6b0 [14742.147579] worker_thread+0x4f/0x3e0 [14742.147954] ? process_one_work+0x6b0/0x6b0 [14742.148377] kthread+0x12a/0x170 [14742.148722] ? kthread_create_worker_on_cpu+0x70/0x70 [14742.149257] ret_from_fork+0x3a/0x50 [14742.149671] INFO: task aio-stress:16274 blocked for more than 241 seconds. [14742.150376] Not tainted 5.7.0-rc7-btrfs-next-59 #1 [14742.150948] "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message. [14742.151962] aio-stress D 0 16274 14855 0x00004000
(...)
Thanks.
Quoted 12 lines
Quoted 5 lines
--
Goldwyn--
Filipe David Manana,“Whether you think you can, or you think you can't — you're right.”
Signature · 3 lines
Filipe David Manana, “Whether you think you can, or you think you can't — you're right.”
Re: [PATCH 4/7] btrfs: Switch to iomap_dio_rw() for dio
Quoted 212 lines · Filipe Manana
Quoted 78 lines · Filipe Manana
Quoted 59 lines · Goldwyn Rodrigues
Quoted 10 lines · Filipe Manana
Quoted 3 lines · Goldwyn Rodrigues
Quoted 1 line
And who locked the extent range before?
This is usually locked by a previous buffered write or read.
A previous buffered write/read that has already finished or is still in progress?
Because if it has finished we're not supposed to have the file range locked anymore.
In progress. Mixing buffered I/O with direct writes.
Quoted 18 lines
Quoted 10 lines
Quoted 9 lines
That seems alarming to me, specially if it's a direct IO write failing to invalidate the page cache, since a subsequent buffered read could get stale data (what's in the page cache), and not what the direct IO write wrote.
Can you elaborate more on all those details?
Quoted 7 lines
The origin of the message is when
iomap_dio_rw()tries to invalidate the inode pages, but fails and callsdio_warn_stale_pagecache().In the vanilla code,
generic_file_direct_write()aborts direct writes and returns 0 so that it may fallback to buffered I/O. Perhaps this should be changed iniomap_dio_rw()as well. I will write a patch to accomodate that.Quoted 5 lines
On vanilla we have no problems of mixing buffered and direct operations as long as they are done sequentially at least. And even if done concurrently we take several measures to ensure that are no surprises (locking ranges, waiting for any ordered extents in progress, etc).
Yes, it is because of the code in
generic_file_direct_write(). Anyways, I did some tests with the following patch, and it seems to work. I will send a formal patch to so that it gets incorporated in iomap sequence as well.fs/iomap/direct-io.c +2
-3@@ -483,9 +483,15 @@ iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter,*/ ret =invalidate_inode_pages2_range (mapping, pos >>PAGE_SHIFT , end >>PAGE_SHIFT ); -if (ret) -dio_warn_stale_pagecache (iocb->ki_filp); - ret =0 ; +/* +* If a page can not be invalidated, return 0 to fall back fs/iomap/direct-io.c iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter, · line 497
Quoted 10 lines
fs/iomap/direct-io.c +7
-0+* to buffered write. +*/ +if (ret) { +if (ret == -EBUSY ) + ret =0 ; + goto out_free_dio; + }if (iov_iter_rw (iter) ==WRITE && !wait_for_completion && !inode->i_sb->s_dio_done_wq) {Thanks. As I just replied on another thread for that patch, we actually have a regression.
There's more than the annoying warning in dmesg, it also sets-EIOon the inode's mapping and makes future fsyncs return that error despite the fact that no actual errors or corruptions happened:Quoted 2 lines
There's also some deadlock/hang, I have triggered it twice today with generic/113 on two different VMs:
[14621.297370] INFO: task kworker/1:117:15962 blocked for more than 120 seconds. [14621.298491] Not tainted 5.7.0-rc7-btrfs-next-59 #1 [14621.299231] "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message. [14621.300523] kworker/1:117 D 0 15962 2 0x80004000 [14621.301558] Workqueue: dio/sdb iomap_dio_complete_work [14621.302389] Call Trace: [14621.302877] __schedule+0x384/0xa30 [14621.303555] schedule+0x33/0xe0 [14621.304167] rwsem_down_write_slowpath+0x2c2/0x750 [14621.305121] ? btrfs_sync_file+0x1fe/0x4d0 [btrfs] [14621.306217] btrfs_sync_file+0x1fe/0x4d0 [btrfs] [14621.307113] iomap_dio_complete+0x11b/0x260 [14621.307888] ? aio_fsync_work+0x5b0/0x5b0 [14621.308585] iomap_dio_complete_work+0x17/0x30 [14621.309476] process_one_work+0x275/0x6b0 [14621.310275] worker_thread+0x4f/0x3e0 [14621.310869] ? process_one_work+0x6b0/0x6b0 [14621.311403] kthread+0x12a/0x170 [14621.311819] ? kthread_create_worker_on_cpu+0x70/0x70 [14621.312460] ret_from_fork+0x3a/0x50 [14621.312983] INFO: task kworker/1:199:16063 blocked for more than 120 seconds. [14621.313921] Not tainted 5.7.0-rc7-btrfs-next-59 #1 [14621.314680] "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message. [14621.315724] kworker/1:199 D 0 16063 2 0x80004000 [14621.316445] Workqueue: dio/sdb iomap_dio_complete_work [14621.317101] Call Trace: [14621.317437] __schedule+0x384/0xa30 [14621.317928] schedule+0x33/0xe0 [14621.318339] rwsem_down_write_slowpath+0x2c2/0x750 [14621.318981] ? btrfs_sync_file+0x1fe/0x4d0 [btrfs] [14621.319609] btrfs_sync_file+0x1fe/0x4d0 [btrfs] [14621.320203] iomap_dio_complete+0x11b/0x260 [14621.320721] ? aio_fsync_work+0x5b0/0x5b0 [14621.321249] iomap_dio_complete_work+0x17/0x30 [14621.321844] process_one_work+0x275/0x6b0 [14621.322376] worker_thread+0x4f/0x3e0 [14621.322871] ? process_one_work+0x6b0/0x6b0 [14621.323408] kthread+0x12a/0x170 [14621.323827] ? kthread_create_worker_on_cpu+0x70/0x70 [14621.324473] ret_from_fork+0x3a/0x50 [14621.324983] INFO: task aio-stress:16274 blocked for more than 120 seconds. [14621.325896] Not tainted 5.7.0-rc7-btrfs-next-59 #1 [14621.326579] "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message. [14621.327580] aio-stress D 0 16274 14855 0x00004000 [14621.328280] Call Trace: [14621.328602] __schedule+0x384/0xa30 [14621.329056] schedule+0x33/0xe0 [14621.329478] rwsem_down_write_slowpath+0x2c2/0x750 [14621.330118] ? btrfs_sync_file+0x219/0x4d0 [btrfs] [14621.330747] btrfs_sync_file+0x219/0x4d0 [btrfs] [14621.331346] iomap_dio_complete+0x11b/0x260 [14621.331886] iomap_dio_rw+0x3bc/0x4c0 [14621.332372] ? btrfs_file_write_iter+0x645/0x870 [btrfs] [14621.333076] btrfs_file_write_iter+0x645/0x870 [btrfs] [14621.333749] aio_write+0x148/0x1d0 [14621.334196] ? lock_acquire+0xb1/0x4a0 [14621.334682] ? __might_fault+0x3e/0x90 [14621.335172] ? __fget_files+0x132/0x270 [14621.335668] ? io_submit_one+0x946/0x1630 [14621.336184] io_submit_one+0x946/0x1630 [14621.336680] ? lock_acquire+0xb1/0x4a0 [14621.337175] ? __might_fault+0x3e/0x90 [14621.337707] ? __x64_sys_io_submit+0x9c/0x330 [14621.338269] __x64_sys_io_submit+0x9c/0x330 [14621.338812] ? do_syscall_64+0x5c/0x280 [14621.339303] do_syscall_64+0x5c/0x280 [14621.339774] entry_SYSCALL_64_after_hwframe+0x49/0xb3 [14621.340416] RIP: 0033:0x7fb6cd395717 [14621.340875] Code: Bad RIP value. [14621.341304] RSP: 002b:00007fb6bf7e1de8 EFLAGS: 00000202 ORIG_RAX: 00000000000000d1 [14621.342262] RAX: ffffffffffffffda RBX: 0000560d3d92ea60 RCX: 00007fb6cd395717 [14621.343180] RDX: 0000560d3d92ea60 RSI: 0000000000000008 RDI: 00007fb6cdb32000 [14621.344081] RBP: 0000000000000008 R08: 0000150e50ac6651 R09: 00000000003081a8 [14621.344981] R10: 00007fb6bf7e1df0 R11: 0000000000000202 R12: 0000560d3d8fe110 [14621.345897] R13: 00007fb6bf7e1e10 R14: 00007fb6bf7e1e00 R15: 0000560d3d8fe110 [14621.346820] INFO: lockdep is turned off. [14742.125500] INFO: task kworker/1:117:15962 blocked for more than 241 seconds. [14742.126456] Not tainted 5.7.0-rc7-btrfs-next-59 #1 [14742.127156] "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message. [14742.128156] kworker/1:117 D 0 15962 2 0x80004000 [14742.128875] Workqueue: dio/sdb iomap_dio_complete_work [14742.129633] Call Trace: [14742.130010] __schedule+0x384/0xa30 [14742.130494] schedule+0x33/0xe0 [14742.131068] rwsem_down_write_slowpath+0x2c2/0x750 [14742.131956] ? btrfs_sync_file+0x1fe/0x4d0 [btrfs] [14742.132834] btrfs_sync_file+0x1fe/0x4d0 [btrfs] [14742.133712] iomap_dio_complete+0x11b/0x260 [14742.134475] ? aio_fsync_work+0x5b0/0x5b0 [14742.135205] iomap_dio_complete_work+0x17/0x30 [14742.136018] process_one_work+0x275/0x6b0 [14742.136677] worker_thread+0x4f/0x3e0 [14742.137154] ? process_one_work+0x6b0/0x6b0 [14742.137805] kthread+0x12a/0x170 [14742.138236] ? kthread_create_worker_on_cpu+0x70/0x70 [14742.138901] ret_from_fork+0x3a/0x50 [14742.139389] INFO: task kworker/1:199:16063 blocked for more than 241 seconds. [14742.140305] Not tainted 5.7.0-rc7-btrfs-next-59 #1 [14742.140998] "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message. [14742.142056] kworker/1:199 D 0 16063 2 0x80004000 [14742.142877] Workqueue: dio/sdb iomap_dio_complete_work [14742.143397] Call Trace: [14742.143654] __schedule+0x384/0xa30 [14742.144017] schedule+0x33/0xe0 [14742.144352] rwsem_down_write_slowpath+0x2c2/0x750 [14742.144859] ? btrfs_sync_file+0x1fe/0x4d0 [btrfs] [14742.145386] btrfs_sync_file+0x1fe/0x4d0 [btrfs] [14742.145863] iomap_dio_complete+0x11b/0x260 [14742.146289] ? aio_fsync_work+0x5b0/0x5b0 [14742.146701] iomap_dio_complete_work+0x17/0x30 [14742.147168] process_one_work+0x275/0x6b0 [14742.147579] worker_thread+0x4f/0x3e0 [14742.147954] ? process_one_work+0x6b0/0x6b0 [14742.148377] kthread+0x12a/0x170 [14742.148722] ? kthread_create_worker_on_cpu+0x70/0x70 [14742.149257] ret_from_fork+0x3a/0x50 [14742.149671] INFO: task aio-stress:16274 blocked for more than 241 seconds. [14742.150376] Not tainted 5.7.0-rc7-btrfs-next-59 #1 [14742.150948] "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message. [14742.151962] aio-stress D 0 16274 14855 0x00004000
Quoted 2 lines
(...)
Seems like the btrfs_inode->dio_sem. Would you have more information on which process is holding on to it, or if there was a failure?
I will try to reproduce at my end. Thanks for testing.
Signature · 1 line
Goldwyn
Re: [PATCH 4/7] btrfs: Switch to iomap_dio_rw() for dio
Quoted 217 lines · Goldwyn Rodrigues
Quoted 212 lines · Filipe Manana
Quoted 78 lines · Filipe Manana
Quoted 59 lines · Goldwyn Rodrigues
Quoted 10 lines · Filipe Manana
Quoted 3 lines · Goldwyn Rodrigues
Quoted 1 line
And who locked the extent range before?
This is usually locked by a previous buffered write or read.
A previous buffered write/read that has already finished or is still in progress?
Because if it has finished we're not supposed to have the file range locked anymore.
In progress. Mixing buffered I/O with direct writes.
Quoted 18 lines
Quoted 10 lines
Quoted 9 lines
That seems alarming to me, specially if it's a direct IO write failing to invalidate the page cache, since a subsequent buffered read could get stale data (what's in the page cache), and not what the direct IO write wrote.
Can you elaborate more on all those details?
Quoted 7 lines
The origin of the message is when
iomap_dio_rw()tries to invalidate the inode pages, but fails and callsdio_warn_stale_pagecache().In the vanilla code,
generic_file_direct_write()aborts direct writes and returns 0 so that it may fallback to buffered I/O. Perhaps this should be changed iniomap_dio_rw()as well. I will write a patch to accomodate that.Quoted 5 lines
On vanilla we have no problems of mixing buffered and direct operations as long as they are done sequentially at least. And even if done concurrently we take several measures to ensure that are no surprises (locking ranges, waiting for any ordered extents in progress, etc).
Yes, it is because of the code in
generic_file_direct_write(). Anyways, I did some tests with the following patch, and it seems to work. I will send a formal patch to so that it gets incorporated in iomap sequence as well.fs/iomap/direct-io.c +2
-3@@ -483,9 +483,15 @@ iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter,*/ ret =invalidate_inode_pages2_range (mapping, pos >>PAGE_SHIFT , end >>PAGE_SHIFT ); -if (ret) -dio_warn_stale_pagecache (iocb->ki_filp); - ret =0 ; +/* +* If a page can not be invalidated, return 0 to fall back fs/iomap/direct-io.c iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter, · line 497
Quoted 10 lines
fs/iomap/direct-io.c +7
-0+* to buffered write. +*/ +if (ret) { +if (ret == -EBUSY ) + ret =0 ; + goto out_free_dio; + }if (iov_iter_rw (iter) ==WRITE && !wait_for_completion && !inode->i_sb->s_dio_done_wq) {Thanks. As I just replied on another thread for that patch, we actually have a regression.
There's more than the annoying warning in dmesg, it also sets-EIOon the inode's mapping and makes future fsyncs return that error despite the fact that no actual errors or corruptions happened:Quoted 2 lines
There's also some deadlock/hang, I have triggered it twice today with generic/113 on two different VMs:
[14621.297370] INFO: task kworker/1:117:15962 blocked for more than 120 seconds. [14621.298491] Not tainted 5.7.0-rc7-btrfs-next-59 #1 [14621.299231] "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message. [14621.300523] kworker/1:117 D 0 15962 2 0x80004000 [14621.301558] Workqueue: dio/sdb iomap_dio_complete_work [14621.302389] Call Trace: [14621.302877] __schedule+0x384/0xa30 [14621.303555] schedule+0x33/0xe0 [14621.304167] rwsem_down_write_slowpath+0x2c2/0x750 [14621.305121] ? btrfs_sync_file+0x1fe/0x4d0 [btrfs] [14621.306217] btrfs_sync_file+0x1fe/0x4d0 [btrfs] [14621.307113] iomap_dio_complete+0x11b/0x260 [14621.307888] ? aio_fsync_work+0x5b0/0x5b0 [14621.308585] iomap_dio_complete_work+0x17/0x30 [14621.309476] process_one_work+0x275/0x6b0 [14621.310275] worker_thread+0x4f/0x3e0 [14621.310869] ? process_one_work+0x6b0/0x6b0 [14621.311403] kthread+0x12a/0x170 [14621.311819] ? kthread_create_worker_on_cpu+0x70/0x70 [14621.312460] ret_from_fork+0x3a/0x50 [14621.312983] INFO: task kworker/1:199:16063 blocked for more than 120 seconds. [14621.313921] Not tainted 5.7.0-rc7-btrfs-next-59 #1 [14621.314680] "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message. [14621.315724] kworker/1:199 D 0 16063 2 0x80004000 [14621.316445] Workqueue: dio/sdb iomap_dio_complete_work [14621.317101] Call Trace: [14621.317437] __schedule+0x384/0xa30 [14621.317928] schedule+0x33/0xe0 [14621.318339] rwsem_down_write_slowpath+0x2c2/0x750 [14621.318981] ? btrfs_sync_file+0x1fe/0x4d0 [btrfs] [14621.319609] btrfs_sync_file+0x1fe/0x4d0 [btrfs] [14621.320203] iomap_dio_complete+0x11b/0x260 [14621.320721] ? aio_fsync_work+0x5b0/0x5b0 [14621.321249] iomap_dio_complete_work+0x17/0x30 [14621.321844] process_one_work+0x275/0x6b0 [14621.322376] worker_thread+0x4f/0x3e0 [14621.322871] ? process_one_work+0x6b0/0x6b0 [14621.323408] kthread+0x12a/0x170 [14621.323827] ? kthread_create_worker_on_cpu+0x70/0x70 [14621.324473] ret_from_fork+0x3a/0x50 [14621.324983] INFO: task aio-stress:16274 blocked for more than 120 seconds. [14621.325896] Not tainted 5.7.0-rc7-btrfs-next-59 #1 [14621.326579] "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message. [14621.327580] aio-stress D 0 16274 14855 0x00004000 [14621.328280] Call Trace: [14621.328602] __schedule+0x384/0xa30 [14621.329056] schedule+0x33/0xe0 [14621.329478] rwsem_down_write_slowpath+0x2c2/0x750 [14621.330118] ? btrfs_sync_file+0x219/0x4d0 [btrfs] [14621.330747] btrfs_sync_file+0x219/0x4d0 [btrfs] [14621.331346] iomap_dio_complete+0x11b/0x260 [14621.331886] iomap_dio_rw+0x3bc/0x4c0 [14621.332372] ? btrfs_file_write_iter+0x645/0x870 [btrfs] [14621.333076] btrfs_file_write_iter+0x645/0x870 [btrfs] [14621.333749] aio_write+0x148/0x1d0 [14621.334196] ? lock_acquire+0xb1/0x4a0 [14621.334682] ? __might_fault+0x3e/0x90 [14621.335172] ? __fget_files+0x132/0x270 [14621.335668] ? io_submit_one+0x946/0x1630 [14621.336184] io_submit_one+0x946/0x1630 [14621.336680] ? lock_acquire+0xb1/0x4a0 [14621.337175] ? __might_fault+0x3e/0x90 [14621.337707] ? __x64_sys_io_submit+0x9c/0x330 [14621.338269] __x64_sys_io_submit+0x9c/0x330 [14621.338812] ? do_syscall_64+0x5c/0x280 [14621.339303] do_syscall_64+0x5c/0x280 [14621.339774] entry_SYSCALL_64_after_hwframe+0x49/0xb3 [14621.340416] RIP: 0033:0x7fb6cd395717 [14621.340875] Code: Bad RIP value. [14621.341304] RSP: 002b:00007fb6bf7e1de8 EFLAGS: 00000202 ORIG_RAX: 00000000000000d1 [14621.342262] RAX: ffffffffffffffda RBX: 0000560d3d92ea60 RCX: 00007fb6cd395717 [14621.343180] RDX: 0000560d3d92ea60 RSI: 0000000000000008 RDI: 00007fb6cdb32000 [14621.344081] RBP: 0000000000000008 R08: 0000150e50ac6651 R09: 00000000003081a8 [14621.344981] R10: 00007fb6bf7e1df0 R11: 0000000000000202 R12: 0000560d3d8fe110 [14621.345897] R13: 00007fb6bf7e1e10 R14: 00007fb6bf7e1e00 R15: 0000560d3d8fe110 [14621.346820] INFO: lockdep is turned off. [14742.125500] INFO: task kworker/1:117:15962 blocked for more than 241 seconds. [14742.126456] Not tainted 5.7.0-rc7-btrfs-next-59 #1 [14742.127156] "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message. [14742.128156] kworker/1:117 D 0 15962 2 0x80004000 [14742.128875] Workqueue: dio/sdb iomap_dio_complete_work [14742.129633] Call Trace: [14742.130010] __schedule+0x384/0xa30 [14742.130494] schedule+0x33/0xe0 [14742.131068] rwsem_down_write_slowpath+0x2c2/0x750 [14742.131956] ? btrfs_sync_file+0x1fe/0x4d0 [btrfs] [14742.132834] btrfs_sync_file+0x1fe/0x4d0 [btrfs] [14742.133712] iomap_dio_complete+0x11b/0x260 [14742.134475] ? aio_fsync_work+0x5b0/0x5b0 [14742.135205] iomap_dio_complete_work+0x17/0x30 [14742.136018] process_one_work+0x275/0x6b0 [14742.136677] worker_thread+0x4f/0x3e0 [14742.137154] ? process_one_work+0x6b0/0x6b0 [14742.137805] kthread+0x12a/0x170 [14742.138236] ? kthread_create_worker_on_cpu+0x70/0x70 [14742.138901] ret_from_fork+0x3a/0x50 [14742.139389] INFO: task kworker/1:199:16063 blocked for more than 241 seconds. [14742.140305] Not tainted 5.7.0-rc7-btrfs-next-59 #1 [14742.140998] "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message. [14742.142056] kworker/1:199 D 0 16063 2 0x80004000 [14742.142877] Workqueue: dio/sdb iomap_dio_complete_work [14742.143397] Call Trace: [14742.143654] __schedule+0x384/0xa30 [14742.144017] schedule+0x33/0xe0 [14742.144352] rwsem_down_write_slowpath+0x2c2/0x750 [14742.144859] ? btrfs_sync_file+0x1fe/0x4d0 [btrfs] [14742.145386] btrfs_sync_file+0x1fe/0x4d0 [btrfs] [14742.145863] iomap_dio_complete+0x11b/0x260 [14742.146289] ? aio_fsync_work+0x5b0/0x5b0 [14742.146701] iomap_dio_complete_work+0x17/0x30 [14742.147168] process_one_work+0x275/0x6b0 [14742.147579] worker_thread+0x4f/0x3e0 [14742.147954] ? process_one_work+0x6b0/0x6b0 [14742.148377] kthread+0x12a/0x170 [14742.148722] ? kthread_create_worker_on_cpu+0x70/0x70 [14742.149257] ret_from_fork+0x3a/0x50 [14742.149671] INFO: task aio-stress:16274 blocked for more than 241 seconds. [14742.150376] Not tainted 5.7.0-rc7-btrfs-next-59 #1 [14742.150948] "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message. [14742.151962] aio-stress D 0 16274 14855 0x00004000Quoted 2 lines
(...)
Quoted 2 lines
Seems like the
btrfs_inode->dio_sem. Would you have more information on which process is holding on to it, or if there was a failure?
This happens 100% of the time.
At btrfs_direct_write():
down_read(&BTRFS_I(inode)->dio_sem);
written = iomap_dio_rw(iocb, from, &btrfs_dio_iomap_ops, &btrfs_dops,
is_sync_kiocb(iocb));
up_read(&BTRFS_I(inode)->dio_sem);
than through iomap_dio_rw(), we end up calling btrfs_sync_file(), which tries to down_write() the dio_sem.
Quoted 2 lines
I will try to reproduce at my end. Thanks for testing.
You should have no difficulty reproducing it.
And another lockdep warning:
[ 422.202844] ============================================
[ 422.204113] WARNING: possible recursive locking detected
[ 422.205014] 5.7.0-rc7-btrfs-next-59 #1 Not tainted
[ 422.205722] --------------------------------------------
[ 422.206598] aio-stress/1665 is trying to acquire lock:
[ 422.207776] ffff8fbc9a24d620
(&sb->s_type->i_mutex_key#14){++++}-{3:3}, at:
btrfs_sync_file+0x1fe/0x4d0 [btrfs]
[ 422.209538]
but task is already holding lock:
[ 422.210424] ffff8fbc9a24d620
(&sb->s_type->i_mutex_key#14){++++}-{3:3}, at:
btrfs_file_write_iter+0x80/0x870 [btrfs]
[ 422.212075]
other info that might help us debug this:
[ 422.213089] Possible unsafe locking scenario:[ 422.214141] CPU0
[ 422.214578] ----
[ 422.215098] lock(&sb->s_type->i_mutex_key#14);
[ 422.215990] lock(&sb->s_type->i_mutex_key#14);
[ 422.216940]
*** DEADLOCK ***[ 422.218115] May be due to missing lock nesting notation
[ 422.219060] 2 locks held by aio-stress/1665:
[ 422.219815] #0: ffff8fbc9a24d620
(&sb->s_type->i_mutex_key#14){++++}-{3:3}, at:
btrfs_file_write_iter+0x80/0x870 [btrfs]
[ 422.221516] #1: ffff8fbc9a24d4a8 (&ei->dio_sem){++++}-{3:3}, at:
btrfs_file_write_iter+0x6b4/0x870 [btrfs]
[ 422.223437]
stack backtrace:
[ 422.224335] CPU: 0 PID: 1665 Comm: aio-stress Not tainted
5.7.0-rc7-btrfs-next-59 #1
[ 422.225960] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996),
BIOS rel-1.12.0-59-gc9ba5276e321-prebuilt.qemu.org 04/01/2014
[ 422.227728] Call Trace:
[ 422.228046] dump_stack+0x87/0xcb
[ 422.228667] __lock_acquire+0x17d0/0x21a0
[ 422.229545] lock_acquire+0xb1/0x4a0
[ 422.230272] ? btrfs_sync_file+0x1fe/0x4d0 [btrfs]
[ 422.231250] down_write+0x38/0x70
[ 422.231821] ? btrfs_sync_file+0x1fe/0x4d0 [btrfs]
[ 422.232502] btrfs_sync_file+0x1fe/0x4d0 [btrfs]
[ 422.233169] iomap_dio_complete+0x11b/0x260
[ 422.233838] iomap_dio_rw+0x3bc/0x4c0
[ 422.234404] ? btrfs_file_write_iter+0x6d9/0x870 [btrfs]
[ 422.235311] btrfs_file_write_iter+0x6d9/0x870 [btrfs]
[ 422.236250] aio_write+0x148/0x1d0
[ 422.236872] ? lock_acquire+0xb1/0x4a0
[ 422.237560] ? __might_fault+0x3e/0x90
[ 422.238291] ? __might_fault+0x3e/0x90
[ 422.239002] ? io_submit_one+0x946/0x1630
[ 422.239874] io_submit_one+0x946/0x1630
[ 422.240565] ? lock_acquire+0xb1/0x4a0
[ 422.241162] ? __might_fault+0x3e/0x90
[ 422.241711] ? __x64_sys_io_submit+0x9c/0x330
[ 422.242336] __x64_sys_io_submit+0x9c/0x330
[ 422.242943] ? do_syscall_64+0x5c/0x280
[ 422.243420] do_syscall_64+0x5c/0x280
[ 422.243878] entry_SYSCALL_64_after_hwframe+0x49/0xb3
[ 422.244626] RIP: 0033:0x7f77e38aa717
[ 422.245219] Code: 00 75 08 8b 47 0c 39 47 08 74 08 e9 c3 ff ff ff
0f 1f 00 31 c0 c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 00 b8 d1 00 00
00 0f 05 <c3> 0f 1f 84 00 00 00 00 00 b8 d2 00 00 00 0f 05 c3 0f 1f 84
00 00
[ 422.247827] RSP: 002b:00007f77d6cf8de8 EFLAGS: 00000202 ORIG_RAX:
00000000000000d1
[ 422.248924] RAX: ffffffffffffffda RBX: 000055c78674c400 RCX: 00007f77e38aa717
[ 422.249959] RDX: 000055c78674c400 RSI: 0000000000000008 RDI: 00007f77e4059000
[ 422.250924] RBP: 0000000000000008 R08: 000000a0afa4d2c9 R09: 0000000000009e34
[ 422.251958] R10: 00007f77d6cf8df0 R11: 0000000000000202 R12: 000055c786720f10
[ 422.252989] R13: 00007f77d6cf8e10 R14: 00007f77d6cf8e00 R15: 000055c786720f10Thanks.
Quoted 3 lines
--
Goldwyn
Signature · 3 lines
Filipe David Manana, “Whether you think you can, or you think you can't — you're right.”
Re: [PATCH 4/7] btrfs: Switch to iomap_dio_rw() for dio
Quoted 225 lines · Filipe Manana
Quoted 217 lines · Goldwyn Rodrigues
Quoted 212 lines · Filipe Manana
Quoted 78 lines · Filipe Manana
Quoted 59 lines · Goldwyn Rodrigues
Quoted 10 lines · Filipe Manana
Quoted 3 lines · Goldwyn Rodrigues
Quoted 1 line
And who locked the extent range before?
This is usually locked by a previous buffered write or read.
A previous buffered write/read that has already finished or is still in progress?
Because if it has finished we're not supposed to have the file range locked anymore.
In progress. Mixing buffered I/O with direct writes.
Quoted 18 lines
Quoted 10 lines
Quoted 9 lines
That seems alarming to me, specially if it's a direct IO write failing to invalidate the page cache, since a subsequent buffered read could get stale data (what's in the page cache), and not what the direct IO write wrote.
Can you elaborate more on all those details?
Quoted 7 lines
The origin of the message is when
iomap_dio_rw()tries to invalidate the inode pages, but fails and callsdio_warn_stale_pagecache().In the vanilla code,
generic_file_direct_write()aborts direct writes and returns 0 so that it may fallback to buffered I/O. Perhaps this should be changed iniomap_dio_rw()as well. I will write a patch to accomodate that.Quoted 5 lines
On vanilla we have no problems of mixing buffered and direct operations as long as they are done sequentially at least. And even if done concurrently we take several measures to ensure that are no surprises (locking ranges, waiting for any ordered extents in progress, etc).
Yes, it is because of the code in
generic_file_direct_write(). Anyways, I did some tests with the following patch, and it seems to work. I will send a formal patch to so that it gets incorporated in iomap sequence as well.fs/iomap/direct-io.c +2
-3@@ -483,9 +483,15 @@ iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter,*/ ret =invalidate_inode_pages2_range (mapping, pos >>PAGE_SHIFT , end >>PAGE_SHIFT ); -if (ret) -dio_warn_stale_pagecache (iocb->ki_filp); - ret =0 ; +/* +* If a page can not be invalidated, return 0 to fall back fs/iomap/direct-io.c iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter, · line 497
Quoted 10 lines
fs/iomap/direct-io.c +7
-0+* to buffered write. +*/ +if (ret) { +if (ret == -EBUSY ) + ret =0 ; + goto out_free_dio; + }if (iov_iter_rw (iter) ==WRITE && !wait_for_completion && !inode->i_sb->s_dio_done_wq) {Thanks. As I just replied on another thread for that patch, we actually have a regression.
There's more than the annoying warning in dmesg, it also sets-EIOon the inode's mapping and makes future fsyncs return that error despite the fact that no actual errors or corruptions happened:Quoted 2 lines
There's also some deadlock/hang, I have triggered it twice today with generic/113 on two different VMs:
[14621.297370] INFO: task kworker/1:117:15962 blocked for more than 120 seconds. [14621.298491] Not tainted 5.7.0-rc7-btrfs-next-59 #1 [14621.299231] "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message. [14621.300523] kworker/1:117 D 0 15962 2 0x80004000 [14621.301558] Workqueue: dio/sdb iomap_dio_complete_work [14621.302389] Call Trace: [14621.302877] __schedule+0x384/0xa30 [14621.303555] schedule+0x33/0xe0 [14621.304167] rwsem_down_write_slowpath+0x2c2/0x750 [14621.305121] ? btrfs_sync_file+0x1fe/0x4d0 [btrfs] [14621.306217] btrfs_sync_file+0x1fe/0x4d0 [btrfs] [14621.307113] iomap_dio_complete+0x11b/0x260 [14621.307888] ? aio_fsync_work+0x5b0/0x5b0 [14621.308585] iomap_dio_complete_work+0x17/0x30 [14621.309476] process_one_work+0x275/0x6b0 [14621.310275] worker_thread+0x4f/0x3e0 [14621.310869] ? process_one_work+0x6b0/0x6b0 [14621.311403] kthread+0x12a/0x170 [14621.311819] ? kthread_create_worker_on_cpu+0x70/0x70 [14621.312460] ret_from_fork+0x3a/0x50 [14621.312983] INFO: task kworker/1:199:16063 blocked for more than 120 seconds. [14621.313921] Not tainted 5.7.0-rc7-btrfs-next-59 #1 [14621.314680] "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message. [14621.315724] kworker/1:199 D 0 16063 2 0x80004000 [14621.316445] Workqueue: dio/sdb iomap_dio_complete_work [14621.317101] Call Trace: [14621.317437] __schedule+0x384/0xa30 [14621.317928] schedule+0x33/0xe0 [14621.318339] rwsem_down_write_slowpath+0x2c2/0x750 [14621.318981] ? btrfs_sync_file+0x1fe/0x4d0 [btrfs] [14621.319609] btrfs_sync_file+0x1fe/0x4d0 [btrfs] [14621.320203] iomap_dio_complete+0x11b/0x260 [14621.320721] ? aio_fsync_work+0x5b0/0x5b0 [14621.321249] iomap_dio_complete_work+0x17/0x30 [14621.321844] process_one_work+0x275/0x6b0 [14621.322376] worker_thread+0x4f/0x3e0 [14621.322871] ? process_one_work+0x6b0/0x6b0 [14621.323408] kthread+0x12a/0x170 [14621.323827] ? kthread_create_worker_on_cpu+0x70/0x70 [14621.324473] ret_from_fork+0x3a/0x50 [14621.324983] INFO: task aio-stress:16274 blocked for more than 120 seconds. [14621.325896] Not tainted 5.7.0-rc7-btrfs-next-59 #1 [14621.326579] "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message. [14621.327580] aio-stress D 0 16274 14855 0x00004000 [14621.328280] Call Trace: [14621.328602] __schedule+0x384/0xa30 [14621.329056] schedule+0x33/0xe0 [14621.329478] rwsem_down_write_slowpath+0x2c2/0x750 [14621.330118] ? btrfs_sync_file+0x219/0x4d0 [btrfs] [14621.330747] btrfs_sync_file+0x219/0x4d0 [btrfs] [14621.331346] iomap_dio_complete+0x11b/0x260 [14621.331886] iomap_dio_rw+0x3bc/0x4c0 [14621.332372] ? btrfs_file_write_iter+0x645/0x870 [btrfs] [14621.333076] btrfs_file_write_iter+0x645/0x870 [btrfs] [14621.333749] aio_write+0x148/0x1d0 [14621.334196] ? lock_acquire+0xb1/0x4a0 [14621.334682] ? __might_fault+0x3e/0x90 [14621.335172] ? __fget_files+0x132/0x270 [14621.335668] ? io_submit_one+0x946/0x1630 [14621.336184] io_submit_one+0x946/0x1630 [14621.336680] ? lock_acquire+0xb1/0x4a0 [14621.337175] ? __might_fault+0x3e/0x90 [14621.337707] ? __x64_sys_io_submit+0x9c/0x330 [14621.338269] __x64_sys_io_submit+0x9c/0x330 [14621.338812] ? do_syscall_64+0x5c/0x280 [14621.339303] do_syscall_64+0x5c/0x280 [14621.339774] entry_SYSCALL_64_after_hwframe+0x49/0xb3 [14621.340416] RIP: 0033:0x7fb6cd395717 [14621.340875] Code: Bad RIP value. [14621.341304] RSP: 002b:00007fb6bf7e1de8 EFLAGS: 00000202 ORIG_RAX: 00000000000000d1 [14621.342262] RAX: ffffffffffffffda RBX: 0000560d3d92ea60 RCX: 00007fb6cd395717 [14621.343180] RDX: 0000560d3d92ea60 RSI: 0000000000000008 RDI: 00007fb6cdb32000 [14621.344081] RBP: 0000000000000008 R08: 0000150e50ac6651 R09: 00000000003081a8 [14621.344981] R10: 00007fb6bf7e1df0 R11: 0000000000000202 R12: 0000560d3d8fe110 [14621.345897] R13: 00007fb6bf7e1e10 R14: 00007fb6bf7e1e00 R15: 0000560d3d8fe110 [14621.346820] INFO: lockdep is turned off. [14742.125500] INFO: task kworker/1:117:15962 blocked for more than 241 seconds. [14742.126456] Not tainted 5.7.0-rc7-btrfs-next-59 #1 [14742.127156] "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message. [14742.128156] kworker/1:117 D 0 15962 2 0x80004000 [14742.128875] Workqueue: dio/sdb iomap_dio_complete_work [14742.129633] Call Trace: [14742.130010] __schedule+0x384/0xa30 [14742.130494] schedule+0x33/0xe0 [14742.131068] rwsem_down_write_slowpath+0x2c2/0x750 [14742.131956] ? btrfs_sync_file+0x1fe/0x4d0 [btrfs] [14742.132834] btrfs_sync_file+0x1fe/0x4d0 [btrfs] [14742.133712] iomap_dio_complete+0x11b/0x260 [14742.134475] ? aio_fsync_work+0x5b0/0x5b0 [14742.135205] iomap_dio_complete_work+0x17/0x30 [14742.136018] process_one_work+0x275/0x6b0 [14742.136677] worker_thread+0x4f/0x3e0 [14742.137154] ? process_one_work+0x6b0/0x6b0 [14742.137805] kthread+0x12a/0x170 [14742.138236] ? kthread_create_worker_on_cpu+0x70/0x70 [14742.138901] ret_from_fork+0x3a/0x50 [14742.139389] INFO: task kworker/1:199:16063 blocked for more than 241 seconds. [14742.140305] Not tainted 5.7.0-rc7-btrfs-next-59 #1 [14742.140998] "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message. [14742.142056] kworker/1:199 D 0 16063 2 0x80004000 [14742.142877] Workqueue: dio/sdb iomap_dio_complete_work [14742.143397] Call Trace: [14742.143654] __schedule+0x384/0xa30 [14742.144017] schedule+0x33/0xe0 [14742.144352] rwsem_down_write_slowpath+0x2c2/0x750 [14742.144859] ? btrfs_sync_file+0x1fe/0x4d0 [btrfs] [14742.145386] btrfs_sync_file+0x1fe/0x4d0 [btrfs] [14742.145863] iomap_dio_complete+0x11b/0x260 [14742.146289] ? aio_fsync_work+0x5b0/0x5b0 [14742.146701] iomap_dio_complete_work+0x17/0x30 [14742.147168] process_one_work+0x275/0x6b0 [14742.147579] worker_thread+0x4f/0x3e0 [14742.147954] ? process_one_work+0x6b0/0x6b0 [14742.148377] kthread+0x12a/0x170 [14742.148722] ? kthread_create_worker_on_cpu+0x70/0x70 [14742.149257] ret_from_fork+0x3a/0x50 [14742.149671] INFO: task aio-stress:16274 blocked for more than 241 seconds. [14742.150376] Not tainted 5.7.0-rc7-btrfs-next-59 #1 [14742.150948] "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message. [14742.151962] aio-stress D 0 16274 14855 0x00004000Quoted 2 lines
(...)
Quoted 2 lines
Seems like the
btrfs_inode->dio_sem. Would you have more information on which process is holding on to it, or if there was a failure?This happens 100% of the time.
At
btrfs_direct_write():
Quoted 7 lines
down_read(&BTRFS_I(inode)->dio_sem);
written = iomap_dio_rw(iocb, from,&btrfs_dio_iomap_ops,&btrfs_dops,is_sync_kiocb(iocb));up_read(&BTRFS_I(inode)->dio_sem);
than through
iomap_dio_rw(), we end up callingbtrfs_sync_file(), which tries todown_write()thedio_sem.
I see what is happening in the code. Also, we have generic_write_sync() called twice. I will work on this. Surprisingly generic/113 works just fine for me.
Thanks,
Signature · 1 line
Goldwyn
PATCH v8 5/7 fs: Remove dio_end_io()
In reply to Goldwyn RodriguesFrom: Goldwyn Rodrigues <[email protected]>
Since we removed the last user of dio_end_io(), remove the helper function dio_end_io().
--- fs/direct-io.c | 19 ------------------- include/linux/fs.h | 2 -- 2 files changed, 21 deletions(-)
fs/direct-io.c +0 -19
@@ -386,25 +386,6 @@ static void dio_bio_end_io(struct bio *bio)spin_unlock_irqrestore (&dio->bio_lock, flags); } -/** -* dio_end_io - handle the end io action for the given bio -* @bio: The direct io bio thats being completed -* -* This is meant to be called by any filesystem that uses their own dio_submit_t -* so that the DIO specific endio actions are dealt with after the filesystem -* has done it's completion work. -*/ -void dio_end_io (struct bio *bio) -{ -struct dio *dio = bio->bi_private; - -if (dio->is_async) -dio_bio_end_aio (bio); -else -dio_bio_end_io (bio); -} -EXPORT_SYMBOL_GPL (dio_end_io); - static inline void dio_bio_alloc(struct dio *dio, struct dio_submit *sdio, struct block_device *bdev,
include/linux/fs.h +0 -2
@@ -3187,8 +3187,6 @@ enum { DIO_SKIP_HOLES = 0x02, }; -void dio_end_io (struct bio *bio); - ssize_t __blockdev_direct_IO(struct kiocb *iocb, struct inode *inode, struct block_device *bdev, struct iov_iter *iter, get_block_t get_block,
Signature · 1 line
2.25.0
PATCH v8 6/7 btrfs: remove BTRFS_INODE_READDIO_NEED_LOCK
In reply to Goldwyn RodriguesFrom: Goldwyn Rodrigues <[email protected]>
Since we now perform direct reads using i_rwsem, we can remove this inode flag used to co-ordinate unlocked reads.
The truncate call takes i_rwsem. This means it is correctly synchronized with concurrent direct reads.
--- fs/btrfs/btrfs_inode.h | 18 ------------------ fs/btrfs/inode.c | 3 --- 2 files changed, 21 deletions(-)
fs/btrfs/btrfs_inode.h +0 -18
@@ -28,7 +28,6 @@ enum {BTRFS_INODE_NEEDS_FULL_SYNC ,BTRFS_INODE_COPY_EVERYTHING ,BTRFS_INODE_IN_DELALLOC_LIST , -BTRFS_INODE_READDIO_NEED_LOCK ,BTRFS_INODE_HAS_PROPS , BTRFS_INODE_SNAPSHOT_FLUSH, };
@@ -313,23 +312,6 @@ struct btrfs_dio_private {u8 csums[]; }; -/* -* Disable DIO read nolock optimization, so new dio readers will be forced -* to grab i_mutex. It is used to avoid the endless truncate due to -* nonlocked dio read. -*/ -static inline void btrfs_inode_block_unlocked_dio (struct btrfs_inode *inode) -{ -set_bit (BTRFS_INODE_READDIO_NEED_LOCK , &inode->runtime_flags); -smp_mb (); -} - -static inline void btrfs_inode_resume_unlocked_dio (struct btrfs_inode *inode) -{ -smp_mb__before_atomic (); -clear_bit (BTRFS_INODE_READDIO_NEED_LOCK , &inode->runtime_flags); -} -/* Array of bytes with variable length, hexadecimal format 0x1234 */ #define CSUM_FMT "0x%*phN"#define CSUM_FMT_VALUE (size, bytes) size, bytes
fs/btrfs/inode.c +0 -3
@@ -4752,10 +4752,7 @@ static int btrfs_setsize(struct inode *inode, struct iattr *attr)truncate_setsize (inode, newsize); -/* Disable nonlocked read DIO to avoid the endless truncate */ -btrfs_inode_block_unlocked_dio (BTRFS_I (inode));inode_dio_wait (inode); -btrfs_inode_resume_unlocked_dio (BTRFS_I (inode)); ret =btrfs_truncate (inode, newsize == oldsize);if (ret && inode->i_nlink) {
Signature · 1 line
2.25.0
PATCH v8 7/7 btrfs: btrfs: split btrfs_direct_IO
In reply to Goldwyn RodriguesFrom: Christoph Hellwig <[email protected]>
The read and write versions don't have anything in common except for the call to iomap_dio_rw. So split this function, and merge each half into its only caller.
--- fs/btrfs/ctree.h | 3 ++ fs/btrfs/file.c | 88 ++++++++++++++++++++++++++++++++++++++++++------ fs/btrfs/inode.c | 83 ++------------------------------------------- 3 files changed, 83 insertions(+), 91 deletions(-)
fs/btrfs/ctree.h +3 -0
@@ -28,6 +28,7 @@#include <linux/dynamic_debug.h> #include <linux/refcount.h> #include <linux/crc32c.h> +#include <linux/iomap.h> #include "extent-io-tree.h" #include "extent_io.h" #include "extent_map.h"
@@ -2912,6 +2913,8 @@ void btrfs_writepage_endio_finish_ordered(struct page *page, u64 start, u64 end, int uptodate);extern const struct dentry_operations btrfs_dentry_operations;ssize_t btrfs_direct_IO (struct kiocb *iocb,struct iov_iter *iter); +extern const struct iomap_ops btrfs_dio_iomap_ops; +extern const struct iomap_dio_ops btrfs_dops;/* ioctl.c */ long btrfs_ioctl (struct file *file,unsigned int cmd,unsigned long arg);
fs/btrfs/file.c +78 -10
122 lines not on this page · raw message
fs/btrfs/inode.c +2 -81
102 lines not on this page · raw message
Signature · 1 line
2.25.0