lkml.org 
[lkml]   [2023]   [May]   [19]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH v20 03/32] splice: Make direct_read_splice() limit to eof where appropriate
Date
Make direct_read_splice() limit the read to the end of the file for regular
files and block devices, thereby reducing the amount of allocation it will
do in such a case.

This means that the blockdev code doesn't require any special handling as
filemap_read_splice() also limits to i_size.

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-block@vger.kernel.org
cc: linux-fsdevel@vger.kernel.org
cc: linux-mm@kvack.org
---
fs/splice.c | 13 +++++++++++++
1 file changed, 13 insertions(+)

diff --git a/fs/splice.c b/fs/splice.c
index 4db3eee49423..89c8516554d1 100644
--- a/fs/splice.c
+++ b/fs/splice.c
@@ -315,6 +315,19 @@ ssize_t direct_splice_read(struct file *in, loff_t *ppos,
size_t used, npages, chunk, remain, keep = 0;
int i;

+ if (!len)
+ return 0;
+
+ if (S_ISREG(file_inode(in)->i_mode) ||
+ S_ISBLK(file_inode(in)->i_mode)) {
+ loff_t i_size = i_size_read(in->f_mapping->host);
+
+ if (*ppos >= i_size)
+ return 0;
+ if (len > i_size - *ppos)
+ len = i_size - *ppos;
+ }
+
/* Work out how much data we can actually add into the pipe */
used = pipe_occupancy(pipe->head, pipe->tail);
npages = max_t(ssize_t, pipe->max_usage - used, 0);
\
 
 \ /
  Last update: 2023-05-19 09:43    [W:1.976 / U:0.196 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site