From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Michael Albinus Newsgroups: gmane.emacs.bugs Subject: bug#53432: [PATCH] Avoid losing keyboard input when inotify is too busy [and 1 more messages] Date: Mon, 24 Jan 2022 15:42:33 +0100 Message-ID: <87lez5ry92.fsf@gmx.de> References: <25067.17249.604070.872185@chiark.greenend.org.uk> <838rv8nua8.fsf@gnu.org> <87r190wqo1.fsf@yahoo.com> <25068.23625.512978.147194@chiark.greenend.org.uk> <87a6fntgfh.fsf@yahoo.com> <25069.23134.887206.241281@chiark.greenend.org.uk> <877daqtnkw.fsf@gmx.de> <25069.40682.688423.883151@chiark.greenend.org.uk> Mime-Version: 1.0 Content-Type: text/plain Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="22450"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux) Cc: Po Lu , 53432@debbugs.gnu.org To: Ian Jackson Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon Jan 24 15:47:24 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 1nC0cu-0005V1-5z for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 24 Jan 2022 15:47:24 +0100 Original-Received: from localhost ([::1]:45738 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nC0cs-0000ZG-Rf for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 24 Jan 2022 09:47:22 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:47908) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nC0Yg-0004SK-Gl for bug-gnu-emacs@gnu.org; Mon, 24 Jan 2022 09:43:02 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:49812) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nC0Yg-0000hj-4C for bug-gnu-emacs@gnu.org; Mon, 24 Jan 2022 09:43:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1nC0Yg-0000NK-0m for bug-gnu-emacs@gnu.org; Mon, 24 Jan 2022 09:43:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Michael Albinus Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 24 Jan 2022 14:43:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 53432 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 53432-submit@debbugs.gnu.org id=B53432.16430353651420 (code B ref 53432); Mon, 24 Jan 2022 14:43:01 +0000 Original-Received: (at 53432) by debbugs.gnu.org; 24 Jan 2022 14:42:45 +0000 Original-Received: from localhost ([127.0.0.1]:42715 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nC0YO-0000Mq-Mt for submit@debbugs.gnu.org; Mon, 24 Jan 2022 09:42:45 -0500 Original-Received: from mout.gmx.net ([212.227.17.21]:50547) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nC0YN-0000Ma-2v for 53432@debbugs.gnu.org; Mon, 24 Jan 2022 09:42:44 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1643035354; bh=Tb/JAbjMAJv+5S1Yq0EvixVaF8E+rzZcNsjr6nM9dZg=; h=X-UI-Sender-Class:From:To:Cc:Subject:References:Date:In-Reply-To; b=imgsEl1A5YmXS9VKiCWcCYd/eKGbbqaglEEbiKZwP21ndT/yAPkH9nQUUH9kQqGvF PebtsXL/HROuvNrjqCAgOglcZj2zAuzbi3yW1aUaJyovM5rHcaY7IOgStKLc1gqWJJ Y7YelQCatjlTQsqQ0cQbk4DneF9jndN7x31oYUMs= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Original-Received: from gandalf.gmx.de ([79.140.118.216]) by mail.gmx.net (mrgmx105 [212.227.17.168]) with ESMTPSA (Nemesis) id 1M6UZl-1nESSB0dxp-006sxj; Mon, 24 Jan 2022 15:42:34 +0100 In-Reply-To: <25069.40682.688423.883151@chiark.greenend.org.uk> (Ian Jackson's message of "Sun, 23 Jan 2022 18:31:06 +0000") X-Provags-ID: V03:K1:ay6jQvPQ9cJKa8ibPaGYeka87RXfQ673jwpDiQr5OZO0rkVtAm8 3Z1cQ+xtdotHmVsWtkIQCIJY7X1w4+Qpo4tNfqgJBcbEeF760NgTSoYPYu1e+9B0Jblpv4p m3vRv6hl7p2fr556chfJe9jULyiUQk8APK6dVeSA35X5Z7Axkfa0qQOi7OV7QQ9qrsFWxCk 040HuUcOUjqnlyu9+7+tA== X-UI-Out-Filterresults: notjunk:1;V03:K0:hxifmJACUmY=:juuIt4yR6KbFYxbqGXVUY5 szu+4nuOdGb6ZhIYkd9IrqIJ6EONpaFALkXi3XDREOqfLep/wOE0APzulQvcSk3PL0yaTSi6C N7RDC2CpNIbRHX1+7vQTk3Q+9TmMR+IcVG6DDiwrFVXj/cnmhRTNggIhq18a3O2qMFQ0L+Uwk h2TYZ9lBFmgRtMgzR9xE+lRL2SOQCJPqYZDyU0wjW3zcB+265mntaA+QIdFa+ynsfK7w7231M szNzgRJ3gw2CZCuRZxxRkR4T8m+N145iM67yzWLz+ZJZW1+a4+K9uQzWQxOjGO5auVKAOu6Jt nef5spL2zILUoicFU2+26iVUfFyBbOjgqaa2exmyMVUOeZVOtTLCJB94J6MroeZRXTGZEb7F5 wDKBo6s8nAYxLl9EAl8bLnpHvisHKgvWda+7YvfEUXiXuv+T3KSXTjCIQG0mBbMIjsXXMqop0 rG8tE24YcTuutuih+LxKLQxBgyckr8JpyCEySTU0wCVcVb/U1o6VvqdYigxPVInVgEr/xDdsH rvetkdt5bzlGJoXqaIfDr+4Sm9gpCLMmhsngE7rpmn066bjthjmlW8xhnDgZ7mRKxlinzdXQP snMF41XPB42Qnf/Yu9OZqbH8Q3qw7vxJxntt6KnI9kRgDZTG/k3lYFOTDtKugCqq92x/kBXmS RtdWBuWQhtDXkwucwEPb3+7sNE9x2K7DZiQbN2TkS5HkKGLSQ8K5UBtzDHaUlpqkn2KdIwNP2 LolCGb7X0Yuzi/NRX68JLLuptbfz9LqJHxu70LsGVV37lYuizYBAqnTKlVt4no8TsmK1qzNQ 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:225058 Archived-At: Ian Jackson writes: > Hi. Thanks for your really helpful reply! Hi Ian, > I guess we probably want a "file notifications might have been missed" > callback. Having it be a callback like a normal file event callback > will probably make it easiest to deal with. Yep. > Another possibility would be simply to fire every file notification > event with a dummy set of information. But that would probably > involve changing a lot more code. Yes, and it might also be a performance degradation. >> For this, I have no opinion. However, I remember vaguely that Stefan >> said once that we shall not (mis-)use the keyboard buffer for incoming >> events, like from file notification or from D-Bus. Another mechanism is >> needed. This idea hasn't been implemented. > > Hrm. I don't think I have an opinion about this. But I think the > design with a fixed size buffer, implying that input to the buffer > needs to be suspended and resumed, means that *every* piece of code > that might write into this buffer must also participate in the flow > control mechanism. > > I don't think separating out the input buffers would remove that > requirement. Ie, the ability to cope correctly with a flood of events > (of whatever kind) will remain necessary. Yes. But if we divide the keyboard buffer (also good for mouse events and other events which do not harm) from the D-Bus and file notification events, such a check is needed at fewer places. >> The following packages inject events via the keyboard buffer: >> dbusbind.c, gfilenotify.c, inotify.c, kqueue.c, w32notify.c. All of the= m >> could see a burst of incoming events. It isn't just an inotify problem. > > Yes. How alarming. Well, this is a bigger problem. > > From my personal point of view I have effort available to fix inotify > and kqueue, provided we can agree a way forward. I looked at kqueue.c > and it writes only file notification events to the buffer, so the same > "file notifications possibly missed" callback would suffice. Yes. Same also for dbusbind.c and gfilenotify.c. For w32notify.c I'm not sure, but likely also the same situation. > But I think the keyboard buffer suspend/resume, with > event-generating-code specific callbacks for suspend > ("hold_keyboard_input" etc. calls in "kbd_buffer_store_buffered_event") > and resume (in "kbd_buffer_get_event") is not a terrible design. > > I think every one of these other event sources ought to be able to > partake of this scheme (adding their own hooks like I proposed for > inotify) without undue difficulty. Yes. But I believe we don't need to handle lost events. If we have a mean to inform the upper libraries, filenotify.el and dbus.el, about this case, it would be sufficient. A simple check whether the event buffer is full. > The alternative would seem to be some kind of dynamic registration > system. As I say, splitting the event input buffer into "keyboard" > and "other things" doesn't seem like it would obviate the need for > this plubming. The advantage of splitting into "keyboard" and "other things" buffers would be, that the keyboard buffer doesn't overrun, whatever burst of D-Bus or file notification events arrives. > I was imagining a callback hook into the inotify code for "keyboard > buffer has become empty", which would check for "have we set the flag > for lost events". If the flag was set, it would drain the inotify fd, > make *one* "lost events" callback, and start reading the inotify fd > again. > > The result would be that if any of the buffers overflowed, we would > stop processing inotify events altogether until emacs has caught up > with the user's keyboard input, and then (via the file notification > "maybe lost" callback, do one check on every file which we might want > to revert). I don't believe that the native backends, like inotify.c, deserve too much intelligence. They shall do stupid event receiving and reporting, with a callback invoked in case of problems. This callback must be clever then. >> > I definitely think we want to get (back) to the point where choosing >> > the keyboard buffer size can be done purely with respect to >> > performance considerations rather than worrying about lossage. >> >> As said above: perhaps it isn't the best idea to handle such events via >> the keyboard buffer. > > Would it be OK to postpone splitting this out ? I don't think > splitting this up is necessary to fix these lost notifications. Not to fix lost events. But it helps to fix lost keyboard strokes. > I think I will let experts on glib, and the glib code in emacs, handle > this. > > I guess if I'm fixing this for inotify, I should at least add a > comment next to kbd_buffer_store_event saying "you may not call this > unless you participate in the flow control protocol" and add FIXMEs to > the call sites that currently don't. > > All of those use cases will have the practical consequences of these > bugs reduced by using a bigger buffer. > > I guess the next thing I should do is go and read the file > notification lisp code to see how a "please do a one-off poll" > callback could be implemented. Hmm. We are still in different camps about the approach ... > Ian. Best regards, Michael.