Performance regression introduced by commit b667b8673443 ("pipe: Advance tail pointer inside of wait spinlock in pipe_read()")

From: Waiman Long
Date: Fri Jan 17 2020 - 11:53:57 EST


David,

I had found that parallel kernel build became much slower when a
5.5-based kernel is used. On a 2-socket 96-thread x86-64 system, the
"make -j88" time increased from less than 3 minutes with the 5.4 kernel
to more than double with the 5.5 kernel.

So I used bisection to try to find the culprit:

b667b867344301e24f21d4a4c844675ff61d89e1 is the first bad commit
commit b667b867344301e24f21d4a4c844675ff61d89e1
Author: David Howells <dhowells@xxxxxxxxxx>
Date:ÂÂ Tue Sep 24 16:09:04 2019 +0100

ÂÂÂ pipe: Advance tail pointer inside of wait spinlock in pipe_read()
ÂÂÂ
ÂÂÂ Advance the pipe ring tail pointer inside of wait spinlock in
pipe_read()
ÂÂÂ so that the pipe can be written into with kernel notifications from
ÂÂÂ contexts where pipe->mutex cannot be taken.
ÂÂÂ
ÂÂÂ Signed-off-by: David Howells <dhowells@xxxxxxxxxx>

diff --git a/fs/pipe.c b/fs/pipe.c
index 69afeab8a73a..ea134f69a292 100644
--- a/fs/pipe.c
+++ b/fs/pipe.c
@@ -325,9 +325,14 @@ pipe_read(struct kiocb *iocb, struct iov_iter *to)
Â
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ if (!buf->len) {
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ pipe_buf_release(pipe, buf);
+ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ spin_lock_irq(&pipe->wait.lock);
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ tail++;
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ pipe->tail = tail;
-ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ do_wakeup = 1;
+ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ do_wakeup = 0;
+ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ wake_up_interruptible_sync_poll_locked(
+ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ &pipe->wait, EPOLLOUT |
EPOLLWRNORM);
+ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ spin_unlock_irq(&pipe->wait.lock);
+ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ kill_fasync(&pipe->fasync_writers,
SIGIO, POLL_O
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ }

I guess the make command may make heavy use of pipe. The adding of
spinlock code in your patch may probably over-serialize the pipe
operation. Could you achieve the same functionality without adding a lock?

Cheers,
Longman