#include <folly/memory/JemallocHugePageAllocator.h>
#include <sstream>
#include <folly/CPortability.h>
#include <folly/memory/Malloc.h>
#include <folly/portability/Malloc.h>
#include <folly/portability/String.h>
#include <folly/portability/SysMman.h>
#include <folly/portability/SysTypes.h>
#include <glog/logging.h>
#if (defined(MADV_HUGEPAGE) || defined(MAP_ALIGNED_SUPER)) && \
defined(FOLLY_USE_JEMALLOC) && !FOLLY_SANITIZE
#if defined(__FreeBSD__) || (JEMALLOC_VERSION_MAJOR >= 5)
#define FOLLY_JEMALLOC_HUGE_PAGE_ALLOCATOR_SUPPORTED …
#else
#define FOLLY_JEMALLOC_HUGE_PAGE_ALLOCATOR_SUPPORTED …
#endif
#else
#define FOLLY_JEMALLOC_HUGE_PAGE_ALLOCATOR_SUPPORTED …
#endif
#if !FOLLY_JEMALLOC_HUGE_PAGE_ALLOCATOR_SUPPORTED
#undef MALLOCX_ARENA
#undef MALLOCX_TCACHE_NONE
#undef MADV_HUGEPAGE
#define MALLOCX_ARENA(x) …
#define MALLOCX_TCACHE_NONE …
#define MADV_HUGEPAGE …
#if !defined(JEMALLOC_VERSION_MAJOR) || (JEMALLOC_VERSION_MAJOR < 5)
extent_hooks_t;
extent_alloc_t;
struct extent_hooks_s { … };
#endif
#endif
namespace folly {
namespace {
void print_error(int err, const char* msg) { … }
class HugePageArena { … };
constexpr size_t kHugePageSize = …;
HugePageArena arena;
template <typename T, typename U>
static inline T align_up(T val, U alignment) { … }
void HugePageArena::map_pages(size_t initial_nr_pages, size_t max_nr_pages) { … }
void HugePageArena::init_more(int nr_pages) { … }
bool HugePageArena::setup_next_pages(uintptr_t upto) { … }
void* HugePageArena::allocHook(
extent_hooks_t* extent,
void* new_addr,
size_t size,
size_t alignment,
bool* zero,
bool* commit,
unsigned arena_ind) { … }
int HugePageArena::init(int initial_nr_pages, int max_nr_pages) { … }
void* HugePageArena::reserve(size_t size, size_t alignment) { … }
}
int JemallocHugePageAllocator::flags_{ … };
bool JemallocHugePageAllocator::default_init() { … }
bool JemallocHugePageAllocator::init(int initial_nr_pages, int max_nr_pages) { … }
void* JemallocHugePageAllocator::allocate(size_t size) { … }
void* JemallocHugePageAllocator::reallocate(void* p, size_t size) { … }
void JemallocHugePageAllocator::deallocate(void* p, size_t) { … }
bool JemallocHugePageAllocator::initialized() { … }
size_t JemallocHugePageAllocator::freeSpace() { … }
bool JemallocHugePageAllocator::addressInArena(void* address) { … }
bool JemallocHugePageAllocator::hugePagesAllocSupported() { … }
unsigned arenaIndex() { … }
}