2 * Copyright 2001-2003 Ximian, Inc
3 * Copyright 2003-2010 Novell, Inc.
4 * Copyright 2011 Xamarin Inc (http://www.xamarin.com)
6 * Permission is hereby granted, free of charge, to any person obtaining
7 * a copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sublicense, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice shall be
15 * included in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 #ifndef __MONO_SGENCONF_H__
26 #define __MONO_SGENCONF_H__
28 /*Basic defines and static tunables */
30 #if SIZEOF_VOID_P == 4
31 typedef guint32 mword;
33 typedef guint64 mword;
38 * Turning on heavy statistics will turn off the managed allocator and
39 * the managed write barrier.
41 //#define HEAVY_STATISTICS
44 * Define this to allow the user to change the nursery size by
45 * specifying its value in the MONO_GC_PARAMS environmental
46 * variable. See mono_gc_base_init for details.
52 * If this is set, the nursery is aligned to an address aligned to its size, ie.
53 * a 1MB nursery will be aligned to an address divisible by 1MB. This allows us to
54 * speed up ptr_in_nursery () checks which are very frequent. This requires the
55 * nursery size to be a compile time constant.
57 #define SGEN_ALIGN_NURSERY 1
60 * The binary protocol enables logging a lot of the GC ativity in a way that is not very
61 * intrusive and produce a compact file that can be searched using a custom tool.
64 //#define SGEN_BINARY_PROTOCOL
67 * Define this and use the "xdomain-checks" MONO_GC_DEBUG option to
68 * have cross-domain checks in the write barrier.
70 //#define XDOMAIN_CHECKS_IN_WBARRIER
72 #ifndef SGEN_BINARY_PROTOCOL
73 #ifndef HEAVY_STATISTICS
74 #define MANAGED_ALLOCATION
75 #ifndef XDOMAIN_CHECKS_IN_WBARRIER
76 #define MANAGED_WBARRIER
82 * Maximum level of debug to enable on this build.
83 * Making this a static variable enables us to put logging in a lot of places.
84 * FIXME decouple logging from assertions
86 #define SGEN_MAX_DEBUG_LEVEL 2
89 #define GC_BITS_PER_WORD (sizeof (mword) * 8)
91 /*Size of the section used by the copying GC. */
92 #define SGEN_SIZEOF_GC_MEM_SECTION ((sizeof (GCMemSection) + 7) & ~7)
95 * to quickly find the head of an object pinned by a conservative
96 * address we keep track of the objects allocated for each
97 * SGEN_SCAN_START_SIZE memory chunk in the nursery or other memory
98 * sections. Larger values have less memory overhead and bigger
99 * runtime cost. 4-8 KB are reasonable values.
101 #define SGEN_SCAN_START_SIZE (4096*2)
104 * Objects bigger then this go into the large object space. This size
105 * has a few constraints. It must fit into the major heap, which in
106 * the case of the copying collector means that it must fit into a
107 * pinned chunk. It must also play well with the GC descriptors, some
108 * of which (DESC_TYPE_RUN_LENGTH, DESC_TYPE_SMALL_BITMAP) encode the
111 #define SGEN_MAX_SMALL_OBJ_SIZE 8000
114 * This is the maximum ammount of memory we're willing to waste in order to speed up allocation.
115 * Wastage comes in thre forms:
117 * -when building the nursery fragment list, small regions are discarded;
118 * -when allocating memory from a fragment if it ends up below the threshold, we remove it from the fragment list; and
119 * -when allocating a new tlab, we discard the remaining space of the old one
121 * Increasing this value speeds up allocation but will cause more frequent nursery collections as less space will be used.
122 * Descreasing this value will cause allocation to be slower since we'll have to cycle thru more fragments.
123 * 512 annedoctally keeps wastage under control and doesn't impact allocation performance too much.
125 #define SGEN_MAX_NURSERY_WASTE 512
128 /* This is also the MAJOR_SECTION_SIZE for the copying major
130 #define SGEN_PINNED_CHUNK_SIZE (128 * 1024)
133 * Number of entries of a sequential store buffer.
134 * This number represents how frequently we'll have to alloc
135 * a new buffer, so it's a tradeoff of potential wasted space and
136 * increased performance.
138 * The current value of 1024 was probably selected because it fits a x86 page.
139 * There's no history on the why's of this value besides this.
141 #define DEFAULT_REMSET_SIZE 1024
145 * Minimum allowance for nursery allocations, as a multiple of the size of nursery.
147 * We allow at least this much allocation to happen to the major heap from multiple
148 * minor collections before triggering a major collection.
150 * Bigger values increases throughput by allowing more garbage to sit in the major heap.
151 * Smaller values leads to better memory effiency but more frequent major collections.
153 #define SGEN_DEFAULT_ALLOWANCE_NURSERY_SIZE_RATIO 4.0
155 #define SGEN_MIN_ALLOWANCE_NURSERY_SIZE_RATIO 1.0
156 #define SGEN_MAX_ALLOWANCE_NURSERY_SIZE_RATIO 10.0
159 * Default ratio of memory we want to release in a major collection in relation to the the current heap size.
161 * A major collection target is to free a given amount of memory. This amount is a ratio of the major heap size.
163 * Values above 0.5 cause the heap to agressively grow when it's small and waste memory when it's big.
164 * Lower values will produce more reasonable sized heaps when it's small, but will be suboptimal at large
165 * sizes as they will use a small fraction only.
168 #define SGEN_DEFAULT_SAVE_TARGET_RATIO 0.5
170 #define SGEN_MIN_SAVE_TARGET_RATIO 0.1
171 #define SGEN_MAX_SAVE_TARGET_RATIO 2.0