Skip to content
This repository has been archived by the owner on May 16, 2024. It is now read-only.

Allocate ignoring off page for larger allocs #32

Merged
merged 1 commit into from
Oct 23, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions gc.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
void* GC_malloc(unsigned int size);
void* GC_malloc_atomic(unsigned int size);
void* GC_malloc_explicitly_typed(unsigned int size, unsigned int gc_descr);
void* GC_malloc_explicitly_typed_ignore_off_page(unsigned int size, unsigned int gc_descr);
void* GC_calloc_explicitly_typed(unsigned int nelements, unsigned int element_size, unsigned int gc_descr);
unsigned int GC_make_descriptor(void* bm, unsigned int len);
void GC_free(void* ptr);
Expand Down Expand Up @@ -138,6 +139,12 @@ func allocLarge(allocSz uintptr, layoutPtr unsafe.Pointer) unsafe.Pointer {
func allocTyped(allocSz uintptr, layoutSz uintptr, desc uintptr) unsafe.Pointer {
itemSz := layoutSz * unsafe.Sizeof(uintptr(0))
if desc == 0 || itemSz == allocSz {
// A bit unsure what the difference is, but it is recommended by bdwgc and seems to make a big
// difference in some apps.
// https://github.com/ivmai/bdwgc/blob/master/README.md#the-c-interface-to-the-allocator
if allocSz >= 100*1024 {
return C.GC_malloc_explicitly_typed_ignore_off_page(C.uint(allocSz), C.uint(desc))
}
return C.GC_malloc_explicitly_typed(C.uint(allocSz), C.uint(desc))
}
numItems := allocSz / itemSz
Expand Down