From 0ab94dd3e48cd4b0d5dcbef7b097cc29084e2aa4 Mon Sep 17 00:00:00 2001 From: Matthew Flatt Date: Mon, 7 Sep 2015 13:28:30 -0600 Subject: [PATCH] force GC more appropriately on phantom bytes When the number of bytes recorded via phantom bytes approaches memory use at the last GC, force a garbage collection. --- racket/src/racket/gc2/newgc.c | 13 +++++++++---- racket/src/racket/gc2/newgc.h | 1 + 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/racket/src/racket/gc2/newgc.c b/racket/src/racket/gc2/newgc.c index ca08b0d627..c919286006 100644 --- a/racket/src/racket/gc2/newgc.c +++ b/racket/src/racket/gc2/newgc.c @@ -1667,11 +1667,11 @@ int GC_allocate_phantom_bytes(intptr_t request_size_bytes) #endif if ((request_size_bytes > 0) - && ((gc->phantom_count + request_size_bytes) < gc->phantom_count)) + && ((gc->gen0_phantom_count + request_size_bytes) < gc->gen0_phantom_count)) /* overflow */ return 1; - gc->phantom_count += request_size_bytes; + gc->gen0_phantom_count += request_size_bytes; /* adjust `gc->memory_in_use', but protect against {over,under}flow: */ if (request_size_bytes < 0) { request_size_bytes = -request_size_bytes; @@ -1680,6 +1680,10 @@ int GC_allocate_phantom_bytes(intptr_t request_size_bytes) } else gc->memory_in_use = add_no_overflow(gc->memory_in_use, request_size_bytes); + /* If we've allocated enough phantom bytes, then force a GC */ + if (gc->gen0_phantom_count > GEN0_MAX_SIZE) + collect_now(gc, 0, 0); + return 1; } @@ -4056,7 +4060,7 @@ void GC_dump_with_traces(int flags, GCWARN((GCOUTF,"Allocated (+reserved) page sizes: %" PRIdPTR " (+%" PRIdPTR ")\n", gc->used_pages * APAGE_SIZE, mmu_memory_allocated(gc->mmu) - (gc->used_pages * APAGE_SIZE))); - GCWARN((GCOUTF,"Phantom bytes: %" PRIdPTR "\n", gc->phantom_count)); + GCWARN((GCOUTF,"Phantom bytes: %" PRIdPTR "\n", (gc->phantom_count + gc->gen0_phantom_count))); GCWARN((GCOUTF,"# of major collections: %" PRIdPTR "\n", gc->num_major_collects)); GCWARN((GCOUTF,"# of minor collections: %" PRIdPTR "\n", gc->num_minor_collects)); GCWARN((GCOUTF,"# of installed finalizers: %i\n", gc->num_fnls)); @@ -4997,7 +5001,7 @@ static void garbage_collect(NewGC *gc, int force_full, int no_full, int switchin old_mem_use = gc->memory_in_use; old_gen0 = gc->gen0.current_size; - old_mem_allocated = mmu_memory_allocated(gc->mmu) + gc->phantom_count; + old_mem_allocated = mmu_memory_allocated(gc->mmu) + gc->phantom_count + gc->gen0_phantom_count; TIME_DECLS(); @@ -5038,6 +5042,7 @@ static void garbage_collect(NewGC *gc, int force_full, int no_full, int switchin if (gc->gc_full) gc->phantom_count = 0; + gc->gen0_phantom_count = 0; TIME_INIT(); diff --git a/racket/src/racket/gc2/newgc.h b/racket/src/racket/gc2/newgc.h index 677a8927b8..a51e919a95 100644 --- a/racket/src/racket/gc2/newgc.h +++ b/racket/src/racket/gc2/newgc.h @@ -239,6 +239,7 @@ typedef struct NewGC { unsigned short phantom_tag; uintptr_t phantom_count; + uintptr_t gen0_phantom_count; Roots roots; GC_Weak_Array *weak_arrays;