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

Commit

Permalink
Ignore off page malloc for non-layout too (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
johnlanni authored Oct 23, 2023
1 parent e39e7c8 commit ecd0c03
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions gc.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
void* GC_malloc(unsigned int size);
void* GC_malloc_atomic(unsigned int size);
void* GC_malloc_ignore_off_page(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);
Expand All @@ -38,6 +39,7 @@ import "C"

const (
gcEventStart = 0
bigObjSize = 100 * 1024
)

const (
Expand Down Expand Up @@ -101,7 +103,11 @@ func alloc(size uintptr, layoutPtr unsafe.Pointer) unsafe.Pointer {
buf = allocSmall(size, layoutSz, layoutBm)
} else if layoutPtr == nil {
// Unknown layout, assume all pointers.
buf = C.GC_malloc(C.uint(size))
if size >= bigObjSize {
buf = C.GC_malloc_ignore_off_page(C.uint(size))
} else {
buf = C.GC_malloc(C.uint(size))
}
} else {
buf = allocLarge(size, layoutPtr)
}
Expand Down Expand Up @@ -142,7 +148,7 @@ func allocTyped(allocSz uintptr, layoutSz uintptr, desc uintptr) unsafe.Pointer
// 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 {
if allocSz >= bigObjSize {
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))
Expand Down

0 comments on commit ecd0c03

Please sign in to comment.