Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp1674853ybx; Thu, 31 Oct 2019 14:14:06 -0700 (PDT) X-Google-Smtp-Source: APXvYqx7WZTjni6qHixXAkJ61RBUZEcVz1JX1SOXGNqlK7zJxEjiP+3pgLNd+mDaUsGJJlplWv2t X-Received: by 2002:a50:fb87:: with SMTP id e7mr8725846edq.268.1572556445924; Thu, 31 Oct 2019 14:14:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1572556445; cv=none; d=google.com; s=arc-20160816; b=cA0lxGl1AmfPIhDIUpL21aUmYyEFmnqgH2YGFqFqirNYAVbjlmueiQYCKEAZ11d/21 Z3/S5lenK+9E3hLg94HeFxuhxSL8tMFX3ZJ6kpMv39hqnEJxQwQG+h5xcZE4vIDvmtHX G12rMd2JxCrxg26DG7s9SugBrgGTTUGXmsR91YulWTNyMZHFLTygNSleO26gyxbUh1IU 4wKWQIpJrn6oQfva83tT6+0xIC0ZAFP05nsmZ4gQLjvGo0X+tqBQptGIcpUXsBIi3O38 RfLZI0/dUA0bLpZCbSlvOqvqX/7b+TEAN+0oap3aB/CRKeMvDEVECQtDRM151wqy8ubf EKvQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:message-id:date :content-id:mime-version:subject:cc:to:references:in-reply-to:from :organization:dkim-signature; bh=mxgLr4gqIZKHqSVNNAtea7HdJZYdiBMzARcL7j6XY2g=; b=XpmwVmWY2PSSrMqdZamz/3yBTYEJKToK1OXgAsU+sUueG1aznGlBXxr/biqMWqPmsZ 3Z41BGFH6aYQ6pMvFJnSV4C5nSFKRyB0mGY8OZxj+NLiP7kJCdxdDzgKLJjzbpdmBLRj TFTHGWeSIblGJcB8lpNGtqNbx6Qbwn85wtSaNqG+E9E2Ued1S+g807CD5pdpTrP+kkpQ qgdilCkOa2STmTt+MSbLmtpfo5Lsp8DJyOMr33tOsrMviBQc5UkFI7byTotBFuxiztCn EqqN1PU6GCCZ5DGr68Raz8RhSxEq7XFwi4cM1itDY/Zm2Wm79ed5tUpB3s3w/OsrSR+i hndQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=h5BTChE2; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z13si4381164ejw.409.2019.10.31.14.13.40; Thu, 31 Oct 2019 14:14:05 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=h5BTChE2; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728616AbfJaQiS (ORCPT + 99 others); Thu, 31 Oct 2019 12:38:18 -0400 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:55495 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727856AbfJaQiR (ORCPT ); Thu, 31 Oct 2019 12:38:17 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1572539896; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=mxgLr4gqIZKHqSVNNAtea7HdJZYdiBMzARcL7j6XY2g=; b=h5BTChE289sI+KXEVqXtpz0KrFvty9/B+inTU5HmlAS/7MRHkHTM1/S7uTtWqo41iy43oN BSfSDd9BB4n1yyDnundvocBfhrHZKFbsRH7GWx+m4XvvgL71C/OCPPJkP4j04KZMZZRc03 BZKTV+ZGDkniPkx5q5bigKXvTDpPUq0= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-120-OBNcKO5IPbCsAav66unpNg-1; Thu, 31 Oct 2019 12:38:11 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D80461800D55; Thu, 31 Oct 2019 16:38:08 +0000 (UTC) Received: from warthog.procyon.org.uk (ovpn-121-40.rdu2.redhat.com [10.10.121.40]) by smtp.corp.redhat.com (Postfix) with ESMTP id A573219C5B; Thu, 31 Oct 2019 16:38:05 +0000 (UTC) Organization: Red Hat UK Ltd. Registered Address: Red Hat UK Ltd, Amberley Place, 107-111 Peascod Street, Windsor, Berkshire, SI4 1TE, United Kingdom. Registered in England and Wales under Company Registration No. 3798903 From: David Howells In-Reply-To: References: <157186182463.3995.13922458878706311997.stgit@warthog.procyon.org.uk> <157186189069.3995.10292601951655075484.stgit@warthog.procyon.org.uk> To: Konstantin Khlebnikov Cc: dhowells@redhat.com, torvalds@linux-foundation.org, Rasmus Villemoes , Greg Kroah-Hartman , Peter Zijlstra , nicolas.dichtel@6wind.com, raven@themaw.net, Christian Brauner , keyrings@vger.kernel.org, linux-usb@vger.kernel.org, linux-block@vger.kernel.org, linux-security-module@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-api@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [RFC PATCH 07/10] pipe: Conditionalise wakeup in pipe_read() [ver #2] MIME-Version: 1.0 Content-ID: <3164.1572539884.1@warthog.procyon.org.uk> Date: Thu, 31 Oct 2019 16:38:04 +0000 Message-ID: <3165.1572539884@warthog.procyon.org.uk> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-MC-Unique: OBNcKO5IPbCsAav66unpNg-1 X-Mimecast-Spam-Score: 0 Content-Type: text/plain; charset=WINDOWS-1252 Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 w= ith 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 branche= s 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 branche= s So it did make something like a 20% reduction in context switches. 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) =09size_t total_len =3D iov_iter_count(to); =09struct file *filp =3D iocb->ki_filp; =09struct pipe_inode_info *pipe =3D filp->private_data; -=09int do_wakeup; +=09int do_wakeup, wake; =09ssize_t ret; =09/* Null read succeeds. */ @@ -329,11 +329,12 @@ pipe_read(struct kiocb *iocb, struct iov_iter *to) =09=09=09=09tail++; =09=09=09=09pipe->tail =3D tail; =09=09=09=09do_wakeup =3D 1; -=09=09=09=09if (head - (tail - 1) =3D=3D pipe->max_usage) +=09=09=09=09wake =3D head - (tail - 1) =3D=3D pipe->max_usage / 2; +=09=09=09=09if (wake) =09=09=09=09=09wake_up_interruptible_sync_poll_locked( =09=09=09=09=09=09&pipe->wait, EPOLLOUT | EPOLLWRNORM); =09=09=09=09spin_unlock_irq(&pipe->wait.lock); -=09=09=09=09if (head - (tail - 1) =3D=3D pipe->max_usage) +=09=09=09=09if (wake) =09=09=09=09=09kill_fasync(&pipe->fasync_writers, SIGIO, POLL_OUT); =09=09=09} =09=09=09total_len -=3D chars;