提交 6f767b04 编写于 作者: J Jens Axboe

[PATCH] splice: speedups and optimizations

- Kill the local variables that cache ->nrbufs, they just take up space.

- Only set do_wakeup for a real pipe. This is a big win for direct splicing.

- Kill i_mutex lock around ->f_pos update, regular io paths don't do this
  either.
Signed-off-by: NJens Axboe <axboe@suse.de>
上级 923f4f23
...@@ -150,8 +150,6 @@ static ssize_t move_to_pipe(struct pipe_inode_info *pipe, struct page **pages, ...@@ -150,8 +150,6 @@ static ssize_t move_to_pipe(struct pipe_inode_info *pipe, struct page **pages,
mutex_lock(&pipe->inode->i_mutex); mutex_lock(&pipe->inode->i_mutex);
for (;;) { for (;;) {
int bufs;
if (!pipe->readers) { if (!pipe->readers) {
send_sig(SIGPIPE, current, 0); send_sig(SIGPIPE, current, 0);
if (!ret) if (!ret)
...@@ -159,9 +157,8 @@ static ssize_t move_to_pipe(struct pipe_inode_info *pipe, struct page **pages, ...@@ -159,9 +157,8 @@ static ssize_t move_to_pipe(struct pipe_inode_info *pipe, struct page **pages,
break; break;
} }
bufs = pipe->nrbufs; if (pipe->nrbufs < PIPE_BUFFERS) {
if (bufs < PIPE_BUFFERS) { int newbuf = (pipe->curbuf + pipe->nrbufs) & (PIPE_BUFFERS - 1);
int newbuf = (pipe->curbuf + bufs) & (PIPE_BUFFERS - 1);
struct pipe_buffer *buf = pipe->bufs + newbuf; struct pipe_buffer *buf = pipe->bufs + newbuf;
struct page *page = pages[i++]; struct page *page = pages[i++];
unsigned long this_len; unsigned long this_len;
...@@ -174,8 +171,9 @@ static ssize_t move_to_pipe(struct pipe_inode_info *pipe, struct page **pages, ...@@ -174,8 +171,9 @@ static ssize_t move_to_pipe(struct pipe_inode_info *pipe, struct page **pages,
buf->offset = offset; buf->offset = offset;
buf->len = this_len; buf->len = this_len;
buf->ops = &page_cache_pipe_buf_ops; buf->ops = &page_cache_pipe_buf_ops;
pipe->nrbufs = ++bufs; pipe->nrbufs++;
do_wakeup = 1; if (pipe->inode)
do_wakeup = 1;
ret += this_len; ret += this_len;
len -= this_len; len -= this_len;
...@@ -184,7 +182,7 @@ static ssize_t move_to_pipe(struct pipe_inode_info *pipe, struct page **pages, ...@@ -184,7 +182,7 @@ static ssize_t move_to_pipe(struct pipe_inode_info *pipe, struct page **pages,
break; break;
if (!len) if (!len)
break; break;
if (bufs < PIPE_BUFFERS) if (pipe->nrbufs < PIPE_BUFFERS)
continue; continue;
break; break;
...@@ -581,11 +579,8 @@ static ssize_t move_from_pipe(struct pipe_inode_info *pipe, struct file *out, ...@@ -581,11 +579,8 @@ static ssize_t move_from_pipe(struct pipe_inode_info *pipe, struct file *out,
mutex_lock(&pipe->inode->i_mutex); mutex_lock(&pipe->inode->i_mutex);
for (;;) { for (;;) {
int bufs = pipe->nrbufs; if (pipe->nrbufs) {
struct pipe_buffer *buf = pipe->bufs + pipe->curbuf;
if (bufs) {
int curbuf = pipe->curbuf;
struct pipe_buffer *buf = pipe->bufs + curbuf;
struct pipe_buf_operations *ops = buf->ops; struct pipe_buf_operations *ops = buf->ops;
sd.len = buf->len; sd.len = buf->len;
...@@ -606,10 +601,10 @@ static ssize_t move_from_pipe(struct pipe_inode_info *pipe, struct file *out, ...@@ -606,10 +601,10 @@ static ssize_t move_from_pipe(struct pipe_inode_info *pipe, struct file *out,
if (!buf->len) { if (!buf->len) {
buf->ops = NULL; buf->ops = NULL;
ops->release(pipe, buf); ops->release(pipe, buf);
curbuf = (curbuf + 1) & (PIPE_BUFFERS - 1); pipe->curbuf = (pipe->curbuf + 1) & (PIPE_BUFFERS - 1);
pipe->curbuf = curbuf; pipe->nrbufs--;
pipe->nrbufs = --bufs; if (pipe->inode)
do_wakeup = 1; do_wakeup = 1;
} }
sd.pos += sd.len; sd.pos += sd.len;
...@@ -618,7 +613,7 @@ static ssize_t move_from_pipe(struct pipe_inode_info *pipe, struct file *out, ...@@ -618,7 +613,7 @@ static ssize_t move_from_pipe(struct pipe_inode_info *pipe, struct file *out,
break; break;
} }
if (bufs) if (pipe->nrbufs)
continue; continue;
if (!pipe->writers) if (!pipe->writers)
break; break;
...@@ -660,9 +655,7 @@ static ssize_t move_from_pipe(struct pipe_inode_info *pipe, struct file *out, ...@@ -660,9 +655,7 @@ static ssize_t move_from_pipe(struct pipe_inode_info *pipe, struct file *out,
kill_fasync(&pipe->fasync_writers, SIGIO, POLL_OUT); kill_fasync(&pipe->fasync_writers, SIGIO, POLL_OUT);
} }
mutex_lock(&out->f_mapping->host->i_mutex);
out->f_pos = sd.pos; out->f_pos = sd.pos;
mutex_unlock(&out->f_mapping->host->i_mutex);
return ret; return ret;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册