This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Patch to account for rlimits in GC heuristics


As noted elsewhere, rlimits need to be accounted for in the GC
heuristics.  The patch below does this by taking the lesser of actual
RAM, RLIMIT_RSS and RLIMIT_DATA as input into the algorithm.

I tested it by setting RLIMIT_DATA to 64Mb and bootstrapping C-only on
sparc-sun-solaris2.7.  Without the patch it crashes with an out of
memory error in stage2.  With the patch it succeeds.

With a restricted 64Mb RLIMIT_DATA, the heuristics show:

> GGC heuristics: --param ggc-min-expand=34 --param ggc-min-heapsize=8192

which by my manual calcuation is correct:
(30% + 70%*(64M/1G) == 34% and 64M/8 == 8M.)

Solaris2 doesn't have RLIMIT_RSS, so I'd like to install it for wider
testing of that bit.

Ok for trunk and 3.3?

		Thanks,
		--Kaveh


2003-02-22  Kaveh R. Ghazi  <ghazi at caip dot rutgers dot edu>

	* doc/invoke.texi (ggc-min-expand, ggc-min-heapsize): Document
	new default behavior.
	* ggc-common.c: Include sys/resource.h.
	(ggc_min_expand_heuristic, ggc_min_heapsize_heuristic): Update
	defaults to account for rlimits.

diff -rup orig/egcc-CVS20030222/gcc/doc/invoke.texi egcc-CVS20030222/gcc/doc/invoke.texi
--- orig/egcc-CVS20030222/gcc/doc/invoke.texi	2003-02-21 22:04:45.000000000 -0500
+++ egcc-CVS20030222/gcc/doc/invoke.texi	2003-02-22 13:27:54.360348000 -0500
@@ -4474,11 +4474,12 @@ Tuning this may improve compilation spee
 generation.
 
 The default is 30% + 70% * (RAM/1GB) with an upper bound of 100% when
-RAM >= 1GB.  If GCC is not able to calculate RAM on a particular
-platform, the lower bound of 30% is used.  Setting this parameter and
- at option{ggc-min-heapsize} to zero causes a full collection to occur at
-every opportunity.  This is extremely slow, but can be useful for
-debugging.
+RAM >= 1GB.  If @code{getrlimit} is available, the notion of "RAM" is
+the lesser of actual RAM, RLIMIT_RSS and RLIMIT_DATA.  If GCC is not
+able to calculate RAM on a particular platform, the lower bound of 30%
+is used.  Setting this parameter and @option{ggc-min-heapsize} 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
 
@@ -4489,11 +4490,13 @@ tuning this may improve compilation spee
 generation.
 
 The default is RAM/8, with a lower bound of 4096 (four megabytes) and an
-upper bound of 131072 (128 megabytes).  If GCC is not able to calculate
-RAM on a particular platform, the lower bound is used.  Setting this
-parameter very large effectively disables garbage collection.  Setting
-this parameter and @option{ggc-min-expand} to zero causes a full
-collection to occur at every opportunity.
+upper bound of 131072 (128 megabytes).  If @code{getrlimit} is
+available, the notion of "RAM" is the lesser of actual RAM, RLIMIT_RSS
+and RLIMIT_DATA.  If GCC is not able to calculate RAM on a particular
+platform, the lower bound is used.  Setting this parameter very large
+effectively disables garbage collection.  Setting this parameter and
+ at option{ggc-min-expand} to zero causes a full collection to occur at
+every opportunity.
 
 @end table
 @end table
diff -rup orig/egcc-CVS20030222/gcc/ggc-common.c egcc-CVS20030222/gcc/ggc-common.c
--- orig/egcc-CVS20030222/gcc/ggc-common.c	2003-02-21 22:05:53.000000000 -0500
+++ egcc-CVS20030222/gcc/ggc-common.c	2003-02-22 13:27:02.022855000 -0500
@@ -29,6 +29,10 @@ Software Foundation, 59 Temple Place - S
 #include "toplev.h"
 #include "params.h"
 
+#ifdef HAVE_SYS_RESOURCE_H
+# include <sys/resource.h>
+#endif
+
 #ifdef HAVE_MMAP_FILE
 # include <sys/mman.h>
 #endif
@@ -631,6 +635,18 @@ int
 ggc_min_expand_heuristic()
 {
   double min_expand = physmem_total();
+
+#if defined(HAVE_GETRLIMIT)
+  struct rlimit rlim;
+# ifdef RLIMIT_RSS
+  if (getrlimit (RLIMIT_RSS, &rlim) == 0 && rlim.rlim_cur < min_expand)
+    min_expand = rlim.rlim_cur;
+# endif
+# ifdef RLIMIT_DATA
+  if (getrlimit (RLIMIT_DATA, &rlim) == 0 && rlim.rlim_cur < min_expand)
+    min_expand = rlim.rlim_cur;
+# endif
+#endif /* HAVE_GETRLIMIT */
   
   /* The heuristic is a percentage equal to 30% + 70%*(RAM/1GB), yielding
      a lower bound of 30% and an upper bound of 100% (when RAM >= 1GB).  */
@@ -646,7 +662,21 @@ ggc_min_expand_heuristic()
 int
 ggc_min_heapsize_heuristic()
 {
-  double min_heap_kbytes = physmem_total() / 1024;
+  double min_heap_kbytes = physmem_total();
+
+#if defined(HAVE_GETRLIMIT)
+  struct rlimit rlim;
+# ifdef RLIMIT_RSS
+  if (getrlimit (RLIMIT_RSS, &rlim) == 0 && rlim.rlim_cur < min_heap_kbytes)
+    min_heap_kbytes = rlim.rlim_cur;
+# endif
+# ifdef RLIMIT_DATA
+  if (getrlimit (RLIMIT_DATA, &rlim) == 0 && rlim.rlim_cur < min_heap_kbytes)
+    min_heap_kbytes = rlim.rlim_cur;
+# endif
+#endif /* HAVE_GETRLIMIT */
+
+  min_heap_kbytes /= 1024; /* convert to Kbytes. */
   
   /* The heuristic is RAM/8, with a lower bound of 4M and an upper
      bound of 128M (when RAM >= 1GB).  */


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]