lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <157219118016.7078.16223055699799396042.stgit@buzz>
Date:   Sun, 27 Oct 2019 18:46:20 +0300
From:   Konstantin Khlebnikov <khlebnikov@...dex-team.ru>
To:     David Howells <dhowells@...hat.com>,
        Peter Zijlstra <peterz@...radead.org>,
        Linus Torvalds <torvalds@...ux-foundation.org>,
        linux-kernel@...r.kernel.org
Subject: [PATCH] pipe: wakeup writer only if pipe buffer is at least half
 empty

There is no reason to wakeup writer if pipe has only one empty page.
This means reader consumes data slower then writer produces it.

This patch waits until buffer is at least half empty before waking writer.
This lets him produce more data at once. In general, this change should
increase data batching and decrease rate of context switches.

perf stat bash -c 'seq 50000000 | wc' shows decreasing count of context
switches from 26k to 13k. Execution time stays the same.

Signed-off-by: Konstantin Khlebnikov <khlebnikov@...dex-team.ru>
---
 fs/pipe.c |    7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/fs/pipe.c b/fs/pipe.c
index 8a2ab2f974bd..14754c9095ce 100644
--- a/fs/pipe.c
+++ b/fs/pipe.c
@@ -324,7 +324,8 @@ pipe_read(struct kiocb *iocb, struct iov_iter *to)
 				curbuf = (curbuf + 1) & (pipe->buffers - 1);
 				pipe->curbuf = curbuf;
 				pipe->nrbufs = --bufs;
-				do_wakeup = 1;
+				/* Wakeup writer if buffer is half empty */
+				do_wakeup = bufs <= pipe->buffers / 2;
 			}
 			total_len -= chars;
 			if (!total_len)
@@ -555,7 +556,9 @@ pipe_poll(struct file *filp, poll_table *wait)
 	}
 
 	if (filp->f_mode & FMODE_WRITE) {
-		mask |= (nrbufs < pipe->buffers) ? EPOLLOUT | EPOLLWRNORM : 0;
+		/* Wakeup writer if buffer is half empty */
+		if (nrbufs <= pipe->buffers / 2)
+			mask |= EPOLLOUT | EPOLLWRNORM;
 		/*
 		 * Most Unices do not set EPOLLERR for FIFOs but on Linux they
 		 * behave exactly like pipes for poll().

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ