From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: GC Date: Mon, 11 Jul 2005 13:00:34 -0400 Message-ID: References: <200506182319.j5INJWF08937@raven.dms.auburn.edu> <200506190015.j5J0FQk09223@raven.dms.auburn.edu> <200506190037.j5J0b9Y09287@raven.dms.auburn.edu> <200506191747.j5JHlha11521@raven.dms.auburn.edu> <200506202312.j5KNCct19091@raven.dms.auburn.edu> <200506212058.j5LKw5P23961@raven.dms.auburn.edu> <874qbqh0lm.fsf@jurta.org> <87mzpf3a5v.fsf_-_@jurta.org> <87y88zv3vm.fsf@jurta.org> <877jgfyu5t.fsf-monnier+emacs@gnu.org> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1121102546 13552 80.91.229.2 (11 Jul 2005 17:22:26 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Mon, 11 Jul 2005 17:22:26 +0000 (UTC) Cc: juri@jurta.org, eliz@gnu.org, emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Jul 11 19:22:18 2005 Return-path: Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1Ds1yi-0004hH-Js for ged-emacs-devel@m.gmane.org; Mon, 11 Jul 2005 19:22:00 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Ds20I-0001N4-DH for ged-emacs-devel@m.gmane.org; Mon, 11 Jul 2005 13:23:38 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Ds1uQ-0007Ah-NU for emacs-devel@gnu.org; Mon, 11 Jul 2005 13:17:35 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Ds1uK-000781-21 for emacs-devel@gnu.org; Mon, 11 Jul 2005 13:17:28 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Ds1uJ-00070E-NW for emacs-devel@gnu.org; Mon, 11 Jul 2005 13:17:27 -0400 Original-Received: from [132.204.24.67] (helo=mercure.iro.umontreal.ca) by monty-python.gnu.org with esmtp (Exim 4.34) id 1Ds1lY-0000RI-0B; Mon, 11 Jul 2005 13:08:25 -0400 Original-Received: from hidalgo.iro.umontreal.ca (hidalgo.iro.umontreal.ca [132.204.27.50]) by mercure.iro.umontreal.ca (Postfix) with ESMTP id E94012CF43E; Mon, 11 Jul 2005 13:00:37 -0400 (EDT) Original-Received: from asado.iro.umontreal.ca (asado.iro.umontreal.ca [132.204.24.84]) by hidalgo.iro.umontreal.ca (Postfix) with ESMTP id 4AB9A4AC00A; Mon, 11 Jul 2005 13:00:34 -0400 (EDT) Original-Received: by asado.iro.umontreal.ca (Postfix, from userid 20848) id 2C6FDE6C1D; Mon, 11 Jul 2005 13:00:34 -0400 (EDT) Original-To: rms@gnu.org In-Reply-To: (Richard M. Stallman's message of "Tue, 28 Jun 2005 17:29:45 -0400") User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (gnu/linux) X-DIRO-MailScanner-Information: Please contact the ISP for more information X-DIRO-MailScanner: Found to be clean X-DIRO-MailScanner-SpamCheck: n'est pas un polluriel, SpamAssassin (score=-4.849, requis 5, autolearn=not spam, AWL 0.05, BAYES_00 -4.90) X-MailScanner-From: monnier@iro.umontreal.ca X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:40789 >>>>> "Richard" == Richard M Stallman writes: > 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. > I agree. Would you like to do it? How 'bout the patch below. It sets the default value to 0.1 (i.e. 10%), which means that the current 400KB threshold (on 32 bit systems) is used until the heap grows to 4MB. A 4MB heap is not enormous, but it's not small either (my one week old running Emacs process with 14 frames and 30 buffers has a heap of about 6MB). This notion of "heap size" is not exactly what you'd expect (it ignores buffers and a few other such things) but it reflects fairly well the part of the heap that the GC actually cares about. Stefan --- orig/src/alloc.c +++ mod/src/alloc.c @@ -180,6 +180,8 @@ /* Number of bytes of consing since GC before another GC should be done. */ EMACS_INT gc_cons_threshold; +static EMACS_INT gc_cons_min_threshold; +static Lisp_Object Vgc_cons_percentage; /* Nonzero during GC. */ @@ -4966,8 +4968,29 @@ gc_in_progress = 0; consing_since_gc = 0; - if (gc_cons_threshold < 10000) - gc_cons_threshold = 10000; + if (gc_cons_min_threshold < 10000) + gc_cons_min_threshold = 10000; + + gc_cons_threshold = gc_cons_min_threshold; + + if (FLOATP (Vgc_cons_percentage)) + { /* Set gc_cons_threshold. */ + EMACS_INT total = 0; + EMACS_INT threshold; + total += total_conses * sizeof (struct Lisp_Cons); + total += total_symbols * sizeof (struct Lisp_Symbol); + total += total_markers * sizeof (union Lisp_Misc); + total += total_string_size; + total += total_vectors * sizeof (struct Lisp_Vector); + total += total_vector_size * sizeof (Lisp_Object); + total += total_floats * sizeof (struct Lisp_Float); + total += total_intervals * sizeof (struct interval); + total += total_strings * sizeof (struct Lisp_String); + + threshold = total * XFLOAT_DATA (Vgc_cons_percentage); + if (threshold > gc_cons_threshold) + gc_cons_threshold = threshold; + } if (garbage_collection_messages) { @@ -6087,7 +6110,7 @@ byte_stack_list = 0; staticidx = 0; consing_since_gc = 0; - gc_cons_threshold = 100000 * sizeof (Lisp_Object); + gc_cons_min_threshold = 100000 * sizeof (Lisp_Object); #ifdef VIRT_ADDR_VARIES malloc_sbrk_unused = 1<<22; /* A large number */ malloc_sbrk_used = 100000; /* as reasonable as any number */ @@ -6124,7 +6147,7 @@ void syms_of_alloc () { - DEFVAR_INT ("gc-cons-threshold", &gc_cons_threshold, + DEFVAR_INT ("gc-cons-threshold", &gc_cons_min_threshold, doc: /* *Number of bytes of consing between garbage collections. Garbage collection can happen automatically once this many bytes have been allocated since the last garbage collection. All data types count. @@ -6132,7 +6155,15 @@ Garbage collection happens automatically only when `eval' is called. By binding this temporarily to a large number, you can effectively -prevent garbage collection during a part of the program. */); +prevent garbage collection during a part of the program. +See also `gc-cons-percentage'. */); + + DEFVAR_LISP ("gc-cons-percentage", &Vgc_cons_percentage, + doc: /* *Portion of the heap used for allocation. +Garbage collection can happen automatically once this portion of the heap +has been allocated since the last garbage collection. +If this portion is smaller than `gc-cons-threshold', this is ignored. */); + Vgc_cons_percentage = make_float (0.1); DEFVAR_INT ("pure-bytes-used", &pure_bytes_used, doc: /* Number of bytes of sharable Lisp data allocated so far. */);