* [PATCH v20 05/32] splice: Make splice from a DAX file use direct_splice_read()
[not found] <20230519074047.1739879-1-dhowells@redhat.com>
@ 2023-05-19 7:40 ` David Howells
2023-05-19 8:10 ` Christoph Hellwig
2023-05-19 7:40 ` [PATCH v20 21/32] xfs: Provide a splice-read stub David Howells
2023-05-19 7:40 ` [PATCH v20 22/32] zonefs: " David Howells
2 siblings, 1 reply; 5+ messages in thread
From: David Howells @ 2023-05-19 7:40 UTC (permalink / raw)
To: Jens Axboe, Al Viro, Christoph Hellwig
Cc: David Howells, Matthew Wilcox, Jan Kara, Jeff Layton,
David Hildenbrand, Jason Gunthorpe, Logan Gunthorpe, Hillf Danton,
Christian Brauner, Linus Torvalds, linux-fsdevel, linux-block,
linux-kernel, linux-mm, Christoph Hellwig, linux-erofs,
linux-ext4, linux-xfs
Make a read splice from a DAX file go directly to direct_splice_read() to
do the reading as filemap_splice_read() is unlikely to find any pagecache
to splice.
I think this affects only erofs, Ext2, Ext4, fuse and XFS.
Signed-off-by: David Howells <dhowells@redhat.com>
cc: Christoph Hellwig <hch@lst.de>
cc: Al Viro <viro@zeniv.linux.org.uk>
cc: Jens Axboe <axboe@kernel.dk>
cc: linux-erofs@lists.ozlabs.org
cc: linux-ext4@vger.kernel.org
cc: linux-fsdevel@vger.kernel.org
cc: linux-xfs@vger.kernel.org
cc: linux-fsdevel@vger.kernel.org
cc: linux-block@vger.kernel.org
cc: linux-mm@kvack.org
---
fs/splice.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/fs/splice.c b/fs/splice.c
index 1e0b7c7038b5..7b818b5b18d4 100644
--- a/fs/splice.c
+++ b/fs/splice.c
@@ -421,6 +421,11 @@ ssize_t generic_file_splice_read(struct file *in, loff_t *ppos,
struct kiocb kiocb;
int ret;
+#ifdef CONFIG_FS_DAX
+ if (IS_DAX(in->f_mapping->host))
+ return direct_splice_read(in, ppos, pipe, len, flags);
+#endif
+
iov_iter_pipe(&to, ITER_DEST, pipe, len);
init_sync_kiocb(&kiocb, in);
kiocb.ki_pos = *ppos;
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v20 21/32] xfs: Provide a splice-read stub
[not found] <20230519074047.1739879-1-dhowells@redhat.com>
2023-05-19 7:40 ` [PATCH v20 05/32] splice: Make splice from a DAX file use direct_splice_read() David Howells
@ 2023-05-19 7:40 ` David Howells
2023-05-19 7:40 ` [PATCH v20 22/32] zonefs: " David Howells
2 siblings, 0 replies; 5+ messages in thread
From: David Howells @ 2023-05-19 7:40 UTC (permalink / raw)
To: Jens Axboe, Al Viro, Christoph Hellwig
Cc: David Howells, Matthew Wilcox, Jan Kara, Jeff Layton,
David Hildenbrand, Jason Gunthorpe, Logan Gunthorpe, Hillf Danton,
Christian Brauner, Linus Torvalds, linux-fsdevel, linux-block,
linux-kernel, linux-mm, Christoph Hellwig, Darrick J . Wong,
linux-xfs
Provide a splice_read stub for XFS. This does a stat count and a shutdown
check before proceeding. For buffered I/O, it emits a new trace line and
locks the inode across the call to filemap_splice_read() and adds to the
stats afterwards. Splicing from DAX files either copies the data into a
buffer (DIO) or splices from the pagecache.
Signed-off-by: David Howells <dhowells@redhat.com>
cc: Christoph Hellwig <hch@lst.de>
cc: Al Viro <viro@zeniv.linux.org.uk>
cc: Jens Axboe <axboe@kernel.dk>
cc: Darrick J. Wong <djwong@kernel.org>
cc: linux-xfs@vger.kernel.org
cc: linux-fsdevel@vger.kernel.org
cc: linux-block@vger.kernel.org
cc: linux-mm@kvack.org
---
fs/xfs/xfs_file.c | 33 ++++++++++++++++++++++++++++++++-
fs/xfs/xfs_trace.h | 2 +-
2 files changed, 33 insertions(+), 2 deletions(-)
diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c
index aede746541f8..bb1ec755a709 100644
--- a/fs/xfs/xfs_file.c
+++ b/fs/xfs/xfs_file.c
@@ -306,6 +306,37 @@ xfs_file_read_iter(
return ret;
}
+STATIC ssize_t
+xfs_file_splice_read(
+ struct file *in,
+ loff_t *ppos,
+ struct pipe_inode_info *pipe,
+ size_t len,
+ unsigned int flags)
+{
+ struct inode *inode = file_inode(in);
+ struct xfs_inode *ip = XFS_I(inode);
+ struct xfs_mount *mp = ip->i_mount;
+ ssize_t ret = 0;
+
+ XFS_STATS_INC(mp, xs_read_calls);
+
+ if (xfs_is_shutdown(mp))
+ return -EIO;
+
+ if (in->f_flags & O_DIRECT)
+ return direct_splice_read(in, ppos, pipe, len, flags);
+
+ trace_xfs_file_splice_read(ip, *ppos, len);
+
+ xfs_ilock(ip, XFS_IOLOCK_SHARED);
+ ret = filemap_splice_read(in, ppos, pipe, len, flags);
+ xfs_iunlock(ip, XFS_IOLOCK_SHARED);
+ if (ret > 0)
+ XFS_STATS_ADD(mp, xs_read_bytes, ret);
+ return ret;
+}
+
/*
* Common pre-write limit and setup checks.
*
@@ -1423,7 +1454,7 @@ const struct file_operations xfs_file_operations = {
.llseek = xfs_file_llseek,
.read_iter = xfs_file_read_iter,
.write_iter = xfs_file_write_iter,
- .splice_read = generic_file_splice_read,
+ .splice_read = xfs_file_splice_read,
.splice_write = iter_file_splice_write,
.iopoll = iocb_bio_iopoll,
.unlocked_ioctl = xfs_file_ioctl,
diff --git a/fs/xfs/xfs_trace.h b/fs/xfs/xfs_trace.h
index cd4ca5b1fcb0..4db669203149 100644
--- a/fs/xfs/xfs_trace.h
+++ b/fs/xfs/xfs_trace.h
@@ -1445,7 +1445,6 @@ DEFINE_RW_EVENT(xfs_file_direct_write);
DEFINE_RW_EVENT(xfs_file_dax_write);
DEFINE_RW_EVENT(xfs_reflink_bounce_dio_write);
-
DECLARE_EVENT_CLASS(xfs_imap_class,
TP_PROTO(struct xfs_inode *ip, xfs_off_t offset, ssize_t count,
int whichfork, struct xfs_bmbt_irec *irec),
@@ -1535,6 +1534,7 @@ DEFINE_SIMPLE_IO_EVENT(xfs_zero_eof);
DEFINE_SIMPLE_IO_EVENT(xfs_end_io_direct_write);
DEFINE_SIMPLE_IO_EVENT(xfs_end_io_direct_write_unwritten);
DEFINE_SIMPLE_IO_EVENT(xfs_end_io_direct_write_append);
+DEFINE_SIMPLE_IO_EVENT(xfs_file_splice_read);
DECLARE_EVENT_CLASS(xfs_itrunc_class,
TP_PROTO(struct xfs_inode *ip, xfs_fsize_t new_size),
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v20 22/32] zonefs: Provide a splice-read stub
[not found] <20230519074047.1739879-1-dhowells@redhat.com>
2023-05-19 7:40 ` [PATCH v20 05/32] splice: Make splice from a DAX file use direct_splice_read() David Howells
2023-05-19 7:40 ` [PATCH v20 21/32] xfs: Provide a splice-read stub David Howells
@ 2023-05-19 7:40 ` David Howells
2 siblings, 0 replies; 5+ messages in thread
From: David Howells @ 2023-05-19 7:40 UTC (permalink / raw)
To: Jens Axboe, Al Viro, Christoph Hellwig
Cc: David Howells, Matthew Wilcox, Jan Kara, Jeff Layton,
David Hildenbrand, Jason Gunthorpe, Logan Gunthorpe, Hillf Danton,
Christian Brauner, Linus Torvalds, linux-fsdevel, linux-block,
linux-kernel, linux-mm, Christoph Hellwig, Darrick J . Wong,
linux-xfs
Provide a splice_read stub for zonefs. This does some checks before
proceeding. For buffered I/O, it locks the inode across the call to
filemap_splice_read() and does a size check in case of truncation.
Signed-off-by: David Howells <dhowells@redhat.com>
cc: Christoph Hellwig <hch@lst.de>
cc: Al Viro <viro@zeniv.linux.org.uk>
cc: Jens Axboe <axboe@kernel.dk>
cc: Darrick J. Wong <djwong@kernel.org>
cc: linux-xfs@vger.kernel.org
cc: linux-fsdevel@vger.kernel.org
cc: linux-block@vger.kernel.org
cc: linux-mm@kvack.org
---
fs/zonefs/file.c | 43 ++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 42 insertions(+), 1 deletion(-)
diff --git a/fs/zonefs/file.c b/fs/zonefs/file.c
index 132f01d3461f..a8d7bae4910d 100644
--- a/fs/zonefs/file.c
+++ b/fs/zonefs/file.c
@@ -752,6 +752,47 @@ static ssize_t zonefs_file_read_iter(struct kiocb *iocb, struct iov_iter *to)
return ret;
}
+static ssize_t zonefs_file_splice_read(struct file *in, loff_t *ppos,
+ struct pipe_inode_info *pipe,
+ size_t len, unsigned int flags)
+{
+ struct inode *inode = file_inode(in);
+ struct zonefs_inode_info *zi = ZONEFS_I(inode);
+ struct zonefs_zone *z = zonefs_inode_zone(inode);
+ loff_t isize;
+ ssize_t ret = 0;
+
+ /* Offline zones cannot be read */
+ if (unlikely(IS_IMMUTABLE(inode) && !(inode->i_mode & 0777)))
+ return -EPERM;
+
+ if (*ppos >= z->z_capacity)
+ return 0;
+
+ if (in->f_flags & O_DIRECT)
+ return direct_splice_read(in, ppos, pipe, len, flags);
+
+ inode_lock_shared(inode);
+
+ /* Limit read operations to written data */
+ mutex_lock(&zi->i_truncate_mutex);
+ isize = i_size_read(inode);
+ if (*ppos >= isize)
+ len = 0;
+ else
+ len = min_t(loff_t, len, isize - *ppos);
+ mutex_unlock(&zi->i_truncate_mutex);
+
+ if (len > 0) {
+ ret = filemap_splice_read(in, ppos, pipe, len, flags);
+ if (ret == -EIO)
+ zonefs_io_error(inode, false);
+ }
+
+ inode_unlock_shared(inode);
+ return ret;
+}
+
/*
* Write open accounting is done only for sequential files.
*/
@@ -896,7 +937,7 @@ const struct file_operations zonefs_file_operations = {
.llseek = zonefs_file_llseek,
.read_iter = zonefs_file_read_iter,
.write_iter = zonefs_file_write_iter,
- .splice_read = generic_file_splice_read,
+ .splice_read = zonefs_file_splice_read,
.splice_write = iter_file_splice_write,
.iopoll = iocb_bio_iopoll,
};
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v20 05/32] splice: Make splice from a DAX file use direct_splice_read()
2023-05-19 7:40 ` [PATCH v20 05/32] splice: Make splice from a DAX file use direct_splice_read() David Howells
@ 2023-05-19 8:10 ` Christoph Hellwig
2023-05-19 8:48 ` David Howells
0 siblings, 1 reply; 5+ messages in thread
From: Christoph Hellwig @ 2023-05-19 8:10 UTC (permalink / raw)
To: David Howells
Cc: Jens Axboe, Al Viro, Christoph Hellwig, Matthew Wilcox, Jan Kara,
Jeff Layton, David Hildenbrand, Jason Gunthorpe, Logan Gunthorpe,
Hillf Danton, Christian Brauner, Linus Torvalds, linux-fsdevel,
linux-block, linux-kernel, linux-mm, Christoph Hellwig,
linux-erofs, linux-ext4, linux-xfs
On Fri, May 19, 2023 at 08:40:20AM +0100, David Howells wrote:
> +#ifdef CONFIG_FS_DAX
> + if (IS_DAX(in->f_mapping->host))
No need for the ifdef. IS_DAX is compile-time false if CONFIG_FS_DAX
is not set.
A comment on why we're doing this in the code would probably be useful
as well.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v20 05/32] splice: Make splice from a DAX file use direct_splice_read()
2023-05-19 8:10 ` Christoph Hellwig
@ 2023-05-19 8:48 ` David Howells
0 siblings, 0 replies; 5+ messages in thread
From: David Howells @ 2023-05-19 8:48 UTC (permalink / raw)
To: Christoph Hellwig
Cc: dhowells, Jens Axboe, Al Viro, Matthew Wilcox, Jan Kara,
Jeff Layton, David Hildenbrand, Jason Gunthorpe, Logan Gunthorpe,
Hillf Danton, Christian Brauner, Linus Torvalds, linux-fsdevel,
linux-block, linux-kernel, linux-mm, Christoph Hellwig,
linux-erofs, linux-ext4, linux-xfs
Christoph Hellwig <hch@infradead.org> wrote:
> On Fri, May 19, 2023 at 08:40:20AM +0100, David Howells wrote:
> > +#ifdef CONFIG_FS_DAX
> > + if (IS_DAX(in->f_mapping->host))
>
> No need for the ifdef. IS_DAX is compile-time false if CONFIG_FS_DAX
> is not set.
Ah - it's not that IS_DAX() is conditionalised, it's that S_DAX is. There's a
bunch of places that use CONFIG_FS_DAX blocks, but I guess that's because they
include calls to functions that are conditionalised out.
I wonder if the dax_iomap_rw() declaration in the header can have a non-DAX
fallback that returns an error and then we can get rid of some of the other
conditionalisation.
David
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2023-05-19 8:49 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20230519074047.1739879-1-dhowells@redhat.com>
2023-05-19 7:40 ` [PATCH v20 05/32] splice: Make splice from a DAX file use direct_splice_read() David Howells
2023-05-19 8:10 ` Christoph Hellwig
2023-05-19 8:48 ` David Howells
2023-05-19 7:40 ` [PATCH v20 21/32] xfs: Provide a splice-read stub David Howells
2023-05-19 7:40 ` [PATCH v20 22/32] zonefs: " David Howells
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox