better defaults and debugging for fixed size chunks

This commit is contained in:
Alex Shinn 2020-05-05 00:41:20 +09:00
parent 696bf30f5e
commit 9100909ae1
4 changed files with 56 additions and 3 deletions

24
benchmarks/gabriel/difftimes.sh Executable file
View file

@ -0,0 +1,24 @@
#!/bin/bash
# set -ex
BENCHDIR=$(dirname $0)
if [ "${BENCHDIR%%/*}" = "." ]; then
BENCHDIR="$(pwd)${BENCHDIR#.}"
fi
TS1="${1:--2}"
TS2="${2:--1}"
DB="${3:-${BENCHDIR}/times.tsv}"
if [ "$TS1" -lt 1000000000 ]; then
TS1=$(cut -f 7 "$DB" | sort -nru | tail -n +$((0 - TS1)) | head -1)
fi
if [ "$TS2" -lt 1000000000 ]; then
TS2=$(cut -f 7 "$DB" | sort -nru | tail -n +$((0 - TS2)) | head -1)
fi
join -t $'\t' \
<(grep $'\t'"$TS1"$'\t' "$DB" | cut -f 1-2) \
<(grep $'\t'"$TS2"$'\t' "$DB" | cut -f 1-2) \
| perl -F'\t' -ane '$g=($F[1]<=0)?0:100*($F[2]-$F[1])/$F[1]; printf STDOUT "%s\t%d\t%d\t%.2f%%\n", @F, $g'

18
gc.c
View file

@ -45,6 +45,22 @@ static size_t sexp_heap_total_size (sexp_heap h) {
}
#if ! SEXP_USE_GLOBAL_HEAP
#if SEXP_USE_DEBUG_GC
void sexp_debug_heap_stats (sexp_heap heap) {
sexp_free_list ls;
size_t available = 0;
for (ls=heap->free_list; ls; ls=ls->next)
available += ls->size;
#if SEXP_USE_FIXED_CHUNK_SIZE_HEAPS
sexp_debug_printf("free heap: %p (chunk size: %lu): %ld / %ld used (%.2f%%)", heap, heap->chunk_size, heap->size - available, heap->size, 100*(heap->size - available) / (float)heap->size);
#else
sexp_debug_printf("free heap: %p: %ld / %ld used (%.2f%%)", heap, heap->size - available, heap->size, 100*(heap->size - available) / (float)heap->size);
#endif
if (heap->next)
sexp_debug_heap_stats(heap->next);
}
#endif
void sexp_free_heap (sexp_heap heap) {
#if SEXP_USE_MMAP_GC
munmap(heap, sexp_heap_pad_size(heap->size));
@ -618,4 +634,4 @@ void sexp_gc_init (void) {
#endif
}
#endif
#endif /* ! SEXP_USE_BOEHM && ! SEXP_USE_MALLOC */

View file

@ -1760,9 +1760,11 @@ SEXP_API sexp sexp_finalize (sexp ctx);
#if SEXP_USE_GLOBAL_HEAP
#define sexp_free_heap(heap)
#define sexp_debug_heap_stats(heap)
#define sexp_destroy_context(ctx) SEXP_TRUE
#else
SEXP_API void sexp_free_heap (sexp_heap heap);
SEXP_API void sexp_debug_heap_stats (sexp_heap heap);
SEXP_API sexp sexp_destroy_context (sexp ctx);
SEXP_API sexp sexp_copy_context (sexp ctx, sexp dst, sexp flags);
#endif

15
sexp.c
View file

@ -617,8 +617,16 @@ sexp sexp_bootstrap_context (sexp_uint_t size, sexp_uint_t max_size) {
} else {
sexp_context_heap(ctx) = heap;
#if SEXP_USE_FIXED_CHUNK_SIZE_HEAPS
heap->chunk_size = 1<<(4+SEXP_64_BIT);
sexp_grow_heap(ctx, sexp_heap_align(size), 0);
heap->chunk_size = sexp_heap_align(1);
heap->next = sexp_make_heap(size, max_size, 0);
if (heap->next) {
heap->next->chunk_size = sexp_heap_align(1 + sexp_heap_align(1));
heap->next->next = sexp_make_heap(size, max_size, 0);
if (heap->next->next) {
heap->next->next->chunk_size = sexp_heap_align(1 + sexp_heap_align(1 + sexp_heap_align(1)));
heap->next->next->next = sexp_make_heap(size, max_size, 0);
}
}
#endif
}
return ctx;
@ -677,6 +685,9 @@ sexp sexp_destroy_context (sexp ctx) {
size_t sum_freed;
if (sexp_context_heap(ctx)) {
heap = sexp_context_heap(ctx);
#if SEXP_USE_DEBUG_GC
sexp_debug_heap_stats(heap);
#endif
sexp_markedp(ctx) = 1;
sexp_markedp(sexp_context_globals(ctx)) = 1;
sexp_mark(ctx, sexp_global(ctx, SEXP_G_TYPES));