From 14c324f8bdad7720cd39abe0cc86b0295b2f1260 Mon Sep 17 00:00:00 2001 From: ivmai Date: Thu, 10 Sep 2009 20:08:05 +0000 Subject: [PATCH] 2009-09-10 Ivan Maidanski (diff118_cvs - superseding diff53) * allchblk.c (MUNMAP_THRESHOLD): Move macro definition out of a function. * allchblk.c (GC_unmap_threshold): New global variable definition (initialized to MUNMAP_THRESHOLD). * allchblk.c (GC_unmap_old): Use GC_unmap_threshold instead of MUNMAP_THRESHOLD; skip unmapping if GC_unmap_threshold is 0. * doc/README.environment (GC_UNMAP_THRESHOLD): Add information. * misc.c (GC_unmap_threshold): New variable declaration. * misc.c (GC_init_inner): Recognize "GC_UNMAP_THRESHOLD" environment variable to set GC_unmap_threshold value (only if USE_MUNMAP). --- ChangeLog | 18 +++++++++++++++++- allchblk.c | 24 +++++++++++++----------- doc/README.environment | 5 +++++ misc.c | 19 +++++++++++++++++++ 4 files changed, 54 insertions(+), 12 deletions(-) diff --git a/ChangeLog b/ChangeLog index 0ed06fe7..3626918c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,19 @@ +2009-09-10 Ivan Maidanski + (diff118_cvs - superseding diff53) + + * allchblk.c (MUNMAP_THRESHOLD): Move macro definition out of + a function. + * allchblk.c (GC_unmap_threshold): New global variable definition + (initialized to MUNMAP_THRESHOLD). + * allchblk.c (GC_unmap_old): Use GC_unmap_threshold instead of + MUNMAP_THRESHOLD; skip unmapping if GC_unmap_threshold is 0. + * doc/README.environment (GC_UNMAP_THRESHOLD): Add information. + * misc.c (GC_unmap_threshold): New variable declaration. + * misc.c (GC_init_inner): Recognize "GC_UNMAP_THRESHOLD" + environment variable to set GC_unmap_threshold value (only if + USE_MUNMAP). + 2009-09-10 Ivan Maidanski (diff117) @@ -428,7 +443,8 @@ GC_check_finalizer_nested): Ditto. 2009-09-10 Ivan Maidanski - (diff103_cvs) + (diff103_cvs - resembling diff78, diff88_cvs, diff99_cvs, + diff100_cvs, diff101_cvs, diff102_cvs) * alloc.c (GC_stopped_mark): Remove GC_log_printf("") (not needed anymore and GCC produces a warning for it). diff --git a/allchblk.c b/allchblk.c index 627ef904..85cba94b 100644 --- a/allchblk.c +++ b/allchblk.c @@ -381,29 +381,31 @@ STATIC void GC_add_to_fl(struct hblk *h, hdr *hhdr) #ifdef USE_MUNMAP +# ifndef MUNMAP_THRESHOLD +# define MUNMAP_THRESHOLD 6 +# endif + +int GC_unmap_threshold = MUNMAP_THRESHOLD; + /* Unmap blocks that haven't been recently touched. This is the only way */ /* way blocks are ever unmapped. */ void GC_unmap_old(void) { struct hblk * h; hdr * hhdr; - word sz; - unsigned short last_rec, threshold; int i; -# ifndef MUNMAP_THRESHOLD -# define MUNMAP_THRESHOLD 6 -# endif + + if (GC_unmap_threshold == 0) + return; /* unmapping disabled */ for (i = 0; i <= N_HBLK_FLS; ++i) { for (h = GC_hblkfreelist[i]; 0 != h; h = hhdr -> hb_next) { hhdr = HDR(h); if (!IS_MAPPED(hhdr)) continue; - threshold = (unsigned short)(GC_gc_no - MUNMAP_THRESHOLD); - last_rec = hhdr -> hb_last_reclaimed; - if ((last_rec > GC_gc_no || last_rec < threshold) - && threshold < GC_gc_no /* not recently wrapped */) { - sz = hhdr -> hb_sz; - GC_unmap((ptr_t)h, sz); + + if ((unsigned short)GC_gc_no - hhdr -> hb_last_reclaimed > + (unsigned short)GC_unmap_threshold) { + GC_unmap((ptr_t)h, hhdr -> hb_sz); hhdr -> hb_flags |= WAS_UNMAPPED; } } diff --git a/doc/README.environment b/doc/README.environment index a5e110e3..b6f6399d 100644 --- a/doc/README.environment +++ b/doc/README.environment @@ -136,6 +136,11 @@ GC_FREE_SPACE_DIVISOR - Set GC_free_space_divisor to the indicated value. Setting it to larger values decreases space consumption and increases GC frequency. +GC_UNMAP_THRESHOLD - Set the desired memory blocks unmapping threshold (the + number of sequential garbage collections for which + a candidate block for unmapping should remain free). The + special value "0" completely disables unmapping. + GC_FIND_LEAK - Turns on GC_find_leak and thus leak detection. Forces a collection at program termination to detect leaks that would otherwise occur after the last GC. diff --git a/misc.c b/misc.c index 60a0586c..e5e06c28 100644 --- a/misc.c +++ b/misc.c @@ -498,6 +498,10 @@ static void maybe_install_looping_handler(void) void GC_thr_init(void); #endif +#ifdef USE_MUNMAP + extern int GC_unmap_threshold; +#endif + void GC_init_inner(void) { # if !defined(THREADS) && defined(GC_ASSERTIONS) @@ -646,6 +650,21 @@ void GC_init_inner(void) GC_free_space_divisor = (GC_word)space_divisor; } } +# ifdef USE_MUNMAP + { + char * string = GETENV("GC_UNMAP_THRESHOLD"); + if (string != NULL) { + if (*string == '0' && *(string + 1) == '\0') { + /* "0" is used to disable unmapping. */ + GC_unmap_threshold = 0; + } else { + int unmap_threshold = atoi(string); + if (unmap_threshold > 0) + GC_unmap_threshold = unmap_threshold; + } + } + } +# endif maybe_install_looping_handler(); /* Adjust normal object descriptor for extra allocation. */ if (ALIGNMENT > GC_DS_TAGS && EXTRA_BYTES != 0) { -- 2.40.0