mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-04-30 03:40:34 +02:00
bdw: Disable thread-local freelists for pointerless allocations
There was a race between GC and popping the head off freelists. We could have separate freelists for tagged and untagged normal allocations though.
This commit is contained in:
parent
06b53470f4
commit
c9063b8027
7 changed files with 52 additions and 65 deletions
|
@ -4,8 +4,15 @@
|
|||
#include "gc-attrs.h"
|
||||
#include "gc-assert.h"
|
||||
|
||||
static inline enum gc_allocator_kind gc_allocator_kind(void) {
|
||||
return GC_ALLOCATOR_INLINE_FREELIST;
|
||||
static inline enum gc_inline_allocator_kind
|
||||
gc_inline_allocator_kind(enum gc_allocation_kind kind) {
|
||||
switch (kind) {
|
||||
case GC_ALLOCATION_TAGGED:
|
||||
case GC_ALLOCATION_UNTAGGED_CONSERVATIVE:
|
||||
return GC_INLINE_ALLOCATOR_FREELIST;
|
||||
default:
|
||||
return GC_INLINE_ALLOCATOR_NONE;
|
||||
}
|
||||
}
|
||||
static inline size_t gc_allocator_small_granule_size(void) {
|
||||
return 2 * sizeof(void *);
|
||||
|
@ -30,11 +37,8 @@ static inline size_t gc_allocator_freelist_offset(size_t size,
|
|||
case GC_ALLOCATION_UNTAGGED_CONSERVATIVE:
|
||||
base = 0;
|
||||
break;
|
||||
case GC_ALLOCATION_UNTAGGED_POINTERLESS:
|
||||
case GC_ALLOCATION_TAGGED_POINTERLESS:
|
||||
base = (sizeof(void*) * gc_allocator_large_threshold() /
|
||||
gc_allocator_small_granule_size());
|
||||
break;
|
||||
default:
|
||||
GC_CRASH();
|
||||
}
|
||||
size_t bucket = (size - 1) / gc_allocator_small_granule_size();
|
||||
return base + sizeof(void*) * bucket;
|
||||
|
|
|
@ -154,12 +154,12 @@ static inline void* gc_allocate_small_fast(struct gc_mutator *mut, size_t size,
|
|||
GC_ASSERT(size != 0);
|
||||
GC_ASSERT(size <= gc_allocator_large_threshold());
|
||||
|
||||
switch (gc_allocator_kind()) {
|
||||
case GC_ALLOCATOR_INLINE_BUMP_POINTER:
|
||||
switch (gc_inline_allocator_kind(kind)) {
|
||||
case GC_INLINE_ALLOCATOR_BUMP_POINTER:
|
||||
return gc_allocate_small_fast_bump_pointer(mut, size, kind);
|
||||
case GC_ALLOCATOR_INLINE_FREELIST:
|
||||
case GC_INLINE_ALLOCATOR_FREELIST:
|
||||
return gc_allocate_small_fast_freelist(mut, size, kind);
|
||||
case GC_ALLOCATOR_INLINE_NONE:
|
||||
case GC_INLINE_ALLOCATOR_NONE:
|
||||
return NULL;
|
||||
default:
|
||||
GC_CRASH();
|
||||
|
|
|
@ -7,13 +7,13 @@
|
|||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
enum gc_allocator_kind {
|
||||
GC_ALLOCATOR_INLINE_BUMP_POINTER,
|
||||
GC_ALLOCATOR_INLINE_FREELIST,
|
||||
GC_ALLOCATOR_INLINE_NONE
|
||||
enum gc_inline_allocator_kind {
|
||||
GC_INLINE_ALLOCATOR_BUMP_POINTER,
|
||||
GC_INLINE_ALLOCATOR_FREELIST,
|
||||
GC_INLINE_ALLOCATOR_NONE
|
||||
};
|
||||
|
||||
static inline enum gc_allocator_kind gc_allocator_kind(void) GC_ALWAYS_INLINE;
|
||||
static inline enum gc_inline_allocator_kind gc_inline_allocator_kind(enum gc_allocation_kind) GC_ALWAYS_INLINE;
|
||||
static inline size_t gc_allocator_large_threshold(void) GC_ALWAYS_INLINE;
|
||||
static inline size_t gc_allocator_small_granule_size(void) GC_ALWAYS_INLINE;
|
||||
|
||||
|
|
|
@ -5,8 +5,8 @@
|
|||
#include "gc-assert.h"
|
||||
#include "gc-attrs.h"
|
||||
|
||||
static inline enum gc_allocator_kind gc_allocator_kind(void) {
|
||||
return GC_ALLOCATOR_INLINE_BUMP_POINTER;
|
||||
static inline enum gc_inline_allocator_kind gc_inline_allocator_kind(enum gc_allocation_kind kind) {
|
||||
return GC_INLINE_ALLOCATOR_BUMP_POINTER;
|
||||
}
|
||||
static inline size_t gc_allocator_small_granule_size(void) {
|
||||
return 16;
|
||||
|
|
|
@ -8,8 +8,8 @@
|
|||
static const uintptr_t GC_ALIGNMENT = 8;
|
||||
static const size_t GC_LARGE_OBJECT_THRESHOLD = 8192;
|
||||
|
||||
static inline enum gc_allocator_kind gc_allocator_kind(void) {
|
||||
return GC_ALLOCATOR_INLINE_BUMP_POINTER;
|
||||
static inline enum gc_inline_allocator_kind gc_inline_allocator_kind(enum gc_allocation_kind kind) {
|
||||
return GC_INLINE_ALLOCATOR_BUMP_POINTER;
|
||||
}
|
||||
static inline size_t gc_allocator_small_granule_size(void) {
|
||||
return GC_ALIGNMENT;
|
||||
|
|
|
@ -7,8 +7,9 @@
|
|||
static const uintptr_t GC_ALIGNMENT = 8;
|
||||
static const size_t GC_LARGE_OBJECT_THRESHOLD = 8192;
|
||||
|
||||
static inline enum gc_allocator_kind gc_allocator_kind(void) {
|
||||
return GC_ALLOCATOR_INLINE_BUMP_POINTER;
|
||||
static inline enum gc_inline_allocator_kind
|
||||
gc_inline_allocator_kind(enum gc_allocation_kind kind) {
|
||||
return GC_INLINE_ALLOCATOR_BUMP_POINTER;
|
||||
}
|
||||
static inline size_t gc_allocator_small_granule_size(void) {
|
||||
return GC_ALIGNMENT;
|
||||
|
|
30
src/bdw.c
30
src/bdw.c
|
@ -65,7 +65,6 @@ struct gc_heap {
|
|||
|
||||
struct gc_mutator {
|
||||
void *freelists[GC_INLINE_FREELIST_COUNT];
|
||||
void *pointerless_freelists[GC_INLINE_FREELIST_COUNT];
|
||||
struct gc_heap *heap;
|
||||
struct gc_mutator_roots *roots;
|
||||
struct gc_mutator *next; // with heap lock
|
||||
|
@ -124,9 +123,6 @@ allocate_small(void **freelist, size_t idx, enum gc_inline_kind kind) {
|
|||
*freelist = *(void **)(head);
|
||||
*(void**)head = NULL;
|
||||
|
||||
if (kind == GC_INLINE_KIND_POINTERLESS)
|
||||
memset(head, 0, gc_inline_freelist_object_size(idx));
|
||||
|
||||
return head;
|
||||
}
|
||||
|
||||
|
@ -134,21 +130,19 @@ void* gc_allocate_slow(struct gc_mutator *mut, size_t size,
|
|||
enum gc_allocation_kind kind) {
|
||||
GC_ASSERT(size != 0);
|
||||
if (size <= gc_allocator_large_threshold()) {
|
||||
size_t idx = gc_inline_bytes_to_freelist_index(size);
|
||||
void **freelists;
|
||||
enum gc_inline_kind freelist_kind;
|
||||
switch (kind) {
|
||||
case GC_ALLOCATION_TAGGED:
|
||||
case GC_ALLOCATION_UNTAGGED_CONSERVATIVE:
|
||||
case GC_ALLOCATION_UNTAGGED_CONSERVATIVE: {
|
||||
size_t idx = gc_inline_bytes_to_freelist_index(size);
|
||||
return allocate_small(&mut->freelists[idx], idx, GC_INLINE_KIND_NORMAL);
|
||||
}
|
||||
case GC_ALLOCATION_TAGGED_POINTERLESS:
|
||||
case GC_ALLOCATION_UNTAGGED_POINTERLESS:
|
||||
return allocate_small(&mut->pointerless_freelists[idx], idx,
|
||||
GC_INLINE_KIND_POINTERLESS);
|
||||
break;
|
||||
default:
|
||||
GC_CRASH();
|
||||
}
|
||||
} else {
|
||||
}
|
||||
switch (kind) {
|
||||
case GC_ALLOCATION_TAGGED:
|
||||
case GC_ALLOCATION_UNTAGGED_CONSERVATIVE: {
|
||||
|
@ -169,7 +163,6 @@ void* gc_allocate_slow(struct gc_mutator *mut, size_t size,
|
|||
default:
|
||||
GC_CRASH();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void gc_pin_object(struct gc_mutator *mut, struct gc_ref ref) {
|
||||
|
@ -400,18 +393,7 @@ mark_mutator(GC_word *addr, struct GC_ms_entry *mark_stack_ptr,
|
|||
return state.mark_stack_ptr;
|
||||
}
|
||||
|
||||
for (int i = 0; i < GC_INLINE_FREELIST_COUNT; i++)
|
||||
state.mark_stack_ptr = GC_MARK_AND_PUSH (mut->freelists[i],
|
||||
state.mark_stack_ptr,
|
||||
state.mark_stack_limit,
|
||||
NULL);
|
||||
|
||||
for (int i = 0; i < GC_INLINE_FREELIST_COUNT; i++)
|
||||
for (void *head = mut->pointerless_freelists[i]; head; head = *(void**)head)
|
||||
state.mark_stack_ptr = GC_MARK_AND_PUSH (head,
|
||||
state.mark_stack_ptr,
|
||||
state.mark_stack_limit,
|
||||
NULL);
|
||||
memset(mut->freelists, 0, sizeof(void*) * GC_INLINE_FREELIST_COUNT);
|
||||
|
||||
if (mut->roots)
|
||||
gc_trace_mutator_roots(mut->roots, bdw_mark_edge, mut->heap, &state);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue