From e39e7c8d1ea71f3a9122f9b421920373692f09c5 Mon Sep 17 00:00:00 2001 From: Anuraag Agrawal Date: Mon, 23 Oct 2023 17:50:55 +0900 Subject: [PATCH] Allocate ignoring off page for larger allocs (#32) --- gc.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/gc.go b/gc.go index 40d6f97..56ca1af 100644 --- a/gc.go +++ b/gc.go @@ -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); @@ -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