lkml.org 
[lkml]   [2019]   [Nov]   [3]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
SubjectRe: [RFC PATCH 07/10] pipe: Conditionalise wakeup in pipe_read() [ver #2]
From
Date
On 31/10/2019 19.38, David Howells wrote:
> Okay, attached is a change that might give you what you want. I tried my
> pipe-bench program (see cover note) with perf. The output of the program with
> the patch applied was:
>
> - pipe 305127298 36262221772 302185181 7887690
>
> The output of perf with the patch applied:
>
> 239,943.92 msec task-clock # 1.997 CPUs utilized
> 17,728 context-switches # 73.884 M/sec
> 124 cpu-migrations # 0.517 M/sec
> 9,330 page-faults # 38.884 M/sec
> 885,107,207,365 cycles # 3688822.793 GHz
> 1,386,873,499,490 instructions # 1.57 insn per cycle
> 311,037,372,339 branches # 1296296921.931 M/sec
> 33,467,827 branch-misses # 0.01% of all branches
>
> And without:
>
> 239,891.87 msec task-clock # 1.997 CPUs utilized
> 22,187 context-switches # 92.488 M/sec
> 133 cpu-migrations # 0.554 M/sec
> 9,334 page-faults # 38.909 M/sec
> 884,906,976,128 cycles # 3688787.725 GHz
> 1,391,986,932,265 instructions # 1.57 insn per cycle
> 311,394,686,857 branches # 1298067400.849 M/sec
> 30,242,823 branch-misses # 0.01% of all branches
>
> So it did make something like a 20% reduction in context switches.

Ok. Looks promising. Depending on workload reduction might be much bigger.

I suppose buffer resize (grow) makes wakeup unconditionally. Should be ok.

>
> David
> ---
> diff --git a/fs/pipe.c b/fs/pipe.c
> index e3d5f7a39123..5167921edd73 100644
> --- a/fs/pipe.c
> +++ b/fs/pipe.c
> @@ -276,7 +276,7 @@ pipe_read(struct kiocb *iocb, struct iov_iter *to)
> size_t total_len = iov_iter_count(to);
> struct file *filp = iocb->ki_filp;
> struct pipe_inode_info *pipe = filp->private_data;
> - int do_wakeup;
> + int do_wakeup, wake;
> ssize_t ret;
>
> /* Null read succeeds. */
> @@ -329,11 +329,12 @@ pipe_read(struct kiocb *iocb, struct iov_iter *to)
> tail++;
> pipe->tail = tail;
> do_wakeup = 1;
> - if (head - (tail - 1) == pipe->max_usage)
> + wake = head - (tail - 1) == pipe->max_usage / 2;
> + if (wake)
> wake_up_interruptible_sync_poll_locked(
> &pipe->wait, EPOLLOUT | EPOLLWRNORM);
> spin_unlock_irq(&pipe->wait.lock);
> - if (head - (tail - 1) == pipe->max_usage)
> + if (wake)
> kill_fasync(&pipe->fasync_writers, SIGIO, POLL_OUT);
> }
> total_len -= chars;
>

\
 
 \ /
  Last update: 2019-11-03 12:05    [W:0.067 / U:0.328 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site