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#37321: 27.0.50; Excessive gc in a use case (el-search) Date: Sat, 7 Sep 2019 18:11:53 -0700 Organization: UCLA Computer Science Department Message-ID: References: <87lfv1pm5x.fsf@web.de> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------2B523541BD342A176D81641C" Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="51395"; 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: 37321@debbugs.gnu.org To: Michael Heerdegen Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sun Sep 08 03:13:10 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 1i6llO-000DEa-FP for geb-bug-gnu-emacs@m.gmane.org; Sun, 08 Sep 2019 03:13:10 +0200 Original-Received: from localhost ([::1]:46506 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i6llN-0008QA-EA for geb-bug-gnu-emacs@m.gmane.org; Sat, 07 Sep 2019 21:13:09 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:50960) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i6llH-0008Q4-Bf for bug-gnu-emacs@gnu.org; Sat, 07 Sep 2019 21:13:04 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i6llG-0000Mv-7l for bug-gnu-emacs@gnu.org; Sat, 07 Sep 2019 21:13:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:57676) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1i6llG-0000Ml-1t for bug-gnu-emacs@gnu.org; Sat, 07 Sep 2019 21:13:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1i6llF-0007y7-RQ for bug-gnu-emacs@gnu.org; Sat, 07 Sep 2019 21:13:01 -0400 X-Loop: help-debbugs@gnu.org In-Reply-To: <87lfv1pm5x.fsf@web.de> Resent-From: Paul Eggert Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 08 Sep 2019 01:13:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 37321 X-GNU-PR-Package: emacs Original-Received: via spool by 37321-submit@debbugs.gnu.org id=B37321.156790512830563 (code B ref 37321); Sun, 08 Sep 2019 01:13:01 +0000 Original-Received: (at 37321) by debbugs.gnu.org; 8 Sep 2019 01:12:08 +0000 Original-Received: from localhost ([127.0.0.1]:38264 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1i6lkN-0007wt-SM for submit@debbugs.gnu.org; Sat, 07 Sep 2019 21:12:08 -0400 Original-Received: from zimbra.cs.ucla.edu ([131.179.128.68]:51044) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1i6lkL-0007wQ-U4 for 37321@debbugs.gnu.org; Sat, 07 Sep 2019 21:12:06 -0400 Original-Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id A00B1160211; Sat, 7 Sep 2019 18:12:00 -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 KwyT7K93xefj; Sat, 7 Sep 2019 18:11:54 -0700 (PDT) Original-Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 1E26116021D; Sat, 7 Sep 2019 18:11:54 -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 51YhnQ2QgjNS; Sat, 7 Sep 2019 18:11:53 -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 D444F160211; Sat, 7 Sep 2019 18:11:53 -0700 (PDT) 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:166290 Archived-At: This is a multi-part message in MIME format. --------------2B523541BD342A176D81641C Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Thanks for reporting the bug. I installed the attached patch; please give it a try. --------------2B523541BD342A176D81641C Content-Type: text/x-patch; name="0001-Fix-bug-when-gc-cons-percentage-is-bumped-to-0.8.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0001-Fix-bug-when-gc-cons-percentage-is-bumped-to-0.8.patch" >From 4c31e7c3e4e70b38ab51a99d61e215aefe0190dd Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sat, 7 Sep 2019 18:08:12 -0700 Subject: [PATCH] Fix bug when gc-cons-percentage is bumped to 0.8 Problem reported by Michael Heerdegen (Bug#37321). * src/alloc.c (gc_threshold): New static var. (bump_consing_until_gc): Change args from DIFF to THRESHOLD and PERCENTAGE. All uses changed. When accounting for a changed gc-cons-percentage, do not assume that total_bytes_of_live_objects returns the same value now that it did the last time we were called. --- src/alloc.c | 45 ++++++++++++++++++++++++++++----------------- 1 file changed, 28 insertions(+), 17 deletions(-) diff --git a/src/alloc.c b/src/alloc.c index 5fc515f33b..be98cfd5f5 100644 --- a/src/alloc.c +++ b/src/alloc.c @@ -297,6 +297,10 @@ #define PUREBEG (char *) pure static intptr_t garbage_collection_inhibited; +/* The GC threshold in bytes, the last time it was calculated + from gc-cons-threshold and gc-cons-percentage. */ +static intmax_t gc_threshold; + /* If nonzero, this is a warning delivered by malloc and not yet displayed. */ @@ -5808,15 +5812,28 @@ consing_threshold (intmax_t threshold, Lisp_Object percentage) } } -/* Increment consing_until_gc by DIFF, avoiding overflow. */ +/* Adjust consing_until_gc, assuming gc-cons-threshold is THRESHOLD and + gc-cons-percentage is PERCENTAGE. */ static Lisp_Object -bump_consing_until_gc (intmax_t diff) +bump_consing_until_gc (intmax_t threshold, Lisp_Object percentage) { /* 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; + if (0 <= consing_until_gc) + { + threshold = consing_threshold (threshold, percentage); + intmax_t sum; + if (INT_ADD_WRAPV (consing_until_gc, threshold - gc_threshold, &sum)) + { + /* Scale the threshold down so that consing_until_gc does + not overflow. */ + sum = INTMAX_MAX; + threshold = INTMAX_MAX - consing_until_gc + gc_threshold; + } + consing_until_gc = sum; + gc_threshold = threshold; + } + return Qnil; } @@ -5825,13 +5842,10 @@ bump_consing_until_gc (intmax_t diff) watch_gc_cons_threshold (Lisp_Object symbol, Lisp_Object newval, Lisp_Object operation, Lisp_Object where) { - Lisp_Object percentage = Vgc_cons_percentage; intmax_t threshold; - intmax_t diff = (INTEGERP (newval) && integer_to_intmax (newval, &threshold) - ? (consing_threshold (threshold, percentage) - - consing_threshold (gc_cons_threshold, percentage)) - : 0); - return bump_consing_until_gc (diff); + if (! (INTEGERP (newval) && integer_to_intmax (newval, &threshold))) + return Qnil; + return bump_consing_until_gc (threshold, Vgc_cons_percentage); } /* Watch changes to gc-cons-percentage. */ @@ -5839,10 +5853,7 @@ watch_gc_cons_threshold (Lisp_Object symbol, Lisp_Object newval, watch_gc_cons_percentage (Lisp_Object symbol, Lisp_Object newval, Lisp_Object operation, Lisp_Object where) { - intmax_t threshold = gc_cons_threshold; - intmax_t diff = (consing_threshold (threshold, newval) - - consing_threshold (threshold, Vgc_cons_percentage)); - return bump_consing_until_gc (diff); + return bump_consing_until_gc (gc_cons_threshold, newval); } /* Subroutine of Fgarbage_collect that does most of the work. */ @@ -5987,8 +5998,8 @@ garbage_collect_1 (struct gcstat *gcst) unblock_input (); - consing_until_gc = consing_threshold (gc_cons_threshold, - Vgc_cons_percentage); + consing_until_gc = gc_threshold + = consing_threshold (gc_cons_threshold, Vgc_cons_percentage); if (garbage_collection_messages && NILP (Vmemory_full)) { -- 2.17.1 --------------2B523541BD342A176D81641C--