#pragma once
#include <atomic>
#include <vector>
#include "port/jemalloc_helper.h"
#include "port/port.h"
#include "rocksdb/memory_allocator.h"
#include "util/thread_local.h"
#if defined(ROCKSDB_JEMALLOC) && defined(ROCKSDB_PLATFORM_POSIX)
#include <sys/mman.h>
#if (JEMALLOC_VERSION_MAJOR >= 5) && defined(MADV_DONTDUMP)
#define ROCKSDB_JEMALLOC_NODUMP_ALLOCATOR
namespace ROCKSDB_NAMESPACE {
class JemallocNodumpAllocator : public MemoryAllocator {
public:
JemallocNodumpAllocator(JemallocAllocatorOptions& options,
std::unique_ptr<extent_hooks_t>&& arena_hooks,
unsigned arena_index);
~JemallocNodumpAllocator();
const char* Name() const override { return "JemallocNodumpAllocator"; }
void* Allocate(size_t size) override;
void Deallocate(void* p) override;
size_t UsableSize(void* p, size_t allocation_size) const override;
private:
friend Status NewJemallocNodumpAllocator(
JemallocAllocatorOptions& options,
std::shared_ptr<MemoryAllocator>* memory_allocator);
static void* Alloc(extent_hooks_t* extent, void* new_addr, size_t size,
size_t alignment, bool* zero, bool* commit,
unsigned arena_ind);
static Status DestroyArena(unsigned arena_index);
static void DestroyThreadSpecificCache(void* ptr);
int GetThreadSpecificCache(size_t size);
static std::atomic<extent_alloc_t*> original_alloc_;
const JemallocAllocatorOptions options_;
const std::unique_ptr<extent_hooks_t> arena_hooks_;
const unsigned arena_index_;
ThreadLocalPtr tcache_;
};
} #endif #endif