This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] more conservative heuristic for ggc-min-heapsize
- From: Nathan Froyd <froydnj at codesourcery dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Fri, 06 Oct 2006 16:26:40 -0400
- Subject: [PATCH] more conservative heuristic for ggc-min-heapsize
We have observed cases when GCC 4.1.x would fail with out-of-memory
errors on moderately-sized source files with rlimits set to "small"
values (~100MB virtual memory). Usually what would happen is that ggc
would be holding onto an amount of memory close to (ggc-min-heapsize *
(100 + ggc-min-expand))--that is, a GC had not yet happened--and there
would be enough memory used by malloc, shared libraries, GCC's code
itself, etc. that the ggc heap and the malloc heap combined would be
very close to the data limit. Then, at the start of an optimization
pass, a large malloc request would come in and blow over the data limit.
This patch attempts to be slightly more conservative in choosing a value
for ggc-min-heapsize (and therefore forcing GC slightly more often).
Instead of triggering a GC when the next GC would be within 16Mb of the
limit, it triggers one when the next GC would be within 20Mb of the
limit *or* a quarter of the limit, whichever is larger. The larger
static value (20Mb vs. 16Mb) is intended to accommodate larger programs
whereas the limit/4 value is adding an extra measure of
conservative-ness.
For what it's worth, mainline is more frugal in its memory usage than
4.1 is and the same testcases referenced above compile without problems
in the same environment (~100MB virtual memory). I believe the patch
still has value; it will just take larger testcases to make the mainline
compiler fall over. ;)
OK?
-Nathan
2006-10-06 Nathan Froyd <froydnj@codesourcery.com>
Nathan Sidwell <nathan@codesourcery.com>
gcc/
* ggc-common.c (ggc_min_heapsize_heuristic): Be more conservative
when choosing the minimum heapsize.
Index: gcc/ggc-common.c
===================================================================
--- gcc/ggc-common.c (revision 117374)
+++ gcc/ggc-common.c (working copy)
@@ -751,10 +751,10 @@
# endif
/* Don't blindly run over our data limit; do GC at least when the
- *next* GC would be within 16Mb of the limit. If GCC does hit the
- data limit, compilation will fail, so this tries to be
- conservative. */
- limit_kbytes = MAX (0, limit_kbytes - 16 * 1024);
+ *next* GC would be within 20Mb of the limit or within a quarter of
+ the limit, whichever is larger. If GCC does hit the data limit,
+ compilation will fail, so this tries to be conservative. */
+ limit_kbytes = MAX (0, limit_kbytes - MAX (limit_kbytes / 4, 20 * 1024));
limit_kbytes = (limit_kbytes * 100) / (110 + ggc_min_expand_heuristic());
phys_kbytes = MIN (phys_kbytes, limit_kbytes);