From patchwork Sun Oct 9 19:55:40 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andi Kleen X-Patchwork-Id: 118619 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 87091B6FA0 for ; Mon, 10 Oct 2011 06:56:23 +1100 (EST) Received: (qmail 19620 invoked by alias); 9 Oct 2011 19:56:12 -0000 Received: (qmail 19504 invoked by uid 22791); 9 Oct 2011 19:56:10 -0000 X-SWARE-Spam-Status: No, hits=-2.0 required=5.0 tests=AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from eggs.gnu.org (HELO eggs.gnu.org) (140.186.70.92) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sun, 09 Oct 2011 19:55:55 +0000 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RCzTV-0005Jd-9i for gcc-patches@gcc.gnu.org; Sun, 09 Oct 2011 15:55:54 -0400 Received: from one.firstfloor.org ([213.235.205.2]:35739) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RCzTU-0005J8-TX for gcc-patches@gcc.gnu.org; Sun, 09 Oct 2011 15:55:53 -0400 Received: by one.firstfloor.org (Postfix, from userid 503) id 6C1AD22C8073; Sun, 9 Oct 2011 21:55:46 +0200 (CEST) From: Andi Kleen To: gcc-patches@gcc.gnu.org Cc: Andi Kleen Subject: [PATCH 4/5] Add a freeing threshold for the garbage collector. Date: Sun, 9 Oct 2011 21:55:40 +0200 Message-Id: <1318190141-1220-5-git-send-email-andi@firstfloor.org> In-Reply-To: <1318190141-1220-1-git-send-email-andi@firstfloor.org> References: <1318190141-1220-1-git-send-email-andi@firstfloor.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 213.235.205.2 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org From: Andi Kleen Add a threshold to avoid freeing pages back too early to the OS. This avoid virtual memory map fragmentation. Based on a idea from Honza ggc/doc/: 2011-10-08 Andi Kleen PR other/50636 * invoke.texi (ggc-free-threshold, ggc-free-min): Add. ggc/: 2011-10-08 Andi Kleen PR other/50636 * ggc-page.c (ggc_collect): Add free threshold. * params.def (GGC_FREE_THRESHOLD, GGC_FREE_MIN): Add. --- gcc/doc/invoke.texi | 11 +++++++++++ gcc/ggc-page.c | 13 +++++++++---- gcc/params.def | 10 ++++++++++ 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index ef7ac68..6557f66 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -8837,6 +8837,17 @@ 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. +@item ggc-free-threshold + +Only free memory back to the system when it would free more than this +many percent of the total allocated memory. Default is 20 percent. +This avoids memory fragmentation. + +@item ggc-free-min + +Only free memory back to the system when it would free more than this. +Unit is kilobytes. + @item max-reload-search-insns The maximum number of instruction reload should look backward for equivalent register. Increasing values mean more aggressive optimization, making the diff --git a/gcc/ggc-page.c b/gcc/ggc-page.c index 6e08cda..cd1c41a 100644 --- a/gcc/ggc-page.c +++ b/gcc/ggc-page.c @@ -1968,14 +1968,19 @@ ggc_collect (void) if (GGC_DEBUG_LEVEL >= 2) fprintf (G.debug_file, "BEGIN COLLECTING\n"); + /* Release the pages we freed the last time we collected, but didn't + reuse in the interim. But only do this if this would free a + reasonable number of pages. Otherwise hold on to them + to avoid virtual memory fragmentation. */ + if (G.bytes_mapped - G.allocated >= + (PARAM_VALUE (GGC_FREE_THRESHOLD) / 100.0) * G.bytes_mapped && + G.bytes_mapped - G.allocated >= (size_t)PARAM_VALUE (GGC_FREE_MIN) * 1024) + release_pages (); + /* Zero the total allocated bytes. This will be recalculated in the sweep phase. */ G.allocated = 0; - /* Release the pages we freed the last time we collected, but didn't - reuse in the interim. */ - release_pages (); - /* Indicate that we've seen collections at this context depth. */ G.context_depth_collections = ((unsigned long)1 << (G.context_depth + 1)) - 1; diff --git a/gcc/params.def b/gcc/params.def index 5e49c48..ca28715 100644 --- a/gcc/params.def +++ b/gcc/params.def @@ -561,6 +561,16 @@ DEFPARAM(GGC_MIN_HEAPSIZE, #undef GGC_MIN_EXPAND_DEFAULT #undef GGC_MIN_HEAPSIZE_DEFAULT +DEFPARAM(GGC_FREE_THRESHOLD, + "ggc-free-threshold", + "Dont free memory back to system less this percent of the total memory", + 20, 0, 100) + +DEFPARAM(GGC_FREE_MIN, + "ggc-free-min", + "Dont free less memory than this back to the system, in kilobytes", + 8 * 1024, 0, 0) + DEFPARAM(PARAM_MAX_RELOAD_SEARCH_INSNS, "max-reload-search-insns", "The maximum number of instructions to search backward when looking for equivalent reload",