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]

Re: Patch to account for rlimits in GC heuristics


 > From: Zack Weinberg <zack at codesourcery dot com>
 > 
 > OK with those changes.
 > zw


Here's what I checked in.

1.  Added RLIMIT_AS.
2.  Changed "lesser" -> "smallest".
3.  Factored out the common rlimit functionality.

4.  I also added a sanity check for RLIM_INFINITY to avoid mistakenly
    considering that a valid limit when the macro is a low or negative
    number.


I couldn't figure out a way to reorganize the two paragraphs that
actually came out better.  (I'm not a terribly gifted writer or
texinfo markup specialist.)  If you can provide more guidance or
suggestions I'd be happy to iterate over it with you.

Rebootstrapped C-only (which rebuilds the docs too) on solaris2 and
applied to trunk and 3.3.

Andrew, would you please confirm whether this solves your bootstrap
problem?

		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_rlimit_bound): New function.
	(ggc_min_expand_heuristic, ggc_min_heapsize_heuristic): Update
	defaults to account for rlimits.

diff -rup orig/egcc-CVS20030223/gcc/doc/invoke.texi egcc-CVS20030223/gcc/doc/invoke.texi
--- orig/egcc-CVS20030223/gcc/doc/invoke.texi	2003-02-23 01:01:52.000000000 -0500
+++ egcc-CVS20030223/gcc/doc/invoke.texi	2003-02-23 11:36:36.994090075 -0500
@@ -4474,8 +4474,10 @@ 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
+RAM >= 1GB.  If @code{getrlimit} is available, the notion of "RAM" is
+the smallest of actual RAM, RLIMIT_RSS, RLIMIT_DATA and RLIMIT_AS.  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.
@@ -4489,7 +4491,9 @@ 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
+upper bound of 131072 (128 megabytes).  If @code{getrlimit} is
+available, the notion of "RAM" is the smallest of actual RAM,
+RLIMIT_RSS, RLIMIT_DATA and RLIMIT_AS.  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
diff -rup orig/egcc-CVS20030223/gcc/ggc-common.c egcc-CVS20030223/gcc/ggc-common.c
--- orig/egcc-CVS20030223/gcc/ggc-common.c	2003-02-21 22:05:53.000000000 -0500
+++ egcc-CVS20030223/gcc/ggc-common.c	2003-02-23 11:30:41.160268351 -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
@@ -54,6 +58,7 @@ static int compare_ptr_data PARAMS ((con
 static void relocate_ptrs PARAMS ((void *, void *));
 static void write_pch_globals PARAMS ((const struct ggc_root_tab * const *tab,
 				       struct traversal_state *state));
+static double ggc_rlimit_bound PARAMS ((double));
 
 /* Maintain global roots that are preserved during GC.  */
 
@@ -626,11 +631,44 @@ gt_pch_restore (f)
   gt_pch_restore_stringpool ();
 }
 
+/* Modify the bound based on rlimits.  Keep the smallest number found.  */
+static double
+ggc_rlimit_bound (limit)
+     double limit;
+{
+#if defined(HAVE_GETRLIMIT)
+  struct rlimit rlim;
+# ifdef RLIMIT_RSS
+  if (getrlimit (RLIMIT_RSS, &rlim) == 0
+      && rlim.rlim_cur != RLIM_INFINITY
+      && rlim.rlim_cur < limit)
+    limit = rlim.rlim_cur;
+# endif
+# ifdef RLIMIT_DATA
+  if (getrlimit (RLIMIT_DATA, &rlim) == 0
+      && rlim.rlim_cur != RLIM_INFINITY
+      && rlim.rlim_cur < limit)
+    limit = rlim.rlim_cur;
+# endif
+# ifdef RLIMIT_AS
+  if (getrlimit (RLIMIT_AS, &rlim) == 0
+      && rlim.rlim_cur != RLIM_INFINITY
+      && rlim.rlim_cur < limit)
+    limit = rlim.rlim_cur;
+# endif
+#endif /* HAVE_GETRLIMIT */
+
+  return limit;
+}
+
 /* Heuristic to set a default for GGC_MIN_EXPAND.  */
 int
 ggc_min_expand_heuristic()
 {
   double min_expand = physmem_total();
+
+  /* Adjust for rlimits.  */
+  min_expand = ggc_rlimit_bound (min_expand);
   
   /* 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 +684,12 @@ ggc_min_expand_heuristic()
 int
 ggc_min_heapsize_heuristic()
 {
-  double min_heap_kbytes = physmem_total() / 1024;
+  double min_heap_kbytes = physmem_total();
+
+  /* Adjust for rlimits.  */
+  min_heap_kbytes = ggc_rlimit_bound (min_heap_kbytes);
+
+  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]