From 3788cc1761ef491333f243e4e846c7246a3cc5bb Mon Sep 17 00:00:00 2001 From: Zack Weinberg Date: Tue, 12 Nov 2002 00:27:31 +0000 Subject: [PATCH] params.def (ggc-min-expand, [...]): New parameters. * params.def (ggc-min-expand, ggc-min-heapsize): New parameters. * doc/invoke.texi: Document them. * ggc-page.c: Include params.h. Remove definitions of GGC_MIN_EXPAND_FOR_GC, GGC_MIN_LAST_ALLOCATED. Replace GGC_POISON with ENABLE_GC_CHECKING in ifdefs, delete #define. (init_gcc): Don't set G.allocated_last_gc here. (ggc_collect): Use PARAM_VALUE (GGC_MIN_HEAPSIZE) and PARAM_VALUE (GGC_MIN_EXPAND) to decide whether or not to perform collection. * ggc-simple.c: Similarly. * Makefile.in (ggc-common.o, ggc-simple.o): Add $(PARAMS_H) to dependencies. From-SVN: r59034 --- gcc/ChangeLog | 16 +++++++++++++++ gcc/Makefile.in | 5 +++-- gcc/doc/invoke.texi | 23 +++++++++++++++++++++ gcc/ggc-page.c | 49 ++++++++++----------------------------------- gcc/ggc-simple.c | 36 ++++++++++----------------------- gcc/params.def | 20 ++++++++++++++++++ 6 files changed, 84 insertions(+), 65 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 37c4d5ecec8a..9d7ab216bca8 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,19 @@ +2002-11-11 Zack Weinberg + + * params.def (ggc-min-expand, ggc-min-heapsize): New parameters. + * doc/invoke.texi: Document them. + + * ggc-page.c: Include params.h. Remove definitions of + GGC_MIN_EXPAND_FOR_GC, GGC_MIN_LAST_ALLOCATED. Replace + GGC_POISON with ENABLE_GC_CHECKING in ifdefs, delete #define. + (init_gcc): Don't set G.allocated_last_gc here. + (ggc_collect): Use PARAM_VALUE (GGC_MIN_HEAPSIZE) and + PARAM_VALUE (GGC_MIN_EXPAND) to decide whether or not to + perform collection. + * ggc-simple.c: Similarly. + * Makefile.in (ggc-common.o, ggc-simple.o): Add $(PARAMS_H) to + dependencies. + 2002-11-11 Kazu Hirata * gthr-dce.h: Fix formatting. diff --git a/gcc/Makefile.in b/gcc/Makefile.in index 8f2256c1c85a..2c43e255cd4c 100644 --- a/gcc/Makefile.in +++ b/gcc/Makefile.in @@ -1329,10 +1329,11 @@ gtype-desc.o: gtype-desc.c $(CONFIG_H) $(SYSTEM_H) varray.h $(HASHTAB_H) \ ssa.h cselib.h insn-addr.h ggc-common.o: ggc-common.c $(CONFIG_H) $(SYSTEM_H) $(RTL_H) $(TREE_H) \ - flags.h $(GGC_H) varray.h $(HASHTAB_H) $(TM_P_H) langhooks.h + flags.h $(GGC_H) varray.h $(HASHTAB_H) $(TM_P_H) langhooks.h \ + $(PARAMS_H) ggc-simple.o: ggc-simple.c $(CONFIG_H) $(SYSTEM_H) $(RTL_H) $(TREE_H) flags.h \ - $(GGC_H) varray.h $(TIMEVAR_H) $(TM_P_H) + $(GGC_H) varray.h $(TIMEVAR_H) $(TM_P_H) $(PARAMS_H) ggc-page.o: ggc-page.c $(CONFIG_H) $(SYSTEM_H) $(RTL_H) $(TREE_H) flags.h \ toplev.h $(GGC_H) varray.h $(TIMEVAR_H) $(TM_P_H) diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index c3605a39afa9..dc8a4363912b 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -4233,6 +4233,29 @@ compilation for profile feedback and one for compilation without. The value for compilation with profile feedback needs to be more conservative (higher) in order to make tracer effective. +@item ggc-min-expand + +GCC uses a garbage collector to manage its own memory allocation. This +parameter specifies the minimum percentage by which the garbage +collector's heap should be allowed to expand between collections. +Tuning this may improve compilation speed; it has no effect on code +generation. + +The default is 30%. Setting this parameter to zero causes a full +collection to occur at every opportunity. This is extremely slow, but +can be useful for debugging. + +@item ggc-min-heapsize + +Minimum size of the garbage collector's heap before it begins bothering +to collect garbage. The first collection occurs after the heap expands +by @option{ggc-min-expand}% beyond @option{ggc-min-heapsize}. Again, +tuning this may improve compilation speed, and has no effect on code +generation. + +The default is 4096 (four megabytes). Setting this parameter very large +effectively disables garbage collection. + @end table @end table diff --git a/gcc/ggc-page.c b/gcc/ggc-page.c index 9a2c03ef7211..31c646349f38 100644 --- a/gcc/ggc-page.c +++ b/gcc/ggc-page.c @@ -28,6 +28,7 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA #include "flags.h" #include "ggc.h" #include "timevar.h" +#include "params.h" /* Prefer MAP_ANON(YMOUS) to /dev/zero, since we don't need to keep a file open. Prefer either to valloc. */ @@ -88,23 +89,6 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA deallocated at the start of the next collection if they haven't been recycled by then. */ - -/* Define GGC_POISON to poison memory marked unused by the collector. */ -#undef GGC_POISON - -/* Define GGC_ALWAYS_COLLECT to perform collection every time - ggc_collect is invoked. Otherwise, collection is performed only - when a significant amount of memory has been allocated since the - last collection. */ -#undef GGC_ALWAYS_COLLECT - -#ifdef ENABLE_GC_CHECKING -#define GGC_POISON -#endif -#ifdef ENABLE_GC_ALWAYS_COLLECT -#define GGC_ALWAYS_COLLECT -#endif - /* Define GGC_DEBUG_LEVEL to print debugging information. 0: No debugging output. 1: GC statistics only. @@ -364,16 +348,6 @@ static struct globals #define BITMAP_SIZE(Num_objects) \ (CEIL ((Num_objects), HOST_BITS_PER_LONG) * sizeof(long)) -/* Skip garbage collection if the current allocation is not at least - this factor times the allocation at the end of the last collection. - In other words, total allocation must expand by (this factor minus - one) before collection is performed. */ -#define GGC_MIN_EXPAND_FOR_GC (1.3) - -/* Bound `allocated_last_gc' to 4MB, to prevent the memory expansion - test from triggering too often when the heap is small. */ -#define GGC_MIN_LAST_ALLOCATED (4 * 1024 * 1024) - /* Allocate pages in chunks of this size, to throttle calls to memory allocation routines. The first page is used, the rest go onto the free list. This cannot be larger than HOST_BITS_PER_INT for the @@ -399,7 +373,7 @@ static void sweep_pages PARAMS ((void)); static void ggc_recalculate_in_use_p PARAMS ((page_entry *)); static void compute_inverse PARAMS ((unsigned)); -#ifdef GGC_POISON +#ifdef ENABLE_GC_CHECKING static void poison_pages PARAMS ((void)); #endif @@ -968,7 +942,7 @@ ggc_alloc (size) /* Calculate the object's address. */ result = entry->page + object_offset; -#ifdef GGC_POISON +#ifdef ENABLE_GC_CHECKING /* `Poison' the entire allocated object, including any padding at the end. */ memset (result, 0xaf, OBJECT_SIZE (order)); @@ -1129,8 +1103,6 @@ init_ggc () G.debug_file = stdout; #endif - G.allocated_last_gc = GGC_MIN_LAST_ALLOCATED; - #ifdef USING_MMAP /* StunOS has an amazing off-by-one error for the first mmap allocation after fiddling with RLIMIT_STACK. The result, as hard as it is to @@ -1430,7 +1402,7 @@ sweep_pages () } } -#ifdef GGC_POISON +#ifdef ENABLE_GC_CHECKING /* Clobber all free objects. */ static inline void @@ -1476,10 +1448,13 @@ ggc_collect () /* Avoid frequent unnecessary work by skipping collection if the total allocations haven't expanded much since the last collection. */ -#ifndef GGC_ALWAYS_COLLECT - if (G.allocated < GGC_MIN_EXPAND_FOR_GC * G.allocated_last_gc) + size_t allocated_last_gc = + MAX (G.allocated_last_gc, (size_t)PARAM_VALUE (GGC_MIN_HEAPSIZE) * 1024); + + size_t min_expand = allocated_last_gc * PARAM_VALUE (GGC_MIN_EXPAND) / 100; + + if (G.allocated < allocated_last_gc + min_expand) return; -#endif timevar_push (TV_GC); if (!quiet_flag) @@ -1496,15 +1471,13 @@ ggc_collect () clear_marks (); ggc_mark_roots (); -#ifdef GGC_POISON +#ifdef ENABLE_GC_CHECKING poison_pages (); #endif sweep_pages (); G.allocated_last_gc = G.allocated; - if (G.allocated_last_gc < GGC_MIN_LAST_ALLOCATED) - G.allocated_last_gc = GGC_MIN_LAST_ALLOCATED; timevar_pop (TV_GC); diff --git a/gcc/ggc-simple.c b/gcc/ggc-simple.c index d3b53279241f..30b8725c0056 100644 --- a/gcc/ggc-simple.c +++ b/gcc/ggc-simple.c @@ -27,20 +27,16 @@ #include "varray.h" #include "ggc.h" #include "timevar.h" +#include "params.h" /* Debugging flags. */ /* Zap memory before freeing to catch dangling pointers. */ -#define GGC_POISON +#undef GGC_POISON /* Collect statistics on how bushy the search tree is. */ #undef GGC_BALANCE -/* Perform collection every time ggc_collect is invoked. Otherwise, - collection is performed only when a significant amount of memory - has been allocated since the last collection. */ -#undef GGC_ALWAYS_COLLECT - /* Always verify that the to-be-marked memory is collectable. */ #undef GGC_ALWAYS_VERIFY @@ -48,9 +44,6 @@ #define GGC_POISON #define GGC_ALWAYS_VERIFY #endif -#ifdef ENABLE_GC_ALWAYS_COLLECT -#define GGC_ALWAYS_COLLECT -#endif #ifndef HOST_BITS_PER_PTR #define HOST_BITS_PER_PTR HOST_BITS_PER_LONG @@ -115,16 +108,6 @@ static struct globals int context; } G; -/* Skip garbage collection if the current allocation is not at least - this factor times the allocation at the end of the last collection. - In other words, total allocation must expand by (this factor minus - one) before collection is performed. */ -#define GGC_MIN_EXPAND_FOR_GC (1.3) - -/* Bound `allocated_last_gc' to 4MB, to prevent the memory expansion - test from triggering too often when the heap is small. */ -#define GGC_MIN_LAST_ALLOCATED (4 * 1024 * 1024) - /* Local function prototypes. */ static void tree_insert PARAMS ((struct ggc_mem *)); @@ -324,10 +307,16 @@ sweep_objs (root) void ggc_collect () { -#ifndef GGC_ALWAYS_COLLECT - if (G.allocated < GGC_MIN_EXPAND_FOR_GC * G.allocated_last_gc) + /* Avoid frequent unnecessary work by skipping collection if the + total allocations haven't expanded much since the last + collection. */ + size_t allocated_last_gc = + MAX (G.allocated_last_gc, (size_t)PARAM_VALUE (GGC_MIN_HEAPSIZE) * 1024); + + size_t min_expand = allocated_last_gc * PARAM_VALUE (GGC_MIN_EXPAND) / 100; + + if (G.allocated < allocated_last_gc + min_expand) return; -#endif #ifdef GGC_BALANCE debug_ggc_balance (); @@ -345,8 +334,6 @@ ggc_collect () sweep_objs (&G.root); G.allocated_last_gc = G.allocated; - if (G.allocated_last_gc < GGC_MIN_LAST_ALLOCATED) - G.allocated_last_gc = GGC_MIN_LAST_ALLOCATED; timevar_pop (TV_GC); @@ -363,7 +350,6 @@ ggc_collect () void init_ggc () { - G.allocated_last_gc = GGC_MIN_LAST_ALLOCATED; } /* Start a new GGC context. Memory allocated in previous contexts diff --git a/gcc/params.def b/gcc/params.def index 1427819d2b80..f65469081fd7 100644 --- a/gcc/params.def +++ b/gcc/params.def @@ -190,6 +190,26 @@ DEFPARAM(TRACER_MIN_BRANCH_PROBABILITY, "Stop forward growth if the probability of best edge is less than \ this threshold (in percents). Used when profile feedback is not available", 50) + +#ifdef ENABLE_GC_ALWAYS_COLLECT +# define GGC_MIN_EXPAND_DEFAULT 0 +#else +# define GGC_MIN_EXPAND_DEFAULT 30 +#endif + +DEFPARAM(GGC_MIN_EXPAND, + "ggc-min-expand", + "Minimum heap expansion to trigger garbage collection, as \ +a percentage of the total size of the heap.", + GGC_MIN_EXPAND_DEFAULT) + +#undef GGC_MIN_EXPAND_DEFAULT + +DEFPARAM(GGC_MIN_HEAPSIZE, + "ggc-min-heapsize", + "Minimum heap size before we start collecting garbage, in kilobytes.", + 4096) + /* Local variables: mode:c