[PATCH 6/6] fuse: optimize short direct reads

2012-12-14 Thread Maxim V. Patlasov
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 
---
 fs/fuse/file.c |   19 +--
 1 files changed, 13 insertions(+), 6 deletions(-)

diff --git a/fs/fuse/file.c b/fs/fuse/file.c
index b6e9b8d..ceacd20 100644
--- a/fs/fuse/file.c
+++ b/fs/fuse/file.c
@@ -1322,7 +1322,8 @@ ssize_t fuse_direct_io(struct fuse_io_priv *io, const 
struct iovec *iov,
 EXPORT_SYMBOL_GPL(fuse_direct_io);
 
 static ssize_t __fuse_direct_read(struct fuse_io_priv *io, const struct iovec 
*iov,
- unsigned long nr_segs, loff_t *ppos)
+ unsigned long nr_segs, loff_t *ppos,
+ size_t count)
 {
ssize_t res;
struct file *file = io->file;
@@ -1331,8 +1332,7 @@ static ssize_t __fuse_direct_read(struct fuse_io_priv 
*io, const struct iovec *i
if (is_bad_inode(inode))
return -EIO;
 
-   res = fuse_direct_io(io, iov, nr_segs, iov_length(iov, nr_segs),
-ppos, 0);
+   res = fuse_direct_io(io, iov, nr_segs, count, ppos, 0);
 
fuse_invalidate_attr(inode);
 
@@ -1344,7 +1344,7 @@ static ssize_t fuse_direct_read(struct file *file, char 
__user *buf,
 {
struct fuse_io_priv io = { .async = 0, .file = file };
struct iovec iov = { .iov_base = buf, .iov_len = count };
-   return __fuse_direct_read(, , 1, ppos);
+   return __fuse_direct_read(, , 1, ppos, count);
 }
 
 static ssize_t __fuse_direct_write(struct fuse_io_priv *io, const struct iovec 
*iov,
@@ -2404,6 +2404,13 @@ fuse_direct_IO(int rw, struct kiocb *iocb, const struct 
iovec *iov,
inode = file->f_mapping->host;
i_size = i_size_read(inode);
 
+   /* optimization for short read */
+   if (rw != WRITE && offset + count > i_size) {
+   if (offset >= i_size)
+   return 0;
+   count = i_size - offset;
+   }
+
io = kmalloc(sizeof(struct fuse_io_priv), GFP_KERNEL);
if (!io)
return -ENOMEM;
@@ -2427,13 +2434,13 @@ fuse_direct_IO(int rw, struct kiocb *iocb, const struct 
iovec *iov,
 * to wait on real async I/O requests, so we must submit this request
 * synchronously.
 */
-   if (!is_sync_kiocb(iocb) && (offset + count > i_size) && rw == WRITE)
+   if (!is_sync_kiocb(iocb) && (offset + count > i_size))
io->async = 0;
 
if (rw == WRITE)
ret = __fuse_direct_write(io, iov, nr_segs, );
else
-   ret = __fuse_direct_read(io, iov, nr_segs, );
+   ret = __fuse_direct_read(io, iov, nr_segs, , count);
 
if (io->async) {
fuse_aio_complete(io, ret == count ? 0 : -EIO, -1);

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 6/6] fuse: optimize short direct reads

2012-12-14 Thread Maxim V. Patlasov
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 mpatla...@parallels.com
---
 fs/fuse/file.c |   19 +--
 1 files changed, 13 insertions(+), 6 deletions(-)

diff --git a/fs/fuse/file.c b/fs/fuse/file.c
index b6e9b8d..ceacd20 100644
--- a/fs/fuse/file.c
+++ b/fs/fuse/file.c
@@ -1322,7 +1322,8 @@ ssize_t fuse_direct_io(struct fuse_io_priv *io, const 
struct iovec *iov,
 EXPORT_SYMBOL_GPL(fuse_direct_io);
 
 static ssize_t __fuse_direct_read(struct fuse_io_priv *io, const struct iovec 
*iov,
- unsigned long nr_segs, loff_t *ppos)
+ unsigned long nr_segs, loff_t *ppos,
+ size_t count)
 {
ssize_t res;
struct file *file = io-file;
@@ -1331,8 +1332,7 @@ static ssize_t __fuse_direct_read(struct fuse_io_priv 
*io, const struct iovec *i
if (is_bad_inode(inode))
return -EIO;
 
-   res = fuse_direct_io(io, iov, nr_segs, iov_length(iov, nr_segs),
-ppos, 0);
+   res = fuse_direct_io(io, iov, nr_segs, count, ppos, 0);
 
fuse_invalidate_attr(inode);
 
@@ -1344,7 +1344,7 @@ static ssize_t fuse_direct_read(struct file *file, char 
__user *buf,
 {
struct fuse_io_priv io = { .async = 0, .file = file };
struct iovec iov = { .iov_base = buf, .iov_len = count };
-   return __fuse_direct_read(io, iov, 1, ppos);
+   return __fuse_direct_read(io, iov, 1, ppos, count);
 }
 
 static ssize_t __fuse_direct_write(struct fuse_io_priv *io, const struct iovec 
*iov,
@@ -2404,6 +2404,13 @@ fuse_direct_IO(int rw, struct kiocb *iocb, const struct 
iovec *iov,
inode = file-f_mapping-host;
i_size = i_size_read(inode);
 
+   /* optimization for short read */
+   if (rw != WRITE  offset + count  i_size) {
+   if (offset = i_size)
+   return 0;
+   count = i_size - offset;
+   }
+
io = kmalloc(sizeof(struct fuse_io_priv), GFP_KERNEL);
if (!io)
return -ENOMEM;
@@ -2427,13 +2434,13 @@ fuse_direct_IO(int rw, struct kiocb *iocb, const struct 
iovec *iov,
 * to wait on real async I/O requests, so we must submit this request
 * synchronously.
 */
-   if (!is_sync_kiocb(iocb)  (offset + count  i_size)  rw == WRITE)
+   if (!is_sync_kiocb(iocb)  (offset + count  i_size))
io-async = 0;
 
if (rw == WRITE)
ret = __fuse_direct_write(io, iov, nr_segs, pos);
else
-   ret = __fuse_direct_read(io, iov, nr_segs, pos);
+   ret = __fuse_direct_read(io, iov, nr_segs, pos, count);
 
if (io-async) {
fuse_aio_complete(io, ret == count ? 0 : -EIO, -1);

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 6/6] fuse: optimize short direct reads

2012-12-09 Thread Maxim V. Patlasov
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 
---
 fs/fuse/file.c |   19 +--
 1 files changed, 13 insertions(+), 6 deletions(-)

diff --git a/fs/fuse/file.c b/fs/fuse/file.c
index 3e0fdb7..d2094e1 100644
--- a/fs/fuse/file.c
+++ b/fs/fuse/file.c
@@ -1324,7 +1324,7 @@ EXPORT_SYMBOL_GPL(fuse_direct_io);
 
 static ssize_t __fuse_direct_read(struct file *file, const struct iovec *iov,
  unsigned long nr_segs, loff_t *ppos,
- struct kiocb *async)
+ struct kiocb *async, size_t count)
 {
ssize_t res;
struct inode *inode = file->f_path.dentry->d_inode;
@@ -1332,8 +1332,7 @@ static ssize_t __fuse_direct_read(struct file *file, 
const struct iovec *iov,
if (is_bad_inode(inode))
return -EIO;
 
-   res = fuse_direct_io(file, iov, nr_segs, iov_length(iov, nr_segs),
-ppos, 0, async);
+   res = fuse_direct_io(file, iov, nr_segs, count, ppos, 0, async);
 
fuse_invalidate_attr(inode);
 
@@ -1344,7 +1343,7 @@ static ssize_t fuse_direct_read(struct file *file, char 
__user *buf,
 size_t count, loff_t *ppos)
 {
struct iovec iov = { .iov_base = buf, .iov_len = count };
-   return __fuse_direct_read(file, , 1, ppos, NULL);
+   return __fuse_direct_read(file, , 1, ppos, NULL, count);
 }
 
 static ssize_t __fuse_direct_write(struct file *file, const struct iovec *iov,
@@ -2405,8 +2404,15 @@ fuse_direct_IO(int rw, struct kiocb *iocb, const struct 
iovec *iov,
inode = file->f_mapping->host;
i_size = i_size_read(inode);
 
+   /* optimization for short read */
+   if (rw != WRITE && offset + count > i_size) {
+   if (offset >= i_size)
+   return 0;
+   count = i_size - offset;
+   }
+
/* cannot write beyond eof asynchronously */
-   if (is_sync_kiocb(iocb) || (offset + count <= i_size) || rw != WRITE) {
+   if (is_sync_kiocb(iocb) || (offset + count <= i_size)) {
struct fuse_io_priv *io;
 
io = kmalloc(sizeof(struct fuse_io_priv), GFP_KERNEL);
@@ -2429,7 +2435,8 @@ fuse_direct_IO(int rw, struct kiocb *iocb, const struct 
iovec *iov,
if (rw == WRITE)
ret = __fuse_direct_write(file, iov, nr_segs, , async_cb);
else
-   ret = __fuse_direct_read(file, iov, nr_segs, , async_cb);
+   ret = __fuse_direct_read(file, iov, nr_segs, , async_cb,
+count);
 
if (async_cb) {
fuse_aio_complete(async_cb->private, ret == count ? 0 : -EIO,

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 6/6] fuse: optimize short direct reads

2012-12-09 Thread Maxim V. Patlasov
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 mpatla...@parallels.com
---
 fs/fuse/file.c |   19 +--
 1 files changed, 13 insertions(+), 6 deletions(-)

diff --git a/fs/fuse/file.c b/fs/fuse/file.c
index 3e0fdb7..d2094e1 100644
--- a/fs/fuse/file.c
+++ b/fs/fuse/file.c
@@ -1324,7 +1324,7 @@ EXPORT_SYMBOL_GPL(fuse_direct_io);
 
 static ssize_t __fuse_direct_read(struct file *file, const struct iovec *iov,
  unsigned long nr_segs, loff_t *ppos,
- struct kiocb *async)
+ struct kiocb *async, size_t count)
 {
ssize_t res;
struct inode *inode = file-f_path.dentry-d_inode;
@@ -1332,8 +1332,7 @@ static ssize_t __fuse_direct_read(struct file *file, 
const struct iovec *iov,
if (is_bad_inode(inode))
return -EIO;
 
-   res = fuse_direct_io(file, iov, nr_segs, iov_length(iov, nr_segs),
-ppos, 0, async);
+   res = fuse_direct_io(file, iov, nr_segs, count, ppos, 0, async);
 
fuse_invalidate_attr(inode);
 
@@ -1344,7 +1343,7 @@ static ssize_t fuse_direct_read(struct file *file, char 
__user *buf,
 size_t count, loff_t *ppos)
 {
struct iovec iov = { .iov_base = buf, .iov_len = count };
-   return __fuse_direct_read(file, iov, 1, ppos, NULL);
+   return __fuse_direct_read(file, iov, 1, ppos, NULL, count);
 }
 
 static ssize_t __fuse_direct_write(struct file *file, const struct iovec *iov,
@@ -2405,8 +2404,15 @@ fuse_direct_IO(int rw, struct kiocb *iocb, const struct 
iovec *iov,
inode = file-f_mapping-host;
i_size = i_size_read(inode);
 
+   /* optimization for short read */
+   if (rw != WRITE  offset + count  i_size) {
+   if (offset = i_size)
+   return 0;
+   count = i_size - offset;
+   }
+
/* cannot write beyond eof asynchronously */
-   if (is_sync_kiocb(iocb) || (offset + count = i_size) || rw != WRITE) {
+   if (is_sync_kiocb(iocb) || (offset + count = i_size)) {
struct fuse_io_priv *io;
 
io = kmalloc(sizeof(struct fuse_io_priv), GFP_KERNEL);
@@ -2429,7 +2435,8 @@ fuse_direct_IO(int rw, struct kiocb *iocb, const struct 
iovec *iov,
if (rw == WRITE)
ret = __fuse_direct_write(file, iov, nr_segs, pos, async_cb);
else
-   ret = __fuse_direct_read(file, iov, nr_segs, pos, async_cb);
+   ret = __fuse_direct_read(file, iov, nr_segs, pos, async_cb,
+count);
 
if (async_cb) {
fuse_aio_complete(async_cb-private, ret == count ? 0 : -EIO,

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/