Cargo Features

[dependencies]
tcmalloc-better = { version = "0.1.19", default-features = false, features = ["std", "extension", "numa_aware", "deprecated_perthread", "legacy_locking", "realloc", "8k_pages", "32k_pages", "256k_pages", "small_but_slow", "disable_madv_hugepage_always", "disable_madv_hugepage_by_var"] }
default = 8k_pages, extension, std

These default features are set whenever tcmalloc-better is added without default-features = false somewhere in the dependency tree.

std default

enable std

extension default

TCMalloc extension API

Enables extension of libtcmalloc-sys

numa_aware

Enable NUMA-aware allocation. Need to use TCMALLOC_NUMA_AWARE environment variable at runtime. See TCMalloc comments

Enables numa_aware of libtcmalloc-sys

deprecated_perthread

Use deprecated per-thread caching. Newer systems with Linux kernel version >= 4.18 should not use this.

Enables deprecated_perthread of libtcmalloc-sys

legacy_locking

Use legacy locking backend (which is not TLB-aware) See TCMalloc docs

Enables legacy_locking of libtcmalloc-sys

realloc

Use TCMalloc's realloc instead of default GlobalAlloc::realloc. Caveats: All memory deallocations will use the slower unsized TCMallocInternalDeleteAligned (which accesses slow page map). Enable this feature only if you frequently use realloc operations which resides in same size class or same kPageSize-sized blocks, and only after performance measurements or benchmarking. Rust standard library uses realloc of such conditions mainly for manually shrinking operations. Reallocation for growing operation increments size twice, so it will not be the same size class anyway in such case.

8k_pages default

Logical Page Sizes (These features are mutually exclusive).

Larger page size leads to greater performance in expense to increased fragmentation. See TCMalloc tuning guide:

8k pages

Enables 8k_pages of libtcmalloc-sys

32k_pages

Large pages

Enables 32k_pages of libtcmalloc-sys

256k_pages

256k pages

Enables 256k_pages of libtcmalloc-sys

small_but_slow

4k pages, option for memory constrained systems

Enables small_but_slow of libtcmalloc-sys

disable_madv_hugepage_always

Madvise Transparent Hugepages control (Use no more than one value)

By default, if none of these features are enabled, madvise hugepages will be enabled:

Disable madvise hugepages

Enables disable_madv_hugepage_always of libtcmalloc-sys

disable_madv_hugepage_by_var

Disable madvise hugepages via environment variable TCMALLOC_DISABLE_MADV_HUGEPAGE at runtime. This variable can be set to 0 or 1 to enable or disable madvise hugepages respectively.

Enables disable_madv_hugepage_by_var of libtcmalloc-sys