unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Jim Blandy <jimb@red-bean.com>
To: Emacs Devel <emacs-devel@gnu.org>
Subject: Figuring out what's doing so much allocation
Date: Fri, 10 Feb 2012 11:22:40 -0800	[thread overview]
Message-ID: <CAHgb+0nidz985uxRw0iZr7ttR3-TUxQo1jO5+fPjhWAKM_C+DQ@mail.gmail.com> (raw)

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

I was running into a problem (now fixed) in which gc was running
constantly, so I put together the following hack to figure out who was
doing the allocation. Set gc-quit-frequency to something like 20, and
then set debug-on-quit, and you'll get a backtrace every 20th gc. It's
hardly precise, but often one just needs a hint to suss out the cause.

[-- Attachment #2: gc-quit-frequency.patch --]
[-- Type: text/x-patch, Size: 1076 bytes --]

diff --git a/src/alloc.c b/src/alloc.c
index 044e750..3b98301 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -4998,6 +4998,14 @@ returns nil, because real GC can't be done.  */)
   int count = SPECPDL_INDEX ();
   EMACS_TIME t1, t2, t3;
 
+  if (gc_quit_frequency) {
+    static int counter = 0;
+    if (--counter == 0)
+      Vquit_flag = Qt;
+    if (counter <= 0)
+      counter = gc_quit_frequency;
+  }
+
   if (abort_on_gc)
     abort ();
 
@@ -6359,6 +6367,7 @@ init_alloc_once (void)
   byte_stack_list = 0;
   staticidx = 0;
   consing_since_gc = 0;
+  gc_quit_frequency = 0;
   gc_cons_threshold = 100000 * sizeof (Lisp_Object);
   gc_relative_threshold = 0;
 }
@@ -6380,6 +6389,9 @@ init_alloc (void)
 void
 syms_of_alloc (void)
 {
+  DEFVAR_INT ("gc-quit-frequency", gc_quit_frequency,
+              doc: /* *Quit every this many GC's. If zero, don't. */);
+
   DEFVAR_INT ("gc-cons-threshold", gc_cons_threshold,
 	      doc: /* *Number of bytes of consing between garbage collections.
 Garbage collection can happen automatically once this many bytes have been

             reply	other threads:[~2012-02-10 19:22 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-02-10 19:22 Jim Blandy [this message]
2012-03-21  3:49 ` Figuring out what's doing so much allocation Stefan Monnier

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=CAHgb+0nidz985uxRw0iZr7ttR3-TUxQo1jO5+fPjhWAKM_C+DQ@mail.gmail.com \
    --to=jimb@red-bean.com \
    --cc=emacs-devel@gnu.org \
    /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).