From 96f077ad7141a3900c623d485cd9a31f6d67acf7 Mon Sep 17 00:00:00 2001 From: Stefan Monnier Date: Wed, 13 Jul 2005 05:28:37 +0000 Subject: (gc_cons_combined_threshold, Vgc_cons_percentage): New vars. (Fgarbage_collect, init_alloc_once): Set gc_cons_combined_threshold. (syms_of_alloc): Declare gc-cons-percentage. --- src/alloc.c | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) (limited to 'src/alloc.c') diff --git a/src/alloc.c b/src/alloc.c index f3c43106087..a8cf897ede2 100644 --- a/src/alloc.c +++ b/src/alloc.c @@ -175,6 +175,8 @@ EMACS_INT strings_consed; /* Number of bytes of consing since GC before another GC should be done. */ EMACS_INT gc_cons_threshold; +EMACS_INT gc_cons_combined_threshold; +static Lisp_Object Vgc_cons_percentage; /* Nonzero during GC. */ @@ -4897,6 +4899,26 @@ returns nil, because real GC can't be done. */) if (gc_cons_threshold < 10000) gc_cons_threshold = 10000; + gc_cons_combined_threshold = gc_cons_threshold; + + if (FLOATP (Vgc_cons_percentage)) + { /* Set gc_cons_combined_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_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_combined_threshold) + gc_cons_combined_threshold = threshold; + } + if (garbage_collection_messages) { if (message_p || minibuf_level > 0) @@ -5986,6 +6008,7 @@ init_alloc_once () staticidx = 0; consing_since_gc = 0; gc_cons_threshold = 100000 * sizeof (Lisp_Object); + gc_cons_combined_threshold = gc_cons_threshold; #ifdef VIRT_ADDR_VARIES malloc_sbrk_unused = 1<<22; /* A large number */ malloc_sbrk_used = 100000; /* as reasonable as any number */ @@ -6017,7 +6040,15 @@ allocated since the last garbage collection. All data types count. 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. */); -- cgit v1.3 From aa37e9e246dd9ef17d387f35dcea59986a7d8567 Mon Sep 17 00:00:00 2001 From: Stefan Monnier Date: Wed, 13 Jul 2005 05:33:34 +0000 Subject: (gc_cons_threshold): Make it static. --- src/alloc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/alloc.c') diff --git a/src/alloc.c b/src/alloc.c index a8cf897ede2..a65a96f1631 100644 --- a/src/alloc.c +++ b/src/alloc.c @@ -174,7 +174,7 @@ EMACS_INT strings_consed; /* Number of bytes of consing since GC before another GC should be done. */ -EMACS_INT gc_cons_threshold; +static EMACS_INT gc_cons_threshold; EMACS_INT gc_cons_combined_threshold; static Lisp_Object Vgc_cons_percentage; -- cgit v1.3 From 974aae61bbb8c05e0d0fc1a95b419fe596423fd8 Mon Sep 17 00:00:00 2001 From: "Richard M. Stallman" Date: Sat, 23 Jul 2005 19:08:06 +0000 Subject: (gc_cons_threshold): Not static. (gc_cons_combined_threshold): Var deleted. (gc_relative_threshold): New variable. (Fgarbage_collect, init_alloc_once): Compute gc_relative_threshold instead of gc_cons_combined_threshold. --- src/alloc.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) (limited to 'src/alloc.c') diff --git a/src/alloc.c b/src/alloc.c index a65a96f1631..3c9b2199e52 100644 --- a/src/alloc.c +++ b/src/alloc.c @@ -172,10 +172,14 @@ EMACS_INT misc_objects_consed; EMACS_INT intervals_consed; EMACS_INT strings_consed; -/* Number of bytes of consing since GC before another GC should be done. */ +/* Minimum number of bytes of consing since GC before next GC. */ + +EMACS_INT gc_cons_threshold; + +/* Similar minimum, computed from Vgc_cons_percentage. */ + +EMACS_INT gc_relative_threshold; -static EMACS_INT gc_cons_threshold; -EMACS_INT gc_cons_combined_threshold; static Lisp_Object Vgc_cons_percentage; /* Nonzero during GC. */ @@ -4899,12 +4903,10 @@ returns nil, because real GC can't be done. */) if (gc_cons_threshold < 10000) gc_cons_threshold = 10000; - gc_cons_combined_threshold = gc_cons_threshold; - if (FLOATP (Vgc_cons_percentage)) { /* Set gc_cons_combined_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); @@ -4914,10 +4916,10 @@ returns nil, because real GC can't be done. */) total += total_intervals * sizeof (struct interval); total += total_strings * sizeof (struct Lisp_String); - threshold = total * XFLOAT_DATA (Vgc_cons_percentage); - if (threshold > gc_cons_combined_threshold) - gc_cons_combined_threshold = threshold; + gc_relative_threshold = total * XFLOAT_DATA (Vgc_cons_percentage); } + else + gc_relative_threshold = 0; if (garbage_collection_messages) { @@ -6008,7 +6010,8 @@ init_alloc_once () staticidx = 0; consing_since_gc = 0; gc_cons_threshold = 100000 * sizeof (Lisp_Object); - gc_cons_combined_threshold = gc_cons_threshold; + gc_relative_threshold = 0; + #ifdef VIRT_ADDR_VARIES malloc_sbrk_unused = 1<<22; /* A large number */ malloc_sbrk_used = 100000; /* as reasonable as any number */ -- cgit v1.3