From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Trevor Bentley Newsgroups: gmane.emacs.bugs Subject: bug#43389: 28.0.50; Emacs memory leaks using hard disk all time Date: Wed, 20 Jan 2021 13:02:23 +0100 Message-ID: <87k0s7q0j4.fsf@mail.trevorbentley.com> References: <83y2j0qb2v.fsf@gnu.org> <83h7pbp5wh.fsf@gnu.org> <83v9dpn9em.fsf@gnu.org> <87sg8ts766.fsf@mail.trevorbentley.com> <87pn3usr13.fsf@mail.trevorbentley.com> <87eek0rmqa.fsf@mail.trevorbentley.com> <83zh2l33fv.fsf@gnu.org> <87zh2jqnhi.fsf@mail.trevorbentley.com> <837dpn1ccp.fsf@gnu.org> <87zh2i7jqp.fsf@web.de> <83eejue5v8.fsf@gnu.org> <87tusqqa6n.fsf@mail.trevorbentley.com> <833609ena5.fsf@gnu.org> <87r1ntqz4c.fsf@mail.trevorbentley.com> <83pn3dcx89.fsf@gnu.org> <87mtyhqxy1.fsf@mail.trevorbentley.com> <83o8ixcv9v.fsf@gnu.org> <87k0tlqvzv.fsf@mail.trevorbentley.com> <83mtyhcbno.fsf@gnu.org> <87ft48qdw7.fsf@mail.trevorbentley.com> Mime-Version: 1.0 Content-Type: text/plain; format=flowed Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="35454"; mail-complaints-to="usenet@ciao.gmane.io" Cc: fweimer@redhat.com, 43389@debbugs.gnu.org, dj@redhat.com, bugs@gnu.support, carlos@redhat.com, michael_heerdegen@web.de, monnier@iro.umontreal.ca, To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Jan 20 13:03:16 2021 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 1l2CCg-00096x-VJ for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 20 Jan 2021 13:03:15 +0100 Original-Received: from localhost ([::1]:53898 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l2CCg-0006ut-24 for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 20 Jan 2021 07:03:14 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:54968) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l2CCU-0006un-Us for bug-gnu-emacs@gnu.org; Wed, 20 Jan 2021 07:03:02 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:41533) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1l2CCU-00085Y-NB for bug-gnu-emacs@gnu.org; Wed, 20 Jan 2021 07:03:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1l2CCU-0006fZ-HR for bug-gnu-emacs@gnu.org; Wed, 20 Jan 2021 07:03:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Trevor Bentley Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 20 Jan 2021 12:03:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 43389 X-GNU-PR-Package: emacs Original-Received: via spool by 43389-submit@debbugs.gnu.org id=B43389.161114415425603 (code B ref 43389); Wed, 20 Jan 2021 12:03:02 +0000 Original-Received: (at 43389) by debbugs.gnu.org; 20 Jan 2021 12:02:34 +0000 Original-Received: from localhost ([127.0.0.1]:53079 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1l2CC2-0006et-3x for submit@debbugs.gnu.org; Wed, 20 Jan 2021 07:02:34 -0500 Original-Received: from mail.trevorbentley.com ([37.187.5.80]:35329) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1l2CBz-0006ec-2R for 43389@debbugs.gnu.org; Wed, 20 Jan 2021 07:02:32 -0500 Original-Received: from localhost (c188-150-0-48.bredband.comhem.se [188.150.0.48]) by mail.trevorbentley.com (Postfix) with ESMTPSA id 6C5E1606E0; Wed, 20 Jan 2021 13:02:24 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mail.trevorbentley.com; s=mail; t=1611144144; bh=8CleTkDI/WZDTrPKRmLjufqksVJAOtXdEkSa5uQaI/U=; h=From:To:Cc:Cc:Subject:In-Reply-To:References:Date:From; b=hlcan/H1OmhyXLZbFv3NRJZgI92kvlWzDL6N8DzRjFJdyYF9CNUkbP2nDZfKApQwi 5V/VzO+C/g+RlAseM8WO1OUkS43r3bnKmMOgbKbP/qaNK7CDLuwAfry4kXg50MXpG2 3ogYEEu5j8TnCnhrLJwGh673QscuvdEcIiETjCC8= In-Reply-To: <87ft48qdw7.fsf@mail.trevorbentley.com> 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:198256 Archived-At: > I tried setting a breakpoint in longjmp, but it's called 3 times > for every keypress! That's inconvenient. Running one single > instance now with a conditional breakpoint on longjmp: it will > break if longjmp is called while it's in unblock_input(). I disappeared for ages because... the problem disappeared. I went a month without reproducing it, despite putting a hold on upgrading both system and emacs packages while debugging. Very odd. But today it appeared again. And, for the first time, in a gdb session with breakpoints to confirm my theory. I believe I've found the underlying issue. If you have a look at this long backtrace, you can see that we are inside a garbage_collect call (frame #38). An X11 focus event comes in, triggering a bunch of GTK/GDK/X calls. Mysteriously, this leads to a maybe_quit() call which in turn calls longjmp(). longjmp jumps right out of the garbage collect, leaving it unfinished. Internally in garbage_collect, consing_until_gc was set to the HI_THRESHOLD upper-bound. It is left that way when longjmp leaps out of it, and no automatic garbage collect is ever performed again. This is the start of the ballooning memory. This also explains why my minimized emacs session never hits it and my work sessions hit it very often, and less often on weekends. It's triggered by focus events. I flitter around between windows constantly while working. I don't know emacs internals, so you'll have to figure out if this is X dependent (probably) and/or GTK dependent. It should be possible to come up with an easier way to reproduce it now. Backtrace: ----------- (gdb) bt #0 0x00007ffff5571230 in siglongjmp () at /usr/lib/libc.so.6 #1 0x00005555557bd38d in unwind_to_catch (catch=0x555555dfc320, type=NONLOCAL_EXIT_THROW, value=0x30) at eval.c:1181 #2 0x00005555557bd427 in Fthrow (tag=0xe75830, value=0x30) at eval.c:1198 #3 0x00005555557bdea7 in process_quit_flag () at eval.c:1526 #4 0x00005555557bdeef in maybe_quit () at eval.c:1547 #5 0x00005555557cbbb1 in Fassq (key=0xd0b0, alist=0x55555901c573) at fns.c:1609 #6 0x0000555555632b63 in window_parameter (w=0x555555f2d088, parameter=0xd0b0) at window.c:2262 #7 0x000055555563a075 in window_wants_tab_line (w=0x555555f2d088) at window.c:5410 #8 0x00005555555c22b1 in get_phys_cursor_geometry (w=0x555555f2d088, row=0x55555d9f3ef0, glyph=0x55555fd20e00, xp=0x7fffffff9c48, yp=0x7fffffff9c4c, heightp=0x7fffffff9c50) at xdisp.c:2650 #9 0x00005555556c1b12 in x_draw_hollow_cursor (w=0x555555f2d088, row=0x55555d9f3ef0) at xterm.c:9495 #10 0x00005555556c24f9 in x_draw_window_cursor (w=0x555555f2d088, glyph_row=0x55555d9f3ef0, x=32, y=678, cursor_type=HOLLOW_BOX_CURSOR, cursor_width=1, on_p=true, active_p=false) at xterm.c:9682 #11 0x000055555561a922 in display_and_set_cursor (w=0x555555f2d088, on=true, hpos=2, vpos=18, x=32, y=678) at xdisp.c:31738 #12 0x000055555561aa5b in update_window_cursor (w=0x555555f2d088, on=true) at xdisp.c:31773 #13 0x000055555561aabf in update_cursor_in_window_tree (w=0x555555f2d088, on_p=true) at xdisp.c:31791 #14 0x000055555561aaab in update_cursor_in_window_tree (w=0x55555907a490, on_p=true) at xdisp.c:31789 #15 0x000055555561aaab in update_cursor_in_window_tree (w=0x55555a514b68, on_p=true) at xdisp.c:31789 #16 0x000055555561ab37 in gui_update_cursor (f=0x555556625468, on_p=true) at xdisp.c:31805 #17 0x00005555556b9829 in x_frame_unhighlight (f=0x555556625468) at xterm.c:4490 #18 0x00005555556ba22d in x_frame_rehighlight (dpyinfo=0x55555626d6c0) at xterm.c:4852 #19 0x00005555556b98fc in x_new_focus_frame (dpyinfo=0x55555626d6c0, frame=0x0) at xterm.c:4520 #20 0x00005555556b9a3d in x_focus_changed (type=10, state=2, dpyinfo=0x55555626d6c0, frame=0x555556625468, bufp=0x7fffffffa0d0) at xterm.c:4554 #21 0x00005555556ba0a6 in x_detect_focus_change (dpyinfo=0x55555626d6c0, frame=0x555556625468, event=0x7fffffffa840, bufp=0x7fffffffa0d0) at xterm.c:4787 #22 0x00005555556c0235 in handle_one_xevent (dpyinfo=0x55555626d6c0, event=0x7fffffffa840, finish=0x555555c901d4 , hold_quit=0x7fffffffab50) at xterm.c:8810 #23 0x00005555556bde28 in event_handler_gdk (gxev=0x7fffffffa840, ev=0x55555cccf0c0, data=0x0) at xterm.c:7768 #24 0x00007ffff75f780f in () at /usr/lib/libgdk-3.so.0 #25 0x00007ffff75fb3cb in () at /usr/lib/libgdk-3.so.0 #26 0x00007ffff759f15b in gdk_display_get_event () at /usr/lib/libgdk-3.so.0 #27 0x00007ffff75fb104 in () at /usr/lib/libgdk-3.so.0 #28 0x00007ffff6fcb8f4 in g_main_context_dispatch () at /usr/lib/libglib-2.0.so.0 #29 0x00007ffff701f821 in () at /usr/lib/libglib-2.0.so.0 #30 0x00007ffff6fca121 in g_main_context_iteration () at /usr/lib/libglib-2.0.so.0 #31 0x00007ffff784e2c7 in gtk_main_iteration () at /usr/lib/libgtk-3.so.0 #32 0x00005555556c1821 in XTread_socket (terminal=0x5555560b7460, hold_quit=0x7fffffffab50) at xterm.c:9395 #33 0x000055555570f3a2 in gobble_input () at keyboard.c:6890 #34 0x000055555570f894 in handle_async_input () at keyboard.c:7121 #35 0x000055555570f8dd in process_pending_signals () at keyboard.c:7139 #36 0x000055555570f9cf in unblock_input_to (level=0) at keyboard.c:7162 #37 0x000055555570fa4c in unblock_input () at keyboard.c:7187 #38 0x000055555578f49a in garbage_collect () at alloc.c:6121 #39 0x000055555578efe7 in maybe_garbage_collect () at alloc.c:5964 #40 0x00005555557bb292 in maybe_gc () at lisp.h:5041 #41 0x00005555557c12d6 in Ffuncall (nargs=2, args=0x7fffffffad68) at eval.c:2793 #42 0x000055555580f7d6 in exec_byte_code ... -------------- For breakpoints, I am doing the following: 1) make a global static variable in alloc.c: static int enable_gc_trace = 0; 2) in garbage_collect(), 'enable_gc_trace++' when it starts and 'enable_gc_trace--' when it ends. I just wrapped the call to unblock_input(), but you could widen that window. 3) run in gdb with conditional breakpoints on GC and longjmp functions: b siglongjmp if enable_gc_trace > 0 b internal_catch if enable_gc_trace > 0 b internal_catch_all if enable_gc_trace > 0 b maybe_garbage_collect if enable_gc_trace > 0 -Trevor