From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Dima Kogan Newsgroups: gmane.emacs.bugs Subject: bug#53041: 29.0.50; TRAMP spins the CPU by polling the child processes without a delay Date: Wed, 05 Jan 2022 15:03:48 -0800 Message-ID: <87pmp57pkb.fsf@jpl.nasa.gov> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="37621"; mail-complaints-to="usenet@ciao.gmane.io" To: 53041@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Jan 06 00:04:17 2022 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1n5FKJ-0009Yf-Cz for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 06 Jan 2022 00:04:16 +0100 Original-Received: from localhost ([::1]:51834 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1n5FKI-0003oF-BT for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 05 Jan 2022 18:04:14 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:59556) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n5FK7-0003nU-JX for bug-gnu-emacs@gnu.org; Wed, 05 Jan 2022 18:04:03 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:46362) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1n5FK6-00055Q-Ao for bug-gnu-emacs@gnu.org; Wed, 05 Jan 2022 18:04:03 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1n5FK6-00028R-6K for bug-gnu-emacs@gnu.org; Wed, 05 Jan 2022 18:04:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Dima Kogan Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 05 Jan 2022 23:04:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 53041 X-GNU-PR-Package: emacs X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.16414238388194 (code B ref -1); Wed, 05 Jan 2022 23:04:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 5 Jan 2022 23:03:58 +0000 Original-Received: from localhost ([127.0.0.1]:39265 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1n5FK2-000285-Ki for submit@debbugs.gnu.org; Wed, 05 Jan 2022 18:03:58 -0500 Original-Received: from lists.gnu.org ([209.51.188.17]:53482) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1n5FK1-00027y-6K for submit@debbugs.gnu.org; Wed, 05 Jan 2022 18:03:57 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:59544) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n5FK1-0003nM-14 for bug-gnu-emacs@gnu.org; Wed, 05 Jan 2022 18:03:57 -0500 Original-Received: from wout5-smtp.messagingengine.com ([64.147.123.21]:59157) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n5FJy-00053V-Kg for bug-gnu-emacs@gnu.org; Wed, 05 Jan 2022 18:03:56 -0500 Original-Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.west.internal (Postfix) with ESMTP id 683A03201F85 for ; Wed, 5 Jan 2022 18:03:51 -0500 (EST) Original-Received: from mailfrontend1 ([10.202.2.162]) by compute3.internal (MEProxy); Wed, 05 Jan 2022 18:03:51 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=secretsauce.net; h=from:to:subject:date:message-id:mime-version:content-type; s= fm2; bh=LFC1JzLTOjaCLqqNZf/wmnbbxNXuuRZRgP/EUNfrgqc=; b=dXhBYA8I D9qHok60P7OqY7GeRDtUvXnmRpwIk0xLL0j4wm40xEoCNrsxgQlt0omHW4MLJ+Sb rWcCaRm5MdXhebIAgSffJ0v9NvaB9BP3GaF/OCbK1jfYBpMQC8JAkJuQhYTXdbgF YvxRxPzPPONleu//JdjTlvc0y0fxCnA8NkuJDUxWrlGfJUN0Rm7Gp+O1VsSW2rr6 CSyMmQnPQUG9BQuZnuYkvFH10rsTPO+siFVaaRzFLt6HRjeJPDgGGnVY1qLHnDMo mQ7Qed0OTHTPwlNpshQZEqdraHVfmggT+jYmA6LRT/xnI/dNHGFPtrXXOfKn6G/M /TQU4YKxIlsBLA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-type:date:from:message-id :mime-version:subject:to:x-me-proxy:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm1; bh=LFC1JzLTOjaCLqqNZf/wmnbbxNXuu RZRgP/EUNfrgqc=; b=Tm2t+J/+/IdrH4FjnZrmfv6zqn+fw4vgfQenP8o/vNGDw y9LNXEAnYOjzvQtMxLKTvCMXkSdFrkylvTfJqErBeV45UKnnMr8nQNSZibXGYdnn Z6vXmvMsZU9veFpDKeClBVSaGAs+p/ByS0MlHAS5Lbm8fm7D+eepH1dtFi+whIMK i+dGLFKmEdwieqCLGahN40moW+ZfP8JzbZV/DUOUemXFIS5i3D1Vf4hzhV5NZ9YL c8ivhnycHUgjWy/4wL77smnd/+cVkoZF+anI/Od+vWhwuGcVPTRSWy08pUzjSCOm D/eTRH+k7lV7ASBIxCck5dlubCmDHrQz5GdD7g/og== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvuddrudefjedgkeegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucgfrhhlucfvnfffucdlqddutddmnecujfgurhephf fvufffkfggtgesthdtredttddttdenucfhrhhomhepffhimhgrucfmohhgrghnuceoughi mhgrsehsvggtrhgvthhsrghutggvrdhnvghtqeenucggtffrrghtthgvrhhnpeffvdffud fhkeffhfeifefhffdvtdfgfeejveeuvdefudejjeduveeftdeggeeuvdenucevlhhushht vghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpeguihhmrgesshgvtghrvg htshgruhgtvgdrnhgvth X-ME-Proxy: Original-Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Wed, 5 Jan 2022 18:03:50 -0500 (EST) Received-SPF: pass client-ip=64.147.123.21; envelope-from=dima@secretsauce.net; helo=wout5-smtp.messagingengine.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:223719 Archived-At: Hi. I use TRAMP regularly, and I often see it redline my CPU, which shouldn't be happening. The cause in all cases I've seen is TRAMP expecting some output from the child process, and looking for this output in a delay-less loop. For instance (tramp-process-one-action) looks like this: (defun tramp-process-one-action (proc vec actions) .... (while (not found) (while (tramp-accept-process-output proc 0)) .... ) The (while (tramp-accept-process-output proc 0)) form does Read all available data; returns immediately if none is available So here we spin the CPU until there's some data to look at AND until the incoming data meets some condition we're looking for. In order to not spin, at least one of the (tramp-accept-process-output) calls needs to block. The simplest thing to do to fix this is to replace (while (tramp-accept-process-output proc 0)) with (tramp-accept-process-output proc nil) Here we block until we get SOME data back. I think this is probably good-enough, since the outer loop will get more data, if it's needed. If we really want to replace the original logic with blocking, we can do this instead: (let (timeout) (while (prog1 (tramp-accept-process-output proc timeout) (setq timeout 0)))) Either one of these makes most of these issues disappear. There are more places in the code where we call (tramp-accept-process-output ... 0), and I think they're all wrong: we should always block. I can send a patch, but let's agree on the approach first. My preference is to replace all the (while (tramp-accept-process-output proc 0)) with (tramp-accept-process-output proc nil) unless there's a specific reason not to. One easy way to reproduce one such behavior: 1. Start up emacs 2. open /ssh:SERVER:FILE 3. Break the network connection (I'm on a laptop. Leaving the wifi area is enough) 4. Try to type into the buffer visiting FILE 5. See emacs block the user while spinning the CPU. Thanks