diff options
author | Yi Wu <yiwu@fb.com> | 2018-10-26 17:27:13 -0700 |
---|---|---|
committer | Facebook Github Bot <facebook-github-bot@users.noreply.github.com> | 2018-10-26 17:29:18 -0700 |
commit | 5f5fddabc78d18d71eb711db12421fdfff866665 (patch) | |
tree | cf601647e73e66656d9de60059c90c65a9b4f3e3 /include | |
parent | 5b4c709fad34e87ce2636eb72a9afcb918da9545 (diff) |
port folly::JemallocNodumpAllocator (#4534)
Summary:
Introduce `JemallocNodumpAllocator`, which allow exclusion of block cache usage from core dump. It utilize custom hook of jemalloc arena, and when jemalloc arena request memory from system, the allocator use the hook to set `MADV_DONTDUMP ` to the memory. The implementation is basically the same as `folly::JemallocNodumpAllocator`, except for some minor difference:
1. It only support jemalloc >= 5.0
2. When the allocator destruct, it explicitly destruct the corresponding arena via `arena.<i>.destroy` via `mallctl`.
Depending on #4502.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/4534
Differential Revision: D10435474
Pulled By: yiwu-arbug
fbshipit-source-id: e80edea755d3853182485d2be710376384ce0bb4
Diffstat (limited to 'include')
-rw-r--r-- | include/rocksdb/memory_allocator.h | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/include/rocksdb/memory_allocator.h b/include/rocksdb/memory_allocator.h index 30b77dfdf..15aab65fc 100644 --- a/include/rocksdb/memory_allocator.h +++ b/include/rocksdb/memory_allocator.h @@ -5,6 +5,10 @@ #pragma once +#include "rocksdb/status.h" + +#include <memory> + namespace rocksdb { // MemoryAllocator is an interface that a client can implement to supply custom @@ -18,10 +22,12 @@ class MemoryAllocator { // Name of the cache allocator, printed in the log virtual const char* Name() const = 0; - // Allocate a block of at least size size + // Allocate a block of at least size. Has to be thread-safe. virtual void* Allocate(size_t size) = 0; - // Deallocate previously allocated block + + // 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 { @@ -30,4 +36,9 @@ class MemoryAllocator { } }; +// Generate cache allocators which allocates through Jemalloc and utilize +// MADV_DONTDUMP through madvice to exclude cache items from core dump. +extern Status NewJemallocNodumpAllocator( + std::shared_ptr<MemoryAllocator>* memory_allocator); + } // namespace rocksdb |