From 0553f191d7fc6cdc7289fc0705a7c4a93f2d239e Mon Sep 17 00:00:00 2001 From: Matthew Flatt Date: Sun, 20 Dec 2015 08:04:55 -0700 Subject: [PATCH] adjust PLT_INCREMENTAL_GC so it can disable generational GC A value that starts "1", "y", or "Y" enabled incremental mode permanently (any value was allowed formerly), while a value that starts "0", "n", or "N" causes incremental-mode requests to be ignored. --- .../scribblings/guide/performance.scrbl | 5 +++-- .../scribblings/reference/memory.scrbl | 10 ++++++++-- racket/src/racket/cmdline.inc | 19 +++++++++++++++++-- racket/src/racket/gc2/gc2.h | 3 ++- racket/src/racket/gc2/newgc.c | 16 ++++++++++------ 5 files changed, 40 insertions(+), 13 deletions(-) diff --git a/pkgs/racket-doc/scribblings/guide/performance.scrbl b/pkgs/racket-doc/scribblings/guide/performance.scrbl index da33166505..e647146b2c 100644 --- a/pkgs/racket-doc/scribblings/guide/performance.scrbl +++ b/pkgs/racket-doc/scribblings/guide/performance.scrbl @@ -598,8 +598,9 @@ pause is as short as a minor collection's pause. Incremental mode tends to run more slowly overall, but it can provide much more consistent real-time behavior. -If the @envvar{PLT_INCREMENTAL_GC} environment variable is set when -Racket starts, incremental mode is permanently enabled. Since +If the @envvar{PLT_INCREMENTAL_GC} environment variable is set +to a value that starts with @litchar{1}, @litchar{y}, or @litchar{Y} +when Racket starts, incremental mode is permanently enabled. Since incremental mode is only useful for certain parts of some programs, however, and since the need for incremental mode is a property of a program rather than its environment, the preferred way to enable diff --git a/pkgs/racket-doc/scribblings/reference/memory.scrbl b/pkgs/racket-doc/scribblings/reference/memory.scrbl index b91df7dc20..4f5f76ef16 100644 --- a/pkgs/racket-doc/scribblings/reference/memory.scrbl +++ b/pkgs/racket-doc/scribblings/reference/memory.scrbl @@ -200,7 +200,8 @@ execution. Otherwise, @racket[#f] is returned.} Set the @as-index{@envvar{PLTDISABLEGC}} environment variable (to any value) before Racket starts to disable @tech{garbage collection}. Set -the @as-index{@envvar{PLT_INCREMENTAL_GC}} environment variable to +the @as-index{@envvar{PLT_INCREMENTAL_GC}} environment variable +to a value that starts with @litchar{1}, @litchar{y}, or @litchar{Y} to request incremental mode at all times, but calling @racket[(collect-garbage 'incremental)] in a program with a periodic task is generally a better mechanism for requesting incremental mode. @@ -302,6 +303,7 @@ collection mode, the text has the format @history[#:changed "6.3.0.7" @elem{Added @envvar{PLT_INCREMENTAL_GC}.}] + @defproc[(collect-garbage [request (or/c 'major 'minor 'incremental) 'major]) void?]{ Requests an immediate @tech{garbage collection} or requests a @@ -336,7 +338,11 @@ garbage-collection mode, depending on @racket[request]: The intent of incremental mode is to significantly reduce pause times due to major collections, but incremental mode typically - implies longer minor-collection times and higher memory use.} + implies longer minor-collection times and higher memory use. + + If the @envvar{PLT_INCREMENTAL_GC} environment variable's value + starts with @litchar{0}, @litchar{n}, or @litchar{N} on + start-up, then incremental-mode requests are ignored.} ] diff --git a/racket/src/racket/cmdline.inc b/racket/src/racket/cmdline.inc index 4e0a5914ef..a532da07f5 100644 --- a/racket/src/racket/cmdline.inc +++ b/racket/src/racket/cmdline.inc @@ -1542,8 +1542,23 @@ static int run_from_cmd_line(int argc, char *_argv[], if (getenv("PLTDISABLEGC")) { scheme_enable_garbage_collection(0); } - if (getenv("PLT_INCREMENTAL_GC")) { - scheme_incremental_garbage_collection(1); + { + char *s; + s = getenv("PLT_INCREMENTAL_GC"); + if (s) { + if ((s[0] == '0') || (s[0] == 'n') || (s[0] == 'N')) + scheme_incremental_garbage_collection(0); + else if ((s[0] == '1') || (s[0] == 'y') || (s[0] == 'Y')) + scheme_incremental_garbage_collection(1); + else { + PRINTF("%s: unrecognized value for PLT_INCREMENTAL_GC;\n" + " a value that starts \"1\", \"y\", or \"Y\" permanently enables incremental mode,\n" + " and a value that starts \"0\", \"n\", or \"N\" disables incremental mode,\n" + " and the default enables incremental mode as requested via `collect-garbage'\n" + " unrecognized value: %s\n", + prog, s); + } + } } #endif diff --git a/racket/src/racket/gc2/gc2.h b/racket/src/racket/gc2/gc2.h index f5e6d68bdc..724c99af58 100644 --- a/racket/src/racket/gc2/gc2.h +++ b/racket/src/racket/gc2/gc2.h @@ -176,7 +176,8 @@ GC2_EXTERN void GC_request_incremental_mode(void); GC2_EXTERN void GC_set_incremental_mode(int on); /* - Sets whether incremental mode is the default. */ + Sets whether incremental mode is the default (1), always disabled (0), + or available on demand (-1). */ GC2_EXTERN void GC_free_all(void); /* diff --git a/racket/src/racket/gc2/newgc.c b/racket/src/racket/gc2/newgc.c index 2f15929221..63653dcaa1 100644 --- a/racket/src/racket/gc2/newgc.c +++ b/racket/src/racket/gc2/newgc.c @@ -257,6 +257,7 @@ MAYBE_UNUSED static void GCVERBOSEprintf(NewGC *gc, const char *fmt, ...) { /* Incremental mode */ static int always_collect_incremental_on_minor = 0; +static int never_collect_incremental_on_minor = 0; #define INCREMENTAL_COLLECT_FUEL_PER_100M (4 * 1024) #define INCREMENTAL_REPAIR_FUEL_PER_100M 32 @@ -3665,17 +3666,20 @@ void GC_gcollect_minor(void) void GC_request_incremental_mode(void) { - NewGC *gc = GC_get_GC(); + if (!never_collect_incremental_on_minor) { + NewGC *gc = GC_get_GC(); - /* The request will expire gradually, so that an extra major GC will - be triggered if incremental mode hasn't been requested recently - enough: */ - gc->incremental_requested = 8; + /* The request will expire gradually, so that an extra major GC will + be triggered if incremental mode hasn't been requested recently + enough: */ + gc->incremental_requested = 8; + } } void GC_set_incremental_mode(int on) { - always_collect_incremental_on_minor = 1; + always_collect_incremental_on_minor = (on > 0); + never_collect_incremental_on_minor = !on; } void GC_enable_collection(int on)