summaryrefslogtreecommitdiff
path: root/libguile/gc-malloc.c
diff options
context:
space:
mode:
authorHan-Wen Nienhuys <hanwen@lilypond.org>2008-08-16 13:57:23 -0300
committerHan-Wen Nienhuys <hanwen@lilypond.org>2008-08-16 13:57:23 -0300
commit82ae1b8eb3413e6be6bd2aa032986fc7782e85ac (patch)
tree7181f0a89744ce910ab3deb3c3c630fb20bc2829 /libguile/gc-malloc.c
parentb474ac33ee0e47ab14306c218cb060667f9af2db (diff)
downloadguile-82ae1b8eb3413e6be6bd2aa032986fc7782e85ac.tar.gz
Garbage collection cleanup.
* New file gc-segment-table.c: hold code for the segment table. * Remove data that might be out of date; remove scm_i_adjust_min_yield(). We don't store min_yields, since they are only accurate at one point in time (when the sweep finishes). We decide the min yield at that point from min_yield_fraction and freelist->collected / freelist->swept * Introduce scm_i_gc_heap_size_delta() replacing scm_i_gc_grow_heap_p(). * Remove foo_1 fields containing penultimate results. * After GC, count mark bit vector to discover number of live objects. This simplifies hairy updates. * Many formatting and layout cleanups. * Fix in scm_i_sweep_card(): return the length of free_list returned, rather than number of deleted objects. * For mtrigger GCs: do not also run a full sweep after the gc() call, as this is inconsistent with lazy sweeping. * Remove scm_i_make_initial_segment(). * Use calloc in scm_i_make_empty_heap_segment() to save on initialization code. * New function scm_i_sweep_for_freelist() which sweeps, with proper statistic variable updates. * New segments are conceptually blocks with 100% reclaimable cells. * Remove some useless constants/comments: SCM_HEAP_SIZE, SCM_INIT_HEAP_SIZE, SCM_EXPHEAP, SCM_HEAP_SEG_SIZE * Do not increment scm_cells_allocated() from the scm_[double]cell(). This would be a race condition. * Move some deprecation checks in separate functions to not distract from main code flow.
Diffstat (limited to 'libguile/gc-malloc.c')
-rw-r--r--libguile/gc-malloc.c24
1 files changed, 14 insertions, 10 deletions
diff --git a/libguile/gc-malloc.c b/libguile/gc-malloc.c
index dd98ad74a..2dc9f0fc1 100644
--- a/libguile/gc-malloc.c
+++ b/libguile/gc-malloc.c
@@ -84,8 +84,8 @@ scm_gc_init_malloc (void)
{
scm_mtrigger = scm_getenv_int ("GUILE_INIT_MALLOC_LIMIT",
SCM_DEFAULT_INIT_MALLOC_LIMIT);
- scm_i_minyield_malloc = scm_getenv_int ("GUILE_MIN_YIELD_MALLOC",
- SCM_DEFAULT_MALLOC_MINYIELD);
+ scm_i_minyield_malloc = scm_getenv_int ("GUILE_MIN_YIELD_MALLOC",
+ SCM_DEFAULT_MALLOC_MINYIELD);
if (scm_i_minyield_malloc >= 100)
scm_i_minyield_malloc = 99;
@@ -105,7 +105,6 @@ void *
scm_realloc (void *mem, size_t size)
{
void *ptr;
- scm_t_sweep_statistics sweep_stats;
SCM_SYSCALL (ptr = realloc (mem, size));
if (ptr)
@@ -114,7 +113,9 @@ scm_realloc (void *mem, size_t size)
scm_i_scm_pthread_mutex_lock (&scm_i_sweep_mutex);
scm_gc_running_p = 1;
- scm_i_sweep_all_segments ("realloc", &sweep_stats);
+ // We don't want these sweep statistics to influence results for
+ // cell GC, so we don't collect statistics.
+ scm_i_sweep_all_segments ("realloc", NULL);
SCM_SYSCALL (ptr = realloc (mem, size));
if (ptr)
@@ -125,7 +126,7 @@ scm_realloc (void *mem, size_t size)
}
scm_i_gc ("realloc");
- scm_i_sweep_all_segments ("realloc", &sweep_stats);
+ scm_i_sweep_all_segments ("realloc", NULL);
scm_gc_running_p = 0;
scm_i_pthread_mutex_unlock (&scm_i_sweep_mutex);
@@ -231,19 +232,22 @@ increase_mtrigger (size_t size, const char *what)
{
unsigned long prev_alloced;
float yield;
- scm_t_sweep_statistics sweep_stats;
scm_i_scm_pthread_mutex_lock (&scm_i_sweep_mutex);
scm_gc_running_p = 1;
- prev_alloced = mallocated;
+ prev_alloced = mallocated;
+
+ /* The GC will finish the pending sweep. For that reason, we
+ don't execute a complete sweep after GC, although that might
+ free some more memory.
+ */
scm_i_gc (what);
- scm_i_sweep_all_segments ("mtrigger", &sweep_stats);
yield = (((float) prev_alloced - (float) scm_mallocated)
/ (float) prev_alloced);
- scm_gc_malloc_yield_percentage = (int) (100 * yield);
+ scm_gc_malloc_yield_percentage = (int) (100 * yield);
#ifdef DEBUGINFO
fprintf (stderr, "prev %lud , now %lud, yield %4.2lf, want %d",
@@ -271,7 +275,7 @@ increase_mtrigger (size_t size, const char *what)
if (no_overflow_trigger >= (float) ULONG_MAX)
scm_mtrigger = ULONG_MAX;
else
- scm_mtrigger = (unsigned long) no_overflow_trigger;
+ scm_mtrigger = (unsigned long) no_overflow_trigger;
#ifdef DEBUGINFO
fprintf (stderr, "Mtrigger sweep: ineffective. New trigger %d\n",