unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: Juri Linkov <juri@jurta.org>, emacs-devel@gnu.org
Subject: Re: GC
Date: Tue, 28 Jun 2005 00:55:00 -0400	[thread overview]
Message-ID: <877jgfyu5t.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <uy88yg41l.fsf@gnu.org> (Eli Zaretskii's message of "Sat, 25 Jun 2005 11:48:54 +0200")

> think, but then again it might not: IIRC, Emacs always does a GC
> before it asks the OS for more heap.  So you might see the message

I don't think this is true.  GC should only ever be called from eval
or funcall.  Several parts of the code assume that Fcons cannot call the GC,
for example.

In any case, here is my understanding of the situation:

The time taken by a single GC is roughly proportional to the total
(live+dead) heap size: the mark phase is proportional to the live-data size,
but the subsequent sweep phase is proportional to the total heap size.

Total heap size at the time of a GC is roughly equal to live-data +
gc-cons-threshold + unused-allocated.  The unused-allocated part of the
memory is basically due to fragmentation.

The frequency of GC is inversely proportional to gc-cons-threshold.
So the total portion of time used up by GC (the GC-overhead) is basically
proportional to:

   live-data + gc-cons-threshold + fragmentation
   ---------------------------------------------
               gc-cons-threshold

with a fixed gc-cons-threshold (as we have now), this boils down to

     live-data + fragmentation
     ------------------------- + 1
         gc-cons-threshold

So the GC-overhead currently grows with the live-data and with the
fragmentation.  This is one of the reasons why with a large heap, Emacs
tends to slow down.

Looking at the above equation one might think "let's bump gc-cons-threshold
way up" to make GC much cheaper.  The problem with it is that it tends to
increase fragmentation by delaying the reclaiming of memory (most serious
studies of memory fragmentation with non-moving memory allocator indicate
that an important factor to reduce fragmentation is prompt reclamation of
memory).

Making gc-cons-threshold proportional to the installed RAM sounds like a bad
idea to me: it's bound to be too small for some cases and much too large
for others.

The normal way to keep GC-overhead under control is to grow
gc-cons-threshold together with the heap size, such that the GC-overhead
stays constant (by making GCs less frequent when they get more
time-consuming).  Of course this may not always be best because by growing
gc-cons-threshold we may increase fragmentation, but "the best" is simply
not doable (not with a simple mark&sweep anyway).

I'd had already suggested a change to grow gc-cons-threshold as the heap
grows (a long time ago), and I see that XEmacs's gc-cons-percentage is
clean interface to such a feature.  I think we should introduce this
variable and give it a good non-zero default value.


        Stefan

  parent reply	other threads:[~2005-06-28  4:55 UTC|newest]

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-06-18 23:19 lists.texi Luc Teirlinck
2005-06-19  0:01 ` lists.texi Luc Teirlinck
2005-06-19  0:15 ` lists.texi Luc Teirlinck
2005-06-19  0:37   ` lists.texi Luc Teirlinck
2005-06-19  6:37     ` lists.texi David Kastrup
2005-06-19 15:55     ` lists.texi Richard Stallman
2005-06-19 17:47       ` lists.texi Luc Teirlinck
2005-06-20 17:52         ` lists.texi Richard Stallman
2005-06-20 23:12           ` lists.texi Luc Teirlinck
2005-06-21  5:13             ` lists.texi David Kastrup
2005-06-21 15:13             ` lists.texi Richard M. Stallman
2005-06-21 16:35             ` lists.texi Thien-Thi Nguyen
2005-06-21 19:00               ` lists.texi Luc Teirlinck
2005-06-21 21:56                 ` lists.texi Thien-Thi Nguyen
2005-06-21 19:45               ` lists.texi Luc Teirlinck
2005-06-21 20:58               ` lists.texi Luc Teirlinck
2005-06-21 22:09                 ` lists.texi Thien-Thi Nguyen
2005-06-22 16:28                 ` lists.texi Juri Linkov
2005-06-22 19:27                   ` lists.texi Eli Zaretskii
2005-06-22 18:44                     ` lists.texi Luc Teirlinck
2005-06-22 20:25                     ` lists.texi Luc Teirlinck
2005-06-23 16:53                       ` lists.texi Richard M. Stallman
2005-06-24 19:02                       ` GC (was: lists.texi) Juri Linkov
2005-06-24 19:02                     ` Juri Linkov
2005-06-24 21:08                       ` Eli Zaretskii
2005-06-24 21:54                         ` Juri Linkov
2005-06-24 23:52                           ` Luc Teirlinck
2005-06-25  0:51                             ` Miles Bader
2005-06-25  9:48                           ` Eli Zaretskii
2005-06-25 11:58                             ` GC Adrian Aichner
2005-06-25 12:53                               ` GC Miles Bader
2005-06-25 21:53                                 ` GC Adrian Aichner
2005-06-26  0:02                                   ` GC Miles Bader
2005-06-26  8:20                                     ` GC Adrian Aichner
2005-06-26 18:51                                       ` GC Eli Zaretskii
2005-06-26 23:43                                         ` GC Juri Linkov
2005-06-27  5:38                                         ` GC Richard M. Stallman
2005-06-26 22:42                                       ` GC Richard M. Stallman
2005-06-25 12:15                             ` GC (was: lists.texi) Miles Bader
2005-06-25 13:10                               ` GC Gaëtan LEURENT
2005-06-25 14:48                                 ` GC Eli Zaretskii
2005-06-25 14:45                               ` GC (was: lists.texi) Eli Zaretskii
2005-06-25 16:40                               ` Richard M. Stallman
2005-06-28  4:55                             ` Stefan Monnier [this message]
2005-06-28 21:29                               ` GC Richard M. Stallman
2005-07-11 17:00                                 ` GC 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=877jgfyu5t.fsf-monnier+emacs@gnu.org \
    --to=monnier@iro.umontreal.ca \
    --cc=emacs-devel@gnu.org \
    --cc=juri@jurta.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).