mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-06-07 12:40:19 +02:00
Add gc_allocation_counter API
This commit is contained in:
parent
c51a48eae8
commit
05e8aba462
6 changed files with 54 additions and 15 deletions
|
@ -31,6 +31,8 @@ GC_API_ int gc_init(const struct gc_options *options,
|
||||||
struct gc_event_listener event_listener,
|
struct gc_event_listener event_listener,
|
||||||
void *event_listener_data);
|
void *event_listener_data);
|
||||||
|
|
||||||
|
GC_API_ uint64_t gc_allocation_counter(struct gc_heap *heap);
|
||||||
|
|
||||||
GC_API_ struct gc_heap* gc_mutator_heap(struct gc_mutator *mut);
|
GC_API_ struct gc_heap* gc_mutator_heap(struct gc_mutator *mut);
|
||||||
|
|
||||||
GC_API_ uintptr_t gc_small_object_nursery_low_address(struct gc_heap *heap);
|
GC_API_ uintptr_t gc_small_object_nursery_low_address(struct gc_heap *heap);
|
||||||
|
|
|
@ -109,17 +109,20 @@ gc_adaptive_heap_sizer_background_task(void *data) {
|
||||||
gc_adaptive_heap_sizer_lock(sizer);
|
gc_adaptive_heap_sizer_lock(sizer);
|
||||||
uint64_t bytes_allocated =
|
uint64_t bytes_allocated =
|
||||||
sizer->get_allocation_counter(sizer->heap);
|
sizer->get_allocation_counter(sizer->heap);
|
||||||
uint64_t heartbeat = gc_platform_monotonic_nanoseconds();
|
// bytes_allocated being 0 means the request failed; retry later.
|
||||||
double rate = (double) (bytes_allocated - sizer->last_bytes_allocated) /
|
if (bytes_allocated) {
|
||||||
(double) (heartbeat - sizer->last_heartbeat);
|
uint64_t heartbeat = gc_platform_monotonic_nanoseconds();
|
||||||
// Just smooth the rate, under the assumption that the denominator is almost
|
double rate = (double) (bytes_allocated - sizer->last_bytes_allocated) /
|
||||||
// always 1.
|
(double) (heartbeat - sizer->last_heartbeat);
|
||||||
sizer->smoothed_allocation_rate *= 1.0 - sizer->allocation_smoothing_factor;
|
// Just smooth the rate, under the assumption that the denominator is almost
|
||||||
sizer->smoothed_allocation_rate += rate * sizer->allocation_smoothing_factor;
|
// always 1.
|
||||||
sizer->last_heartbeat = heartbeat;
|
sizer->smoothed_allocation_rate *= 1.0 - sizer->allocation_smoothing_factor;
|
||||||
sizer->last_bytes_allocated = bytes_allocated;
|
sizer->smoothed_allocation_rate += rate * sizer->allocation_smoothing_factor;
|
||||||
sizer->set_heap_size(sizer->heap,
|
sizer->last_heartbeat = heartbeat;
|
||||||
gc_adaptive_heap_sizer_calculate_size(sizer));
|
sizer->last_bytes_allocated = bytes_allocated;
|
||||||
|
sizer->set_heap_size(sizer->heap,
|
||||||
|
gc_adaptive_heap_sizer_calculate_size(sizer));
|
||||||
|
}
|
||||||
gc_adaptive_heap_sizer_unlock(sizer);
|
gc_adaptive_heap_sizer_unlock(sizer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -505,6 +505,10 @@ static void on_heap_resize(GC_word size) {
|
||||||
HEAP_EVENT(heap_resized, size);
|
HEAP_EVENT(heap_resized, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint64_t gc_allocation_counter(struct gc_heap *heap) {
|
||||||
|
return GC_get_total_bytes();
|
||||||
|
}
|
||||||
|
|
||||||
int gc_init(const struct gc_options *options, struct gc_stack_addr *stack_base,
|
int gc_init(const struct gc_options *options, struct gc_stack_addr *stack_base,
|
||||||
struct gc_heap **heap, struct gc_mutator **mutator,
|
struct gc_heap **heap, struct gc_mutator **mutator,
|
||||||
struct gc_event_listener event_listener,
|
struct gc_event_listener event_listener,
|
||||||
|
|
17
src/mmc.c
17
src/mmc.c
|
@ -1080,12 +1080,25 @@ gc_options_parse_and_set(struct gc_options *options, int option,
|
||||||
return gc_common_options_parse_and_set(&options->common, option, value);
|
return gc_common_options_parse_and_set(&options->common, option, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint64_t allocation_counter_from_thread(struct gc_heap *heap) {
|
// with heap lock
|
||||||
|
static uint64_t allocation_counter(struct gc_heap *heap) {
|
||||||
uint64_t ret = heap->total_allocated_bytes_at_last_gc;
|
uint64_t ret = heap->total_allocated_bytes_at_last_gc;
|
||||||
if (pthread_mutex_trylock(&heap->lock)) return ret;
|
|
||||||
nofl_space_add_to_allocation_counter(heap_nofl_space(heap), &ret);
|
nofl_space_add_to_allocation_counter(heap_nofl_space(heap), &ret);
|
||||||
large_object_space_add_to_allocation_counter(heap_large_object_space(heap),
|
large_object_space_add_to_allocation_counter(heap_large_object_space(heap),
|
||||||
&ret);
|
&ret);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint64_t gc_allocation_counter(struct gc_heap *heap) {
|
||||||
|
pthread_mutex_lock(&heap->lock);
|
||||||
|
uint64_t ret = allocation_counter(heap);
|
||||||
|
pthread_mutex_unlock(&heap->lock);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
static uint64_t allocation_counter_from_thread(struct gc_heap *heap) {
|
||||||
|
if (pthread_mutex_trylock(&heap->lock)) return 0;
|
||||||
|
uint64_t ret = allocation_counter(heap);
|
||||||
pthread_mutex_unlock(&heap->lock);
|
pthread_mutex_unlock(&heap->lock);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
17
src/pcc.c
17
src/pcc.c
|
@ -1149,12 +1149,25 @@ int gc_options_parse_and_set(struct gc_options *options, int option,
|
||||||
return gc_common_options_parse_and_set(&options->common, option, value);
|
return gc_common_options_parse_and_set(&options->common, option, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint64_t allocation_counter_from_thread(struct gc_heap *heap) {
|
// with heap lock
|
||||||
|
static uint64_t allocation_counter(struct gc_heap *heap) {
|
||||||
uint64_t ret = heap->total_allocated_bytes_at_last_gc;
|
uint64_t ret = heap->total_allocated_bytes_at_last_gc;
|
||||||
if (pthread_mutex_trylock(&heap->lock)) return ret;
|
|
||||||
copy_space_add_to_allocation_counter(heap_allocation_space(heap), &ret);
|
copy_space_add_to_allocation_counter(heap_allocation_space(heap), &ret);
|
||||||
large_object_space_add_to_allocation_counter(heap_large_object_space(heap),
|
large_object_space_add_to_allocation_counter(heap_large_object_space(heap),
|
||||||
&ret);
|
&ret);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint64_t gc_allocation_counter(struct gc_heap *heap) {
|
||||||
|
pthread_mutex_lock(&heap->lock);
|
||||||
|
uint64_t ret = allocation_counter(heap);
|
||||||
|
pthread_mutex_unlock(&heap->lock);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
static uint64_t allocation_counter_from_thread(struct gc_heap *heap) {
|
||||||
|
if (pthread_mutex_trylock(&heap->lock)) return 0;
|
||||||
|
uint64_t ret = allocation_counter(heap);
|
||||||
pthread_mutex_unlock(&heap->lock);
|
pthread_mutex_unlock(&heap->lock);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
|
@ -618,6 +618,10 @@ static uint64_t get_allocation_counter(struct gc_heap *heap) {
|
||||||
return heap->total_allocated_bytes_at_last_gc;
|
return heap->total_allocated_bytes_at_last_gc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint64_t gc_allocation_counter(struct gc_heap *heap) {
|
||||||
|
return get_allocation_counter(heap);
|
||||||
|
}
|
||||||
|
|
||||||
static void ignore_async_heap_size_adjustment(struct gc_heap *heap,
|
static void ignore_async_heap_size_adjustment(struct gc_heap *heap,
|
||||||
size_t size) {
|
size_t size) {
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue