Packages
rocksdb
2.6.0
3.1.1
3.1.0
3.0.0
2.6.2
2.6.1
retired
2.6.0
retired
2.5.0
2.4.1
2.4.0
2.3.0
2.2.0
2.1.0
2.0.0
1.9.0
1.8.0
1.7.0
1.6.0
1.5.1
1.5.0
1.4.0
1.3.2
1.3.1
1.3.0
1.2.0
1.1.1
1.1.0
1.0.0
0.26.2
0.26.1
0.26.0
0.25.0
0.24.0
0.23.3
0.23.2
0.23.1
0.23.0
0.22.0
0.21.0
0.20.1
0.20.0
0.19.0
0.18.0
0.17.0
0.16.0
0.15.0
0.14.0
0.13.1
0.13.0
0.12.0
0.11.0
0.10.0
0.9.1
0.9.0
0.8.2
0.8.1
0.8.0
0.7.1
0.7.0
0.6.4
0.6.3
0.6.2
0.6.1
0.6.0
RocksDB for Erlang
Retired package: Release invalid - Use 2.6.1 instead
Current section
Files
Jump to
Current section
Files
deps/rocksdb/include/rocksdb/memory_allocator.h
// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
// This source code is licensed under both the GPLv2 (found in the
// COPYING file in the root directory) and Apache 2.0 License
// (found in the LICENSE.Apache file in the root directory).
#pragma once
#include <memory>
#include "rocksdb/customizable.h"
#include "rocksdb/status.h"
namespace ROCKSDB_NAMESPACE {
// MemoryAllocator is an interface that a client can implement to supply custom
// memory allocation and deallocation methods. See rocksdb/cache.h for more
// information.
// All methods should be thread-safe.
class MemoryAllocator : public Customizable {
public:
static const char* Type() { return "MemoryAllocator"; }
static Status CreateFromString(const ConfigOptions& options,
const std::string& value,
std::shared_ptr<MemoryAllocator>* result);
// Allocate a block of at least size. Has to be thread-safe.
virtual void* Allocate(size_t size) = 0;
// Deallocate previously allocated block. Has to be thread-safe.
virtual void Deallocate(void* p) = 0;
// Returns the memory size of the block allocated at p. The default
// implementation that just returns the original allocation_size is fine.
virtual size_t UsableSize(void* /*p*/, size_t allocation_size) const {
// default implementation just returns the allocation size
return allocation_size;
}
std::string GetId() const override { return GenerateIndividualId(); }
};
struct JemallocAllocatorOptions {
static const char* kName() { return "JemallocAllocatorOptions"; }
// Jemalloc tcache cache allocations by size class. For each size class,
// it caches between 20 (for large size classes) to 200 (for small size
// classes). To reduce tcache memory usage in case the allocator is access
// by large number of threads, we can control whether to cache an allocation
// by its size.
bool limit_tcache_size = false;
// Lower bound of allocation size to use tcache, if limit_tcache_size=true.
// When used with block cache, it is recommended to set it to block_size/4.
size_t tcache_size_lower_bound = 1024;
// Upper bound of allocation size to use tcache, if limit_tcache_size=true.
// When used with block cache, it is recommended to set it to block_size.
size_t tcache_size_upper_bound = 16 * 1024;
// Number of arenas across which we spread allocation requests. Increasing
// this setting can mitigate arena mutex contention. The value must be
// positive.
size_t num_arenas = 1;
};
// Generate 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 (see also
// `JemallocAllocatorOptions::num_arenas` above), 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.
Status NewJemallocNodumpAllocator(
const JemallocAllocatorOptions& options,
std::shared_ptr<MemoryAllocator>* memory_allocator);
} // namespace ROCKSDB_NAMESPACE