Skip to content

Commit 439ee5f

Browse files
Maxim PatlasovMiklos Szeredi
authored andcommitted
fuse: optimize short direct reads
If user requested direct read beyond EOF, we can skip sending fuse requests for positions beyond EOF because userspace would ACK them with zero bytes read anyway. We can trust to i_size in fuse_direct_IO for such cases because it's called from fuse_file_aio_read() and the latter updates fuse attributes including i_size. Signed-off-by: Maxim Patlasov <mpatlasov@parallels.com> Signed-off-by: Miklos Szeredi <mszeredi@suse.cz>
1 parent bcba24c commit 439ee5f

1 file changed

Lines changed: 13 additions & 6 deletions

File tree

‎fs/fuse/file.c‎

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1331,7 +1331,8 @@ EXPORT_SYMBOL_GPL(fuse_direct_io);
13311331

13321332
static ssize_t __fuse_direct_read(struct fuse_io_priv *io,
13331333
const struct iovec *iov,
1334-
unsigned long nr_segs, loff_t *ppos)
1334+
unsigned long nr_segs, loff_t *ppos,
1335+
size_t count)
13351336
{
13361337
ssize_t res;
13371338
struct file *file = io->file;
@@ -1340,8 +1341,7 @@ static ssize_t __fuse_direct_read(struct fuse_io_priv *io,
13401341
if (is_bad_inode(inode))
13411342
return -EIO;
13421343

1343-
res = fuse_direct_io(io, iov, nr_segs, iov_length(iov, nr_segs),
1344-
ppos, 0);
1344+
res = fuse_direct_io(io, iov, nr_segs, count, ppos, 0);
13451345

13461346
fuse_invalidate_attr(inode);
13471347

@@ -1353,7 +1353,7 @@ static ssize_t fuse_direct_read(struct file *file, char __user *buf,
13531353
{
13541354
struct fuse_io_priv io = { .async = 0, .file = file };
13551355
struct iovec iov = { .iov_base = buf, .iov_len = count };
1356-
return __fuse_direct_read(&io, &iov, 1, ppos);
1356+
return __fuse_direct_read(&io, &iov, 1, ppos, count);
13571357
}
13581358

13591359
static ssize_t __fuse_direct_write(struct fuse_io_priv *io,
@@ -2369,6 +2369,13 @@ fuse_direct_IO(int rw, struct kiocb *iocb, const struct iovec *iov,
23692369
inode = file->f_mapping->host;
23702370
i_size = i_size_read(inode);
23712371

2372+
/* optimization for short read */
2373+
if (rw != WRITE && offset + count > i_size) {
2374+
if (offset >= i_size)
2375+
return 0;
2376+
count = i_size - offset;
2377+
}
2378+
23722379
io = kmalloc(sizeof(struct fuse_io_priv), GFP_KERNEL);
23732380
if (!io)
23742381
return -ENOMEM;
@@ -2392,13 +2399,13 @@ fuse_direct_IO(int rw, struct kiocb *iocb, const struct iovec *iov,
23922399
* to wait on real async I/O requests, so we must submit this request
23932400
* synchronously.
23942401
*/
2395-
if (!is_sync_kiocb(iocb) && (offset + count > i_size) && rw == WRITE)
2402+
if (!is_sync_kiocb(iocb) && (offset + count > i_size))
23962403
io->async = false;
23972404

23982405
if (rw == WRITE)
23992406
ret = __fuse_direct_write(io, iov, nr_segs, &pos);
24002407
else
2401-
ret = __fuse_direct_read(io, iov, nr_segs, &pos);
2408+
ret = __fuse_direct_read(io, iov, nr_segs, &pos, count);
24022409

24032410
if (io->async) {
24042411
fuse_aio_complete(io, ret < 0 ? ret : 0, -1);

0 commit comments

Comments
 (0)