unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Paul Eggert <eggert@cs.ucla.edu>
To: Michael Heerdegen <michael_heerdegen@web.de>
Cc: 37321@debbugs.gnu.org
Subject: bug#37321: 27.0.50; Excessive gc in a use case (el-search)
Date: Sat, 7 Sep 2019 18:11:53 -0700	[thread overview]
Message-ID: <fe4db180-5223-a75b-0b73-f0715616396d@cs.ucla.edu> (raw)
In-Reply-To: <87lfv1pm5x.fsf@web.de>

[-- Attachment #1: Type: text/plain, Size: 85 bytes --]

Thanks for reporting the bug. I installed the attached patch; please give it a try.


[-- Attachment #2: 0001-Fix-bug-when-gc-cons-percentage-is-bumped-to-0.8.patch --]
[-- Type: text/x-patch, Size: 3907 bytes --]

From 4c31e7c3e4e70b38ab51a99d61e215aefe0190dd Mon Sep 17 00:00:00 2001
From: Paul Eggert <eggert@cs.ucla.edu>
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


  parent reply	other threads:[~2019-09-08  1:11 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-06 13:52 bug#37321: 27.0.50; Excessive gc in a use case (el-search) Michael Heerdegen
2019-09-07 14:23 ` Michael Heerdegen
2019-09-07 15:30   ` Michael Heerdegen
2019-09-08  1:11 ` Paul Eggert [this message]
2019-09-08 14:52   ` Michael Heerdegen
2019-09-08 15:25     ` Michael Heerdegen
2019-09-14  8:04       ` Paul Eggert
2019-09-14  8:37         ` Eli Zaretskii
2019-09-14  8:52           ` Paul Eggert
2019-09-14  9:57             ` Eli Zaretskii
2019-09-14 17:57               ` Paul Eggert
2019-09-14 18:16                 ` Eli Zaretskii
2019-09-15  4:33             ` Richard Stallman
2019-09-16 23:53         ` Michael Heerdegen
2019-09-17  0:55           ` Paul Eggert
2019-09-21  0:41             ` Michael Heerdegen
2019-09-21  0:46               ` Michael Heerdegen
2019-09-21  6:19                 ` Paul Eggert
2019-09-17 12:47           ` Noam Postavsky
2019-09-21  0:44             ` Michael Heerdegen
2019-09-25  9:42         ` Michael Heerdegen
2019-09-25 20:37           ` Paul Eggert
2019-09-26 11:42             ` Michael Heerdegen
2019-09-26 12:14               ` Eli Zaretskii
2019-09-26 13:03                 ` Michael Heerdegen
2019-10-08  8:43                 ` Michael Heerdegen
2019-10-08  9:09                   ` Eli Zaretskii
2019-10-08  9:11                     ` Michael Heerdegen
2019-10-08  9:19                       ` Eli Zaretskii
2019-10-08 11:12                         ` Michael Heerdegen
2019-10-08 12:11                           ` Eli Zaretskii
2019-10-08 12:38                             ` Michael Heerdegen
2019-10-08 13:03                               ` Eli Zaretskii
2019-10-09 14:47                                 ` Michael Heerdegen
2019-10-09 15:33                                   ` Eli Zaretskii
2019-10-09 20:53                                     ` Paul Eggert
2019-10-10 10:58                                     ` Michael Heerdegen
2019-10-08  9:22                       ` Michael Heerdegen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=fe4db180-5223-a75b-0b73-f0715616396d@cs.ucla.edu \
    --to=eggert@cs.ucla.edu \
    --cc=37321@debbugs.gnu.org \
    --cc=michael_heerdegen@web.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).