forked from linxGnu/grocksdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jemalloc.go
38 lines (32 loc) · 1.33 KB
/
jemalloc.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
//go:build !testing && jemalloc
package grocksdb
// #include "rocksdb/c.h"
import "C"
// CreateJemallocNodumpAllocator generates memory allocator which allocates through
// Jemalloc and utilize MADV_DONTDUMP through madvise to exclude cache items from core dump.
// Applications can use the allocator with block cache to exclude block cache
// usage from core dump.
//
// Implementation details:
// The JemallocNodumpAllocator creates a dedicated jemalloc arena, and all
// allocations of the JemallocNodumpAllocator are through the same arena.
// The memory allocator hooks memory allocation of the arena, and calls
// madvise() with MADV_DONTDUMP flag to exclude the piece of memory from
// core dump. Side benefit of using single arena would be reduction of jemalloc
// metadata for some workloads.
//
// To mitigate mutex contention for using one single arena, jemalloc tcache
// (thread-local cache) is enabled to cache unused allocations for future use.
// The tcache normally incurs 0.5M extra memory usage per-thread. The usage
// can be reduced by limiting allocation sizes to cache.
func CreateJemallocNodumpAllocator() (*MemoryAllocator, error) {
var cErr *C.char
c := C.rocksdb_jemalloc_nodump_allocator_create(&cErr)
// check error
if err := fromCError(cErr); err != nil {
return nil, err
}
return &MemoryAllocator{
c: c,
}, nil
}