From 45e4684e4fe3fa5eac22d415cd765ec6e046884e Mon Sep 17 00:00:00 2001 From: Matthew Flatt Date: Mon, 15 Dec 2008 17:09:33 +0000 Subject: [PATCH] memory accounting: blame the parent instead of the child svn: r12853 --- collects/scheme/sandbox.ss | 2 +- .../scribblings/reference/custodians.scrbl | 21 +++++++++++-------- .../scribblings/reference/eval-model.scrbl | 10 +++++---- doc/release-notes/mzscheme/HISTORY.txt | 3 +++ src/mzscheme/gc2/Makefile.in | 2 +- .../gc2/{blame_the_child.c => mem_account.c} | 14 ++++--------- src/mzscheme/gc2/newgc.c | 6 +++--- 7 files changed, 30 insertions(+), 28 deletions(-) rename src/mzscheme/gc2/{blame_the_child.c => mem_account.c} (97%) diff --git a/collects/scheme/sandbox.ss b/collects/scheme/sandbox.ss index d8129d0977..46c241d02b 100644 --- a/collects/scheme/sandbox.ss +++ b/collects/scheme/sandbox.ss @@ -312,7 +312,7 @@ ;; time limit (when sec (let ([t (current-thread)]) - (thread (lambda () (sleep sec) (set! r 'time) (kill-thread t))))) + (thread (lambda () (unless (sync/timeout sec t) (set! r 'time)) (kill-thread t))))) (set! r (with-handlers ([void (lambda (e) (list raise e))]) (call-with-values thunk (lambda vs (list* values vs)))))) ;; The thread might be killed by the timer thread, so don't let diff --git a/collects/scribblings/reference/custodians.scrbl b/collects/scribblings/reference/custodians.scrbl index 69e5a66a76..32d5ecaa1f 100644 --- a/collects/scribblings/reference/custodians.scrbl +++ b/collects/scribblings/reference/custodians.scrbl @@ -57,19 +57,19 @@ or indirectly). If @scheme[cust] is not strictly subordinate to @defproc[(custodian-memory-accounting-available?) boolean?]{ -Returns @scheme[#t] if PLT Scheme is compiled with support for -per-custodian memory accounting, @scheme[#f] otherwise. - @margin-note{Memory accounting is normally available in PLT Scheme 3m, which is the main variant of PLT Scheme, and not normally available in -PLT Scheme CGC.}} +PLT Scheme CGC.} + +Returns @scheme[#t] if PLT Scheme is compiled with support for +per-custodian memory accounting, @scheme[#f] otherwise.} @defproc[(custodian-require-memory [limit-cust custodian?] [need-amt exact-nonnegative-integer?] [stop-cust custodian?]) void?]{ -Registers a require check if PLT Scheme is compiled with support for -per-custodian memory accounting, otherwise the +Registers a required-memory check if PLT Scheme is compiled with +support for per-custodian memory accounting, otherwise the @exnraise[exn:fail:unsupported]. If a check is registered, and if PLT Scheme later reaches a state after @@ -81,8 +81,8 @@ trigger some shutdown, then @scheme[stop-cust] is shut down.} [limit-amt exact-nonnegative-integer?] [stop-cust custodian? limit-cust]) void?]{ -Registers a limit check if PLT Scheme is compiled with support for -per-custodian memory accounting, otherwise the +Registers a limited-memory check if PLT Scheme is compiled with +support for per-custodian memory accounting, otherwise the @exnraise[exn:fail:unsupported]. If a check is registered, and if PLT Scheme later reaches a state @@ -93,7 +93,10 @@ after garbage collection (see @secref["gc-model"]) where @margin-note{A custodian's limit is checked only after a garbage collection, except that it may also be checked during certain large allocations that are individually larger - than the custodian's limit.} + than the custodian's limit. A single garbage collection + may shut down multiple custodians, even if shutting down + only one of the custodians would have reduced memory use + for other custodians.} For reliable shutdown, @scheme[limit-amt] for @scheme[custodian-limit-memory] must be much lower than the total diff --git a/collects/scribblings/reference/eval-model.scrbl b/collects/scribblings/reference/eval-model.scrbl index 4cd934cbe6..4e073ec0e3 100644 --- a/collects/scribblings/reference/eval-model.scrbl +++ b/collects/scribblings/reference/eval-model.scrbl @@ -801,7 +801,9 @@ object is reachable from two custodians where neither is an ancestor of the other, an object is arbitrarily charged to one of the other, and the choice can change after each collection; objects reachable from both a custodian and its descendant, however, are reliably -charged to the descendant. Reachability for per-custodian accounting -does not include weak references, references to threads managed by -non-descendant custodians, references to non-descendant custodians, or -references to custodian boxes for non-descendant custodians. +charged to the custodian and not to the descendants, unless the +custodian can reach the objects only through a descendant custodian or +a descendant's thread. Reachability for per-custodian accounting does +not include weak references, references to threads managed by other +custodians, references to other custodians, or references to custodian +boxes for other custodians. diff --git a/doc/release-notes/mzscheme/HISTORY.txt b/doc/release-notes/mzscheme/HISTORY.txt index 68435a0adb..ea4c3098fd 100644 --- a/doc/release-notes/mzscheme/HISTORY.txt +++ b/doc/release-notes/mzscheme/HISTORY.txt @@ -1,3 +1,6 @@ +Version 4.1.3.6 +Memory accounting changed to bias charges to parent instead of children + Version 4.1.3.3 Added compile-context-preservation-enabled Added exception-backtrace support for x86_84+JIT diff --git a/src/mzscheme/gc2/Makefile.in b/src/mzscheme/gc2/Makefile.in index 315209a657..3dce9e6b25 100644 --- a/src/mzscheme/gc2/Makefile.in +++ b/src/mzscheme/gc2/Makefile.in @@ -312,7 +312,7 @@ main.@LTO@: $(XSRCDIR)/main.c $(CC) $(CFLAGS) -c $(XSRCDIR)/main.c -o main.@LTO@ gc2.@LTO@: $(srcdir)/gc2.c $(srcdir)/newgc.c $(srcdir)/gc2.h \ - $(srcdir)/newgc.h $(srcdir)/blame_the_child.c \ + $(srcdir)/newgc.h $(srcdir)/mem_account.c \ $(srcdir)/sighand.c \ $(srcdir)/vm_osx.c $(srcdir)/vm_mmap.c $(srcdir)/vm_osk.c $(srcdir)/vm.c\ $(srcdir)/vm_memalign.c $(srcdir)/alloc_cache.c \ diff --git a/src/mzscheme/gc2/blame_the_child.c b/src/mzscheme/gc2/mem_account.c similarity index 97% rename from src/mzscheme/gc2/blame_the_child.c rename to src/mzscheme/gc2/mem_account.c index 5b8a21e8c7..76ca9eaf45 100644 --- a/src/mzscheme/gc2/blame_the_child.c +++ b/src/mzscheme/gc2/mem_account.c @@ -1,11 +1,11 @@ /*****************************************************************************/ -/* blame-the-child accounting */ +/* memory accounting */ /*****************************************************************************/ #ifdef NEWGC_BTC_ACCOUNT #include "../src/schpriv.h" /* BTC_ prefixed functions are called by newgc.c */ -/* btc_ prefixed functions are internal to blame_the_child.c */ +/* btc_ prefixed functions are internal to mem_account.c */ static const int btc_redirect_thread = 511; static const int btc_redirect_custodian = 510; @@ -430,13 +430,7 @@ static void BTC_do_accounting(NewGC *gc) if(owner_table[i]) owner_table[i]->memory_use = 0; - /* the end of the custodian list is where we want to start */ - while(SCHEME_PTR1_VAL(box)) { - cur = (Scheme_Custodian*)SCHEME_PTR1_VAL(box); - box = cur->global_next; - } - - /* walk backwards for the order we want */ + /* walk forward for the order we want (blame parents instead of children) */ while(cur) { int owner = custodian_to_owner_set(gc, cur); @@ -448,7 +442,7 @@ static void BTC_do_accounting(NewGC *gc) GCDEBUG((DEBUGOUTF, "Propagating accounting marks\n")); propagate_accounting_marks(gc); - box = cur->global_prev; cur = box ? SCHEME_PTR1_VAL(box) : NULL; + box = cur->global_next; cur = box ? SCHEME_PTR1_VAL(box) : NULL; } gc->in_unsafe_allocation_mode = 0; diff --git a/src/mzscheme/gc2/newgc.c b/src/mzscheme/gc2/newgc.c index f29aecf90d..479cb70c87 100644 --- a/src/mzscheme/gc2/newgc.c +++ b/src/mzscheme/gc2/newgc.c @@ -93,7 +93,7 @@ inline static int is_master_gc(NewGC *gc) { /* particular collector you want. */ /*****************************************************************************/ -/* This turns on blame-the-child automatic memory accounting */ +/* This turns on automatic memory accounting */ /* #define NEWGC_BTC_ACCOUNT */ /* #undef NEWGC_BTC_ACCOUNT */ @@ -1365,11 +1365,11 @@ inline static void reset_pointer_stack(void) } /*****************************************************************************/ -/* BLAME THE CHILD */ +/* MEMORY ACCOUNTING */ /*****************************************************************************/ #ifdef NEWGC_BTC_ACCOUNT -# include "blame_the_child.c" +# include "mem_account.c" #else # define clean_up_thread_list() /* */ #endif