#include <folly/compression/CompressionContextPoolSingletons.h>
#include <stdlib.h>
#include <folly/Portability.h>
#include <folly/memory/Malloc.h>
#ifndef FOLLY_COMPRESSION_USE_HUGEPAGES
#if defined(__linux__) && !defined(__ANDROID__)
#define FOLLY_COMPRESSION_USE_HUGEPAGES …
#else
#define FOLLY_COMPRESSION_USE_HUGEPAGES …
#endif
#endif
#if FOLLY_COMPRESSION_USE_HUGEPAGES
#include <folly/memory/JemallocHugePageAllocator.h>
#endif
#if FOLLY_HAVE_LIBZSTD
#ifndef ZSTD_STATIC_LINKING_ONLY
#define ZSTD_STATIC_LINKING_ONLY
#endif
#include <zstd.h>
#endif
namespace folly {
namespace compression {
namespace contexts {
#if FOLLY_HAVE_LIBZSTD
namespace {
ZSTD_CCtx_Pool zstd_cctx_pool_singleton;
ZSTD_DCtx_Pool zstd_dctx_pool_singleton;
#if FOLLY_COMPRESSION_USE_HUGEPAGES
constexpr bool use_huge_pages = kIsArchAmd64;
void* huge_page_alloc(void*, size_t size) {
if (size < 16 * 4096) {
return malloc(size);
}
return JemallocHugePageAllocator::allocate(size);
}
void huge_page_free(void*, void* address) {
if (address != nullptr) {
if (JemallocHugePageAllocator::addressInArena(address)) {
JemallocHugePageAllocator::deallocate(address);
} else {
free(address);
}
}
}
ZSTD_customMem huge_page_custom_mem = (use_huge_pages && usingJEMalloc())
? (ZSTD_customMem){huge_page_alloc, huge_page_free, nullptr}
: ZSTD_defaultCMem;
#else
ZSTD_customMem huge_page_custom_mem = …;
#endif
}
ZSTD_CCtx* ZSTD_CCtx_Creator::operator()() const noexcept { … }
ZSTD_DCtx* ZSTD_DCtx_Creator::operator()() const noexcept { … }
void ZSTD_CCtx_Deleter::operator()(ZSTD_CCtx* ctx) const noexcept { … }
void ZSTD_DCtx_Deleter::operator()(ZSTD_DCtx* ctx) const noexcept { … }
void ZSTD_CCtx_Resetter::operator()(ZSTD_CCtx* ctx) const noexcept { … }
void ZSTD_DCtx_Resetter::operator()(ZSTD_DCtx* ctx) const noexcept { … }
ZSTD_CCtx_Pool::Ref getZSTD_CCtx() { … }
ZSTD_DCtx_Pool::Ref getZSTD_DCtx() { … }
ZSTD_CCtx_Pool::Ref getNULL_ZSTD_CCtx() { … }
ZSTD_DCtx_Pool::Ref getNULL_ZSTD_DCtx() { … }
ZSTD_CCtx_Pool& zstd_cctx_pool() { … }
ZSTD_DCtx_Pool& zstd_dctx_pool() { … }
size_t get_zstd_cctx_created_count() { … }
size_t get_zstd_dctx_created_count() { … }
#endif
}
}
}