From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Paul Eggert Newsgroups: gmane.emacs.bugs Subject: bug#37006: Emacs 27 master consumes more memory than 26 and freezes regularly Date: Tue, 3 Sep 2019 13:11:03 -0700 Organization: UCLA Computer Science Department Message-ID: <9a06837b-eedd-808c-01e8-97ac504032e4@cs.ucla.edu> References: <87mufpfid6.fsf@gmail.com> <83r2518fhz.fsf@gnu.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------8DA7481FB350B1D4355642B5" Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="83079"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 Cc: Joseph Mingrone , Mattias =?UTF-8?Q?Engdeg=C3=A5rd?= , 37006-done@debbugs.gnu.org To: Eli Zaretskii , Akater Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Tue Sep 03 22:12:12 2019 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1i5F9w-000LWz-J5 for geb-bug-gnu-emacs@m.gmane.org; Tue, 03 Sep 2019 22:12:12 +0200 Original-Received: from localhost ([::1]:50530 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i5F9v-0007N2-9K for geb-bug-gnu-emacs@m.gmane.org; Tue, 03 Sep 2019 16:12:11 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:47546) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i5F9n-0007MR-M5 for bug-gnu-emacs@gnu.org; Tue, 03 Sep 2019 16:12:04 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i5F9m-0001B2-CK for bug-gnu-emacs@gnu.org; Tue, 03 Sep 2019 16:12:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:51751) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1i5F9m-0001Ao-7N for bug-gnu-emacs@gnu.org; Tue, 03 Sep 2019 16:12:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1i5F9l-0000SU-W6 for bug-gnu-emacs@gnu.org; Tue, 03 Sep 2019 16:12:02 -0400 Resent-From: Paul Eggert Original-Sender: "Debbugs-submit" Resent-To: bug-gnu-emacs@gnu.org Resent-Date: Tue, 03 Sep 2019 20:12:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: cc-closed 37006 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Mail-Followup-To: 37006@debbugs.gnu.org, eggert@cs.ucla.edu, jrm@ftfl.ca Original-Received: via spool by 37006-done@debbugs.gnu.org id=D37006.15675414751692 (code D ref 37006); Tue, 03 Sep 2019 20:12:01 +0000 Original-Received: (at 37006-done) by debbugs.gnu.org; 3 Sep 2019 20:11:15 +0000 Original-Received: from localhost ([127.0.0.1]:60570 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1i5F90-0000RE-I3 for submit@debbugs.gnu.org; Tue, 03 Sep 2019 16:11:14 -0400 Original-Received: from zimbra.cs.ucla.edu ([131.179.128.68]:60720) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1i5F8w-0000Qw-7I for 37006-done@debbugs.gnu.org; Tue, 03 Sep 2019 16:11:11 -0400 Original-Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 9F3F516008D; Tue, 3 Sep 2019 13:11:04 -0700 (PDT) Original-Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id YB2jq8NLSrmE; Tue, 3 Sep 2019 13:11:03 -0700 (PDT) Original-Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 98BD21600AA; Tue, 3 Sep 2019 13:11:03 -0700 (PDT) X-Virus-Scanned: amavisd-new at zimbra.cs.ucla.edu Original-Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id xJW852S4F1Al; Tue, 3 Sep 2019 13:11:03 -0700 (PDT) Original-Received: from [192.168.1.9] (cpe-23-242-74-103.socal.res.rr.com [23.242.74.103]) by zimbra.cs.ucla.edu (Postfix) with ESMTPSA id 5F10E16008D; Tue, 3 Sep 2019 13:11:03 -0700 (PDT) In-Reply-To: Content-Language: en-US X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.51.188.43 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.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:166179 Archived-At: This is a multi-part message in MIME format. --------------8DA7481FB350B1D4355642B5 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Paul Eggert wrote: > Eli Zaretskii wrote: >> once >> gc-cons-threshold is set to a large value, it effectively disables GC >> for the rest of the session, even if after that gc-cons-threshold is >> reset back > > Yes, that's next on my list of things to look at, after untangling this XDG > configuration mess. Although I haven't finished untangling the XDG configuration mess, I did get some time free to attack the gc-cons-threshold issue and installed the attached. As this should fix the problem reported in Bug#37006 I'm boldly closing that bug report. --------------8DA7481FB350B1D4355642B5 Content-Type: text/x-patch; name="0001-Sync-consing_until_gc-with-gc-cons-threshold.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="0001-Sync-consing_until_gc-with-gc-cons-threshold.patch" >From 97ffa339b6d67cebcbefbdfaa2880214adab639c Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Tue, 3 Sep 2019 13:03:34 -0700 Subject: [PATCH] Sync consing_until_gc with gc-cons-threshold Add watchers for gc-cons-threshold and gc-cons-percentage that update consing_until_gc accordingly. Suggested by Eli Zaretskii (Bug#37006#52). * src/alloc.c (consing_threshold, bump_consing_until_gc) (watch_gc_cons_threshold, watch_gc_cons_percentage): New functions. (garbage_collect_1): Use consing_threshold. (syms_of_alloc): Arrange to watch gc-cons-threshold and gc-cons-percentage. --- src/alloc.c | 100 ++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 81 insertions(+), 19 deletions(-) diff --git a/src/alloc.c b/src/alloc.c index 39964c4b29..5f8ef0a5dd 100644 --- a/src/alloc.c +++ b/src/alloc.c @@ -5781,6 +5781,68 @@ mark_and_sweep_weak_table_contents (void) } } +/* Return the number of bytes to cons between GCs, assuming + gc-cons-threshold is THRESHOLD and gc-cons-percentage is + GC_CONS_PERCENTAGE. */ +static intmax_t +consing_threshold (intmax_t threshold, Lisp_Object gc_cons_percentage) +{ + if (!NILP (Vmemory_full)) + return memory_full_cons_threshold; + else + { + threshold = max (threshold, GC_DEFAULT_THRESHOLD / 10); + if (FLOATP (gc_cons_percentage)) + { + double tot = (XFLOAT_DATA (gc_cons_percentage) + * total_bytes_of_live_objects ()); + if (threshold < tot) + { + if (tot < INTMAX_MAX) + threshold = tot; + else + threshold = INTMAX_MAX; + } + } + return threshold; + } +} + +/* Increment consing_until_gc by DIFF, avoiding overflow. */ +static Lisp_Object +bump_consing_until_gc (intmax_t diff) +{ + /* If consing_until_gc is negative leave it alone, since this prevents + negative integer overflow and a GC would have been done soon anyway. */ + if (0 <= consing_until_gc + && INT_ADD_WRAPV (consing_until_gc, diff, &consing_until_gc)) + consing_until_gc = INTMAX_MAX; + return Qnil; +} + +/* Watch changes to gc-cons-threshold. */ +static Lisp_Object +watch_gc_cons_threshold (Lisp_Object symbol, Lisp_Object newval, + Lisp_Object operation, Lisp_Object where) +{ + intmax_t new_threshold; + int diff = (INTEGERP (newval) && integer_to_intmax (newval, &new_threshold) + ? (consing_threshold (new_threshold, Vgc_cons_percentage) + - consing_threshold (gc_cons_threshold, Vgc_cons_percentage)) + : 0); + return bump_consing_until_gc (diff); +} + +/* Watch changes to gc-cons-percentage. */ +static Lisp_Object +watch_gc_cons_percentage (Lisp_Object symbol, Lisp_Object newval, + Lisp_Object operation, Lisp_Object where) +{ + int diff = (consing_threshold (consing_until_gc, newval) + - consing_threshold (consing_until_gc, Vgc_cons_percentage)); + return bump_consing_until_gc (diff); +} + /* Subroutine of Fgarbage_collect that does most of the work. */ static bool garbage_collect_1 (struct gcstat *gcst) @@ -5923,25 +5985,8 @@ garbage_collect_1 (struct gcstat *gcst) unblock_input (); - if (!NILP (Vmemory_full)) - consing_until_gc = memory_full_cons_threshold; - else - { - intmax_t threshold = max (gc_cons_threshold, GC_DEFAULT_THRESHOLD / 10); - if (FLOATP (Vgc_cons_percentage)) - { - double tot = (XFLOAT_DATA (Vgc_cons_percentage) - * total_bytes_of_live_objects ()); - if (threshold < tot) - { - if (tot < INTMAX_MAX) - threshold = tot; - else - threshold = INTMAX_MAX; - } - } - consing_until_gc = threshold; - } + consing_until_gc = consing_threshold (gc_cons_threshold, + Vgc_cons_percentage); if (garbage_collection_messages && NILP (Vmemory_full)) { @@ -7362,6 +7407,7 @@ do hash-consing of the objects allocated to pure space. */); DEFSYM (Qheap, "heap"); DEFSYM (QAutomatic_GC, "Automatic GC"); + DEFSYM (Qgc_cons_percentage, "gc-cons-percentage"); DEFSYM (Qgc_cons_threshold, "gc-cons-threshold"); DEFSYM (Qchar_table_extra_slots, "char-table-extra-slots"); @@ -7395,6 +7441,22 @@ N should be nonnegative. */); defsubr (&Smemory_info); defsubr (&Smemory_use_counts); defsubr (&Ssuspicious_object); + + Lisp_Object watcher; + + static union Aligned_Lisp_Subr Swatch_gc_cons_threshold = + {{{ PSEUDOVECTOR_FLAG | (PVEC_SUBR << PSEUDOVECTOR_AREA_BITS) }, + { .a4 = watch_gc_cons_threshold }, + 4, 4, "watch_gc_cons_threshold", 0, 0}}; + XSETSUBR (watcher, &Swatch_gc_cons_threshold.s); + Fadd_variable_watcher (Qgc_cons_threshold, watcher); + + static union Aligned_Lisp_Subr Swatch_gc_cons_percentage = + {{{ PSEUDOVECTOR_FLAG | (PVEC_SUBR << PSEUDOVECTOR_AREA_BITS) }, + { .a4 = watch_gc_cons_percentage }, + 4, 4, "watch_gc_cons_percentage", 0, 0}}; + XSETSUBR (watcher, &Swatch_gc_cons_percentage.s); + Fadd_variable_watcher (Qgc_cons_percentage, watcher); } #ifdef HAVE_X_WINDOWS -- 2.17.1 --------------8DA7481FB350B1D4355642B5--