11 /* {heap tuning parameters}
13 * These are parameters for controlling memory allocation. The heap
14 * is the area out of which scm_cons, and object headers are allocated.
16 * Each heap cell is 8 bytes on a 32 bit machine and 16 bytes on a
17 * 64 bit machine. The units of the _SIZE parameters are bytes.
18 * Cons pairs and object headers occupy one heap cell.
20 * SCM_INIT_HEAP_SIZE is the initial size of heap. If this much heap is
21 * allocated initially the heap will grow by half its current size
22 * each subsequent time more heap is needed.
24 * If SCM_INIT_HEAP_SIZE heap cannot be allocated initially, SCM_HEAP_SEG_SIZE
25 * will be used, and the heap will grow by SCM_HEAP_SEG_SIZE when more
26 * heap is needed. SCM_HEAP_SEG_SIZE must fit into type size_t. This code
27 * is in scm_init_storage() and alloc_some_heap() in sys.c
29 * If SCM_INIT_HEAP_SIZE can be allocated initially, the heap will grow by
30 * SCM_EXPHEAP(scm_heap_size) when more heap is needed.
32 * SCM_MIN_HEAP_SEG_SIZE is minimum size of heap to accept when more heap
38 * Heap size 45000 and 40% min yield gives quick startup and no extra
39 * heap allocation. Having higher values on min yield may lead to
40 * large heaps, especially if code behaviour is varying its
41 * maximum consumption between different freelists.
45 These values used to be global C variables. However, they're also
46 available through the environment, and having a double interface is
47 confusing. Now they're #defines --hwn.
50 #define SCM_DEFAULT_INIT_HEAP_SIZE_1 256*1024
51 #define SCM_DEFAULT_MIN_YIELD_1 40
52 #define SCM_DEFAULT_INIT_HEAP_SIZE_2 32*1024
54 /* The following value may seem large, but note that if we get to GC at
55 * all, this means that we have a numerically intensive application
57 #define SCM_DEFAULT_MIN_YIELD_2 40
59 #define SCM_DEFAULT_MAX_SEGMENT_SIZE (20*1024*1024L)
63 #define SCM_MIN_HEAP_SEG_SIZE (8 * SCM_GC_SIZEOF_CARD)
64 #define SCM_HEAP_SEG_SIZE (16384L * sizeof (scm_t_cell))
67 #define SCM_DOUBLECELL_ALIGNED_P(x) (((2 * sizeof (scm_t_cell) - 1) & SCM_UNPACK (x)) == 0)
70 #define SCM_GC_CARD_BVEC_SIZE_IN_LONGS \
71 ((SCM_GC_CARD_N_CELLS + SCM_C_BVEC_LONG_BITS - 1) / SCM_C_BVEC_LONG_BITS)
72 #define SCM_GC_IN_CARD_HEADERP(x) \
73 (scm_t_cell *) (x) < SCM_GC_CELL_CARD (x) + SCM_GC_CARD_N_HEADER_CELLS
76 int scm_getenv_int (const char *var, int def);
79 typedef enum { return_on_error, abort_on_error } policy_on_error;
86 A struct holding GC statistics on a particular type of cells.
88 typedef struct scm_t_cell_type_statistics {
91 heap segment where the last cell was allocated
95 /* minimum yield on this list in order not to grow the heap
99 /* defines min_yield as percent of total heap size
101 int min_yield_fraction;
103 /* number of cells per object on this list */
106 /* number of collected cells during last GC */
107 unsigned long collected;
109 /* number of collected cells during penultimate GC */
110 unsigned long collected_1;
112 /* total number of cells in heap segments
113 * belonging to this list.
115 unsigned long heap_size;
118 } scm_t_cell_type_statistics;
121 extern scm_t_cell_type_statistics scm_i_master_freelist;
122 extern scm_t_cell_type_statistics scm_i_master_freelist2;
123 extern unsigned long scm_gc_cells_collected_1;
125 void scm_i_adjust_min_yield (scm_t_cell_type_statistics *freelist);
126 void scm_i_gc_sweep_freelist_reset (scm_t_cell_type_statistics *freelist);
127 int scm_i_gc_grow_heap_p (scm_t_cell_type_statistics * freelist);
130 #define SCM_HEAP_SIZE \
131 (scm_i_master_freelist.heap_size + scm_i_master_freelist2.heap_size)
134 #define SCM_MAX(A, B) ((A) > (B) ? (A) : (B))
135 #define SCM_MIN(A, B) ((A) < (B) ? (A) : (B))
137 /* CELL_P checks a random word whether it has the right form for a
138 pointer to a cell. Use scm_i_find_heap_segment_containing_object
139 to find out whether it actually points to a real cell.
141 The right form for a cell pointer is this: the low three bits must
142 be scm_tc3_cons, and when the scm_tc3_cons tag is stripped, the
143 resulting pointer must be correctly aligned.
144 scm_i_initialize_heap_segment_data guarantees that the test below
147 #define CELL_P(x) ((SCM_UNPACK(x) & (sizeof(scm_t_cell)-1)) == scm_tc3_cons)
154 void scm_mark_all (void);
167 Cells are stored in a heap-segment: it is a contiguous chunk of
168 memory, that associated with one freelist.
171 typedef struct scm_t_heap_segment
174 {lower, upper} bounds of the segment
176 The upper bound is also the start of the mark space.
178 scm_t_cell *bounds[2];
181 If we ever decide to give it back, we could do it with this ptr.
183 Note that giving back memory is not very useful; as long we don't
184 touch a chunk of memory, the virtual memory system will keep it
185 swapped out. We could simply forget about a block.
187 (not that we do that, but anyway.)
192 scm_t_cell * next_free_card;
194 /* address of the head-of-freelist pointer for this segment's cells.
195 All segments usually point to the same one, scm_i_freelist. */
196 scm_t_cell_type_statistics *freelist;
198 /* number of cells per object in this segment */
203 Is this the first time that the cells are accessed?
207 } scm_t_heap_segment;
213 A table of segment records is kept that records the upper and
214 lower extents of the segment; this is used during the conservative
215 phase of gc to identify probably gc roots (because they point
216 into valid segments at reasonable offsets).
219 extern scm_t_heap_segment ** scm_i_heap_segment_table;
220 extern size_t scm_i_heap_segment_table_size;
223 int scm_i_init_card_freelist (scm_t_cell * card, SCM *free_list,scm_t_heap_segment*);
224 int scm_i_sweep_card (scm_t_cell * card, SCM *free_list, scm_t_heap_segment*);
225 void scm_i_card_statistics (scm_t_cell *p, SCM hashtab, scm_t_heap_segment *seg);
226 char const *scm_i_tag_name (scm_t_bits tag); /* MOVEME */
228 int scm_i_initialize_heap_segment_data (scm_t_heap_segment * segment, size_t requested);
229 int scm_i_segment_card_count (scm_t_heap_segment * seg);
230 int scm_i_segment_cell_count (scm_t_heap_segment * seg);
232 void scm_i_clear_segment_mark_space (scm_t_heap_segment *seg);
233 scm_t_heap_segment * scm_i_make_empty_heap_segment (scm_t_cell_type_statistics*);
234 SCM scm_i_sweep_some_cards (scm_t_heap_segment *seg);
235 void scm_i_sweep_segment (scm_t_heap_segment * seg);
237 void scm_i_heap_segment_statistics (scm_t_heap_segment *seg, SCM tab);
240 int scm_i_insert_segment (scm_t_heap_segment * seg);
241 long int scm_i_find_heap_segment_containing_object (SCM obj);
242 int scm_i_get_new_heap_segment (scm_t_cell_type_statistics *, policy_on_error);
243 void scm_i_clear_mark_space (void);
244 void scm_i_sweep_segments (void);
245 SCM scm_i_sweep_some_segments (scm_t_cell_type_statistics * fl);
246 void scm_i_reset_segments (void);
247 void scm_i_sweep_all_segments (char const *reason);
248 SCM scm_i_all_segments_statistics (SCM hashtab);
249 void scm_i_make_initial_segment (int init_heap_size, scm_t_cell_type_statistics *freelist);
251 extern long int scm_i_deprecated_memory_return;
257 void scm_gc_init_malloc (void);
258 void scm_gc_init_freelist (void);
259 void scm_gc_init_segments (void);
260 void scm_gc_init_mark (void);