+2002-08-04 Han-Wen <hanwen@cs.uu.nl>
+
+ * NEWS: add entries for GC and vector WB.
+
2002-07-22 Han-Wen <hanwen@cs.uu.nl>
* autogen.sh (mscripts): find and check version number of
* Changes to the standalone interpreter
+** SCM_VELTS macros is now read-only. For writing, use the new macros
+SCM_WRITABLE_VELTS, SCM_SET_VECTOR_LENGTH. The use of
+SCM_WRITABLE_VELTS is discouraged, though.
+
+** Garbage collector rewrite.
+
+The garbage collector is cleaned up a lot, and now uses lazy
+sweeping. This is reflected in the output of (gc-stats); since cells
+are being freed when they are allocated, the cells-allocated field
+stays roughly constant.
+
+For malloc related triggers, the behavior is changed. It uses the same
+heuristic as the cell-triggered collections. It may be tuned with the
+environment variables GUILE_MIN_YIELD_MALLOC. This is the percentage
+for minimum yield of malloc related triggers; (default: 40)
+GUILE_INIT_MALLOC_LIMIT is the trigger for doing a GC. The default is
+200 kb.
+
+Debugging operations for the freelist have been deprecated, along with
+the C variables that control garbage collection. The environment
+variables GUILE_MAX_SEGMENT_SIZE, GUILE_INIT_SEGMENT_SIZE_2,
+GUILE_INIT_SEGMENT_SIZE_1, and GUILE_MIN_YIELD_2 should be used.
+
** New command line option `--no-debug'.
Specifying `--no-debug' on the command line will keep the debugging
2002-08-04 Han-Wen <hanwen@cs.uu.nl>
+ * gc.c (s_scm_gc_stats): add cell-yield and malloc-yield statistic
+ to gc-stats.
+
* numbers.c (big2str): return "0" for 0 iso. ""
- * gc-segment.c, gc-malloc.c gc-mark.c, gc-freelist.c, gc-card.c, private-gc.h:
- new file
+ * gc-segment.c, gc-malloc.c gc-mark.c, gc-freelist.c, gc-card.c,
+ private-gc.h: new file
* gc.c: completely revised and cleaned up the GC. It now uses lazy
sweeping. More documentation in workbook/newgc.text
#include "libltdl/ltdl.h"
-/* From the libtool manual: "Note that libltdl is not threadsafe,
- i.e. a multithreaded application has to use a mutex for libltdl.".
+/*
+ From the libtool manual: "Note that libltdl is not threadsafe,
+ i.e. a multithreaded application has to use a mutex for libltdl.".
- Guile does not currently support pre-emptive threads, so there is
- no mutex. Previously SCM_DEFER_INTS and SCM_ALLOW_INTS were used:
- they are mentioned here in case somebody is grepping for thread
- problems ;)
+ Guile does not currently support pre-emptive threads, so there is
+ no mutex. Previously SCM_DEFER_INTS and SCM_ALLOW_INTS were used:
+ they are mentioned here in case somebody is grepping for thread
+ problems ;)
*/
static void *
alloced memory, which won't go away on GC. Let's set the init such
that we get a nice yield on the next allocation:
*/
-#define SCM_DEFAULT_INIT_MALLOC_LIMIT 200000
+#define SCM_DEFAULT_INIT_MALLOC_LIMIT 200*1024
#define SCM_DEFAULT_MALLOC_MINYIELD 40
scm_igc (what);
scm_i_sweep_all_segments("mtrigger");
- yield = (prev_alloced - scm_mallocated) / (float) prev_alloced;
-
+ yield = (prev_alloced - scm_mallocated) / (float) prev_alloced;
+ scm_gc_malloc_yield_percentage = (int) (100 * yield);
/*
fprintf (stderr, "prev %lud , now %lud, yield %4.2lf, want %d",
prev_alloced, scm_mallocated, 100.0*yield, scm_i_minyield_malloc);
/*
fprintf (stderr, "Mtrigger sweep: ineffective. New trigger %d\n", scm_mtrigger);
*/
-
-
}
+
+
}
#ifdef GUILE_DEBUG_MALLOC
scm_gc_cells_swept += cards_swept * (SCM_GC_CARD_N_CELLS - SCM_GC_CARD_N_HEADER_CELLS);
scm_gc_cells_collected += collected * seg->span;
+
+ if (!seg->first_time)
+ scm_cells_allocated -= collected * seg->span;
+
seg->freelist->collected += collected * seg->span;
+
if(next_free == seg->bounds[1])
{
statistics, it just frees the memory pointed to by to-be-swept
cells.
- Implementation is slightly ugh, and how do we handle the swept_cells
- statistic?
+ Implementation is slightly ugh.
+
+ FIXME: if you do scm_i_sweep_segment(), and then allocate from this
+ segment again, the statistics are off.
*/
void
scm_i_sweep_segment (scm_t_heap_segment * seg)
scm_t_cell * p = seg->next_free_card;
int yield = scm_gc_cells_collected;
int coll = seg->freelist->collected;
-
+ int alloc = scm_cells_allocated ;
+
while (scm_i_sweep_some_cards (seg) != SCM_EOL)
;
scm_gc_cells_collected = yield;
+ scm_cells_allocated = alloc;
seg->freelist->collected = coll;
seg->next_free_card =p;
/* GC Statistics Keeping
*/
-unsigned long scm_cells_allocated = 0;
+long scm_cells_allocated = 0;
unsigned long scm_mallocated = 0;
unsigned long scm_gc_cells_collected;
unsigned long scm_gc_cells_collected_1 = 0; /* previous GC yield */
unsigned long scm_gc_ports_collected;
unsigned long scm_gc_time_taken = 0;
static unsigned long t_before_gc;
-static unsigned long t_before_sweep;
unsigned long scm_gc_mark_time_taken = 0;
unsigned long scm_gc_times = 0;
unsigned long scm_gc_cells_swept = 0;
double scm_gc_cells_marked_acc = 0.;
double scm_gc_cells_swept_acc = 0.;
+int scm_gc_cell_yield_percentage =0;
+int scm_gc_malloc_yield_percentage = 0;
+
SCM_SYMBOL (sym_cells_allocated, "cells-allocated");
SCM_SYMBOL (sym_heap_size, "cell-heap-size");
SCM_SYMBOL (sym_times, "gc-times");
SCM_SYMBOL (sym_cells_marked, "cells-marked");
SCM_SYMBOL (sym_cells_swept, "cells-swept");
+SCM_SYMBOL (sym_malloc_yield, "malloc-yield");
+SCM_SYMBOL (sym_cell_yield, "cell-yield");
/* {Scheme Interface to GC}
*/
-
+extern int scm_gc_malloc_yield_percentage;
SCM_DEFINE (scm_gc_stats, "gc-stats", 0, 0, 0,
(),
"Return an association list of statistics about Guile's current\n"
unsigned long int local_scm_mtrigger;
unsigned long int local_scm_mallocated;
unsigned long int local_scm_heap_size;
- unsigned long int local_scm_cells_allocated;
+ int local_scm_gc_cell_yield_percentage;
+ int local_scm_gc_malloc_yield_percentage;
+ long int local_scm_cells_allocated;
unsigned long int local_scm_gc_time_taken;
unsigned long int local_scm_gc_times;
unsigned long int local_scm_gc_mark_time_taken;
local_scm_gc_time_taken = scm_gc_time_taken;
local_scm_gc_mark_time_taken = scm_gc_mark_time_taken;
local_scm_gc_times = scm_gc_times;
-
-
- local_scm_gc_cells_swept = scm_gc_cells_swept_acc + scm_gc_cells_swept;
+ local_scm_gc_malloc_yield_percentage = scm_gc_malloc_yield_percentage;
+ local_scm_gc_cell_yield_percentage= scm_gc_cell_yield_percentage;
+
+ local_scm_gc_cells_swept =
+ (double) scm_gc_cells_swept_acc
+ + (double) scm_gc_cells_swept;
local_scm_gc_cells_marked = scm_gc_cells_marked_acc
+(double) scm_gc_cells_swept
-(double) scm_gc_cells_collected;
-
for (i = table_size; i--;)
{
heap_segs = scm_cons (scm_cons (scm_ulong2num (bounds[2*i]),
}
answer = scm_list_n (scm_cons (sym_gc_time_taken, scm_ulong2num (local_scm_gc_time_taken)),
- scm_cons (sym_cells_allocated, scm_ulong2num (local_scm_cells_allocated)),
+ scm_cons (sym_cells_allocated, scm_long2num (local_scm_cells_allocated)),
scm_cons (sym_heap_size, scm_ulong2num (local_scm_heap_size)),
scm_cons (sym_mallocated, scm_ulong2num (local_scm_mallocated)),
scm_cons (sym_mtrigger, scm_ulong2num (local_scm_mtrigger)),
scm_cons (sym_gc_mark_time_taken, scm_ulong2num (local_scm_gc_mark_time_taken)),
scm_cons (sym_cells_marked, scm_i_dbl2big (local_scm_gc_cells_marked)),
scm_cons (sym_cells_swept, scm_i_dbl2big (local_scm_gc_cells_swept)),
+ scm_cons (sym_malloc_yield, scm_long2num (local_scm_gc_malloc_yield_percentage)),
+ scm_cons (sym_cell_yield, scm_long2num (local_scm_gc_cell_yield_percentage)),
scm_cons (sym_heap_segments, heap_segs),
SCM_UNDEFINED);
SCM_ALLOW_INTS;
scm_gc_cells_marked_acc += (double) scm_gc_cells_swept
- (double) scm_gc_cells_collected;
- scm_gc_cells_swept_acc += scm_gc_cells_swept;
+ scm_gc_cells_swept_acc += (double) scm_gc_cells_swept;
+ scm_gc_cell_yield_percentage = ( scm_gc_cells_collected * 100 ) / SCM_HEAP_SIZE;
+
scm_gc_cells_swept = 0;
scm_gc_cells_collected_1 = scm_gc_cells_collected;
scm_mark_all ();
- t_before_sweep = scm_c_get_internal_run_time ();
- scm_gc_mark_time_taken += (t_before_sweep - t_before_gc);
+ scm_gc_mark_time_taken += (scm_c_get_internal_run_time () - t_before_gc);
scm_c_hook_run (&scm_before_sweep_c_hook, 0);
SCM_API unsigned long scm_gc_cells_collected;
SCM_API unsigned long scm_gc_malloc_collected;
SCM_API unsigned long scm_gc_ports_collected;
-SCM_API unsigned long scm_cells_allocated;
+SCM_API long scm_cells_allocated;
+SCM_API int scm_gc_cell_yield_percentage;
+SCM_API int scm_gc_malloc_yield_percentage;
SCM_API unsigned long scm_mallocated;
SCM_API unsigned long scm_mtrigger;
*/
unsigned long heap_size;
+
} scm_t_cell_type_statistics;