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

Commit

Permalink
Allocate ignoring off page for larger allocs (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
anuraaga authored Oct 23, 2023
1 parent 0363fb1 commit e39e7c8
Showing 1 changed file with 7 additions and 0 deletions.
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

0 comments on commit e39e7c8

Please sign in to comment.