Add two heap growth knobs: save-target-ratio and default-allowance-ratio.
authorRodrigo Kumpera <kumpera@gmail.com>
Mon, 2 Jul 2012 20:33:15 +0000 (17:33 -0300)
committerRodrigo Kumpera <kumpera@gmail.com>
Mon, 2 Jul 2012 20:53:10 +0000 (17:53 -0300)
mono/metadata/sgen-conf.h
mono/metadata/sgen-gc.c
mono/metadata/sgen-memory-governor.c
mono/metadata/sgen-memory-governor.h

index 52ba3e9b675ea1d72e31c45c7e989c91ae787ac3..89960397fe778a1902834bc301759ae95a9308a8 100644 (file)
@@ -150,7 +150,10 @@ typedef guint64 mword;
  * Bigger values increases throughput by allowing more garbage to sit in the major heap.
  * Smaller values leads to better memory effiency but more frequent major collections.
  */
-#define SGEN_MIN_ALLOWANCE_NURSERY_SIZE_RATIO 4
+#define SGEN_DEFAULT_ALLOWANCE_NURSERY_SIZE_RATIO 4.0
+
+#define SGEN_MIN_ALLOWANCE_NURSERY_SIZE_RATIO 1.0
+#define SGEN_MAX_ALLOWANCE_NURSERY_SIZE_RATIO 10.0
 
 /*
  * Default ratio of memory we want to release in a major collection in relation to the the current heap size.
@@ -162,6 +165,9 @@ typedef guint64 mword;
  * sizes as they will use a small fraction only.
  *
  */
-#define SGEN_DEFAULT_SAVE_TARGET_RATIO 0.5f
+#define SGEN_DEFAULT_SAVE_TARGET_RATIO 0.5
+
+#define SGEN_MIN_SAVE_TARGET_RATIO 0.1
+#define SGEN_MAX_SAVE_TARGET_RATIO 2.0
 
 #endif
index 397a6c68ac4f8e9a7e75d74d3c795226b3ca9290..2a9c4cb96bda15989d0e45fb6fe44053efff2ab2 100644 (file)
@@ -4453,6 +4453,7 @@ mono_gc_base_init (void)
        int result;
        int dummy;
        gboolean debug_print_allowance = FALSE;
+       double allowance_ratio = 0, save_target = 0;
 
        do {
                result = InterlockedCompareExchange (&gc_initialized, -1, 0);
@@ -4690,6 +4691,36 @@ mono_gc_base_init (void)
                                continue;
                        }
 #endif
+                       if (g_str_has_prefix (opt, "save-target-ratio=")) {
+                               char *endptr;
+                               opt = strchr (opt, '=') + 1;
+                               save_target = strtod (opt, &endptr);
+                               if (endptr == opt) {
+                                       fprintf (stderr, "save-target-ratio must be a number.");
+                                       exit (1);
+                               }
+                               if (save_target < SGEN_MIN_SAVE_TARGET_RATIO || save_target > SGEN_MAX_SAVE_TARGET_RATIO) {
+                                       fprintf (stderr, "save-target-ratio must be between %.2f - %.2f.", SGEN_MIN_SAVE_TARGET_RATIO, SGEN_MAX_SAVE_TARGET_RATIO);
+                                       exit (1);
+                               }
+                               continue;
+                       }
+                       if (g_str_has_prefix (opt, "default-allowance-ratio=")) {
+                               char *endptr;
+                               opt = strchr (opt, '=') + 1;
+
+                               allowance_ratio = strtod (opt, &endptr);
+                               if (endptr == opt) {
+                                       fprintf (stderr, "save-target-ratio must be a number.");
+                                       exit (1);
+                               }
+                               if (allowance_ratio < SGEN_MIN_ALLOWANCE_NURSERY_SIZE_RATIO || allowance_ratio > SGEN_MIN_ALLOWANCE_NURSERY_SIZE_RATIO) {
+                                       fprintf (stderr, "default-allowance-ratio must be between %.2f - %.2f.", SGEN_MIN_ALLOWANCE_NURSERY_SIZE_RATIO, SGEN_MIN_ALLOWANCE_NURSERY_SIZE_RATIO);
+                                       exit (1);
+                               }
+                               continue;
+                       }
+
                        if (major_collector.handle_gc_param && major_collector.handle_gc_param (opt))
                                continue;
 
@@ -4708,6 +4739,9 @@ mono_gc_base_init (void)
                                major_collector.print_gc_param_usage ();
                        if (sgen_minor_collector.print_gc_param_usage)
                                sgen_minor_collector.print_gc_param_usage ();
+                       fprintf (stderr, " Experimental options:\n");
+                       fprintf (stderr, "  save-target-ratio=R (where R must be between %.2f - %.2f).\n", SGEN_MIN_SAVE_TARGET_RATIO, SGEN_MAX_SAVE_TARGET_RATIO);
+                       fprintf (stderr, "  default-allowance-ratio=R (where R must be between %.2f - %.2f).\n", SGEN_MIN_ALLOWANCE_NURSERY_SIZE_RATIO, SGEN_MAX_ALLOWANCE_NURSERY_SIZE_RATIO);
                        exit (1);
                }
                g_strfreev (opts);
@@ -4832,7 +4866,7 @@ mono_gc_base_init (void)
        if (major_collector.post_param_init)
                major_collector.post_param_init ();
 
-       sgen_memgov_init (max_heap, soft_limit, debug_print_allowance);
+       sgen_memgov_init (max_heap, soft_limit, debug_print_allowance, allowance_ratio, save_target);
 
        memset (&remset, 0, sizeof (remset));
 
index 3d0746643fbbdc20ec53576020dcb8650e189705..0c880c6b4550da912f42217bca07e9ae9c442b5e 100644 (file)
 #include "utils/mono-mmap.h"
 #include "utils/mono-logger-internal.h"
 
-#define MIN_MINOR_COLLECTION_ALLOWANCE ((mword)(DEFAULT_NURSERY_SIZE * SGEN_MIN_ALLOWANCE_NURSERY_SIZE_RATIO))
+#define MIN_MINOR_COLLECTION_ALLOWANCE ((mword)(DEFAULT_NURSERY_SIZE * default_allowance_nursery_size_ratio))
 
-/*heap limits*/
+/*Heap limits and allocation knobs*/
 static mword max_heap_size = ((mword)0)- ((mword)1);
 static mword soft_heap_limit = ((mword)0) - ((mword)1);
-static mword allocated_heap;
 
-/*Memory usage tracking */
+static double default_allowance_nursery_size_ratio = SGEN_DEFAULT_ALLOWANCE_NURSERY_SIZE_RATIO;
+static double save_target_ratio = SGEN_DEFAULT_SAVE_TARGET_RATIO;
+
+/**/
+static mword allocated_heap;
 static mword total_alloc = 0;
 
 /* GC triggers. */
 
+static gboolean debug_print_allowance = FALSE;
+
+
 /* use this to tune when to do a major/minor collection */
 static mword memory_pressure = 0;
 static mword minor_collection_allowance;
 static int minor_collection_sections_alloced = 0;
 
-static gboolean debug_print_allowance = FALSE;
-
-/* GC stats */
 static int last_major_num_sections = 0;
 static int last_los_memory_usage = 0;
 static gboolean major_collection_happened = FALSE;
@@ -328,7 +331,7 @@ sgen_memgov_try_alloc_space (mword size, int space)
 }
 
 void
-sgen_memgov_init (glong max_heap, glong soft_limit, gboolean debug_allowance)
+sgen_memgov_init (glong max_heap, glong soft_limit, gboolean debug_allowance, double allowance_ratio, double save_target)
 {
        if (soft_limit)
                soft_heap_limit = soft_limit;
@@ -350,6 +353,12 @@ sgen_memgov_init (glong max_heap, glong soft_limit, gboolean debug_allowance)
        max_heap_size = max_heap - sgen_nursery_size;
 
        minor_collection_allowance = MIN_MINOR_COLLECTION_ALLOWANCE;
+
+       if (allowance_ratio)
+               default_allowance_nursery_size_ratio = allowance_ratio;
+
+       if (save_target)
+               save_target_ratio = save_target;
 }
 
 #endif
index 02959545324103d320753e831676b4d512b78ef3..ea9211856abc1ec2578827d6efa4a0d1f433b2a7 100644 (file)
@@ -25,7 +25,7 @@
 #define __MONO_SGEN_MEMORY_GOVERNOR_H__
 
 /* Heap limits */
-void sgen_memgov_init (glong max_heap, glong soft_limit, gboolean debug_allowance) MONO_INTERNAL;
+void sgen_memgov_init (glong max_heap, glong soft_limit, gboolean debug_allowance, double min_allowance_ratio, double save_target) MONO_INTERNAL;
 void sgen_memgov_release_space (mword size, int space) MONO_INTERNAL;
 gboolean sgen_memgov_try_alloc_space (mword size, int space) MONO_INTERNAL;