splice: direct call for default_file_splice*()
diff mbox series

Message ID 12375b7baa741f0596d54eafc6b1cfd2489dd65a.1579553271.git.asml.silence@gmail.com
State New
Headers show
Series
  • splice: direct call for default_file_splice*()
Related show

Commit Message

Pavel Begunkov Jan. 20, 2020, 8:49 p.m. UTC
Indirect calls could be very expensive nowadays, so try to use direct calls
whenever possible.

Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
---
 fs/splice.c | 17 ++++-------------
 1 file changed, 4 insertions(+), 13 deletions(-)

Comments

Christoph Hellwig Jan. 30, 2020, 4:54 p.m. UTC | #1
On Mon, Jan 20, 2020 at 11:49:46PM +0300, Pavel Begunkov wrote:
> Indirect calls could be very expensive nowadays, so try to use direct calls
> whenever possible.

... and independent of that your new version is much shorter and easier
to read.  But it could be improved a tiny little bit further:

>  	if (out->f_op->splice_write)
> -		splice_write = out->f_op->splice_write;
> +		return out->f_op->splice_write(pipe, out, ppos, len, flags);
>  	else
> -		splice_write = default_file_splice_write;
> -
> -	return splice_write(pipe, out, ppos, len, flags);
> +		return default_file_splice_write(pipe, out, ppos, len, flags);

No need for the else after an return.

>  	if (in->f_op->splice_read)
> -		splice_read = in->f_op->splice_read;
> +		return in->f_op->splice_read(in, ppos, pipe, len, flags);
>  	else
> -		splice_read = default_file_splice_read;
> -
> -	return splice_read(in, ppos, pipe, len, flags);
> +		return default_file_splice_read(in, ppos, pipe, len, flags);

Same here.
Pavel Begunkov Jan. 31, 2020, 9:52 a.m. UTC | #2
On 1/30/2020 7:54 PM, Christoph Hellwig wrote:
> On Mon, Jan 20, 2020 at 11:49:46PM +0300, Pavel Begunkov wrote:
>> Indirect calls could be very expensive nowadays, so try to use direct calls
>> whenever possible.
> 
> ... and independent of that your new version is much shorter and easier
> to read.  But it could be improved a tiny little bit further:
> 
>>  	if (out->f_op->splice_write)
>> -		splice_write = out->f_op->splice_write;
>> +		return out->f_op->splice_write(pipe, out, ppos, len, flags);
>>  	else
>> -		splice_write = default_file_splice_write;
>> -
>> -	return splice_write(pipe, out, ppos, len, flags);
>> +		return default_file_splice_write(pipe, out, ppos, len, flags);
> 
> No need for the else after an return.

It generates identical binary. For this to not look sloppy, I'd add new
line between, so the same 4 lines. And this looks better for me, but
that's rather subjective.

I don't think it's worth of changing. What's the benefit?

> 
>>  	if (in->f_op->splice_read)
>> -		splice_read = in->f_op->splice_read;
>> +		return in->f_op->splice_read(in, ppos, pipe, len, flags);
>>  	else
>> -		splice_read = default_file_splice_read;
>> -
>> -	return splice_read(in, ppos, pipe, len, flags);
>> +		return default_file_splice_read(in, ppos, pipe, len, flags);
> 
> Same here.
>

Patch
diff mbox series

diff --git a/fs/splice.c b/fs/splice.c
index 6a6f30432688..91448d855ff0 100644
--- a/fs/splice.c
+++ b/fs/splice.c
@@ -852,15 +852,10 @@  EXPORT_SYMBOL(generic_splice_sendpage);
 static long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
 			   loff_t *ppos, size_t len, unsigned int flags)
 {
-	ssize_t (*splice_write)(struct pipe_inode_info *, struct file *,
-				loff_t *, size_t, unsigned int);
-
 	if (out->f_op->splice_write)
-		splice_write = out->f_op->splice_write;
+		return out->f_op->splice_write(pipe, out, ppos, len, flags);
 	else
-		splice_write = default_file_splice_write;
-
-	return splice_write(pipe, out, ppos, len, flags);
+		return default_file_splice_write(pipe, out, ppos, len, flags);
 }
 
 /*
@@ -870,8 +865,6 @@  static long do_splice_to(struct file *in, loff_t *ppos,
 			 struct pipe_inode_info *pipe, size_t len,
 			 unsigned int flags)
 {
-	ssize_t (*splice_read)(struct file *, loff_t *,
-			       struct pipe_inode_info *, size_t, unsigned int);
 	int ret;
 
 	if (unlikely(!(in->f_mode & FMODE_READ)))
@@ -885,11 +878,9 @@  static long do_splice_to(struct file *in, loff_t *ppos,
 		len = MAX_RW_COUNT;
 
 	if (in->f_op->splice_read)
-		splice_read = in->f_op->splice_read;
+		return in->f_op->splice_read(in, ppos, pipe, len, flags);
 	else
-		splice_read = default_file_splice_read;
-
-	return splice_read(in, ppos, pipe, len, flags);
+		return default_file_splice_read(in, ppos, pipe, len, flags);
 }
 
 /**