Dash Core Source Documentation (0.16.0.1)
Find detailed information regarding the Dash Core source code.
Pool for locked memory chunks. More...
#include <lockedpool.h>
Classes | |
class | LockedPageArena |
Create an arena from locked pages. More... | |
struct | Stats |
Memory statistics. More... | |
Public Types | |
typedef bool(* | LockingFailed_Callback) () |
Callback when allocation succeeds but locking fails. More... | |
Public Member Functions | |
LockedPool (std::unique_ptr< LockedPageAllocator > allocator, LockingFailed_Callback lf_cb_in=nullptr) | |
Create a new LockedPool. More... | |
~LockedPool () | |
LockedPool (const LockedPool &other)=delete | |
LockedPool & | operator= (const LockedPool &)=delete |
void * | alloc (size_t size) |
Allocate size bytes from this arena. More... | |
void | free (void *ptr) |
Free a previously allocated chunk of memory. More... | |
Stats | stats () const |
Get pool usage statistics. More... | |
Static Public Attributes | |
static const size_t | ARENA_SIZE = 256*1024 |
Size of one arena of locked memory. More... | |
static const size_t | ARENA_ALIGN = 16 |
Chunk alignment. More... | |
Private Member Functions | |
bool | new_arena (size_t size, size_t align) |
Private Attributes | |
std::unique_ptr< LockedPageAllocator > | allocator |
std::list< LockedPageArena > | arenas |
LockingFailed_Callback | lf_cb |
size_t | cumulative_bytes_locked |
std::mutex | mutex |
Mutex protects access to this pool's data structures, including arenas. More... | |
Detailed Description
Pool for locked memory chunks.
To avoid sensitive key data from being swapped to disk, the memory in this pool is locked/pinned.
An arena manages a contiguous region of memory. The pool starts out with one arena but can grow to multiple arenas if the need arises.
Unlike a normal C heap, the administrative structures are separate from the managed memory. This has been done as the sizes and bases of objects are not in themselves sensitive information, as to conserve precious locked memory. In some operating systems the amount of memory that can be locked is small.
Definition at line 117 of file lockedpool.h.
Member Typedef Documentation
◆ LockingFailed_Callback
typedef bool(* LockedPool::LockingFailed_Callback) () |
Callback when allocation succeeds but locking fails.
Definition at line 133 of file lockedpool.h.
Constructor & Destructor Documentation
◆ LockedPool() [1/2]
|
explicit |
Create a new LockedPool.
This takes ownership of the MemoryPageLocker, you can only instantiate this with LockedPool(std::move(...)).
The second argument is an optional callback when locking a newly allocated arena failed. If this callback is provided and returns false, the allocation fails (hard fail), if it returns true the allocation proceeds, but it could warn.
Definition at line 261 of file lockedpool.cpp.
◆ ~LockedPool()
LockedPool::~LockedPool | ( | ) |
Definition at line 266 of file lockedpool.cpp.
◆ LockedPool() [2/2]
|
delete |
Member Function Documentation
◆ alloc()
void * LockedPool::alloc | ( | size_t | size | ) |
Allocate size bytes from this arena.
Returns pointer on success, or 0 if memory is full or the application tried to allocate 0 bytes.
Definition at line 269 of file lockedpool.cpp.
References ARENA_ALIGN, ARENA_SIZE, arenas, mutex, and new_arena().
Referenced by secure_allocator< T >::allocate(), and pooled_secure_allocator< T >::internal_secure_allocator::malloc().
◆ free()
void LockedPool::free | ( | void * | ptr | ) |
Free a previously allocated chunk of memory.
Freeing the zero pointer has no effect. Raises std::runtime_error in case of error.
Definition at line 291 of file lockedpool.cpp.
Referenced by secure_allocator< T >::deallocate(), and pooled_secure_allocator< T >::internal_secure_allocator::free().
◆ new_arena()
|
private |
Definition at line 320 of file lockedpool.cpp.
References allocator, arenas, cumulative_bytes_locked, and lf_cb.
Referenced by alloc().
◆ operator=()
|
delete |
◆ stats()
LockedPool::Stats LockedPool::stats | ( | ) | const |
Get pool usage statistics.
Definition at line 305 of file lockedpool.cpp.
References arenas, Arena::Stats::chunks_free, Arena::Stats::chunks_used, cumulative_bytes_locked, Arena::Stats::free, mutex, Arena::Stats::total, and Arena::Stats::used.
Referenced by RPCLockedMemoryInfo().
Member Data Documentation
◆ allocator
|
private |
Definition at line 174 of file lockedpool.h.
Referenced by LockedPoolManager::CreateInstance(), new_arena(), and LockedPool::LockedPageArena::~LockedPageArena().
◆ ARENA_ALIGN
|
static |
Chunk alignment.
Another compromise. Setting this too high will waste memory, setting it too low will facilitate fragmentation.
Definition at line 129 of file lockedpool.h.
Referenced by alloc().
◆ ARENA_SIZE
|
static |
Size of one arena of locked memory.
This is a compromise. Do not set this too low, as managing many arenas will increase allocation and deallocation overhead. Setting it too high allocates more locked memory from the OS than strictly necessary.
Definition at line 125 of file lockedpool.h.
Referenced by alloc().
◆ arenas
|
private |
Definition at line 190 of file lockedpool.h.
Referenced by alloc(), free(), new_arena(), and stats().
◆ cumulative_bytes_locked
|
private |
Definition at line 192 of file lockedpool.h.
Referenced by new_arena(), and stats().
◆ lf_cb
|
private |
Definition at line 191 of file lockedpool.h.
Referenced by new_arena().
◆ mutex
|
mutableprivate |
Mutex protects access to this pool's data structures, including arenas.
Definition at line 195 of file lockedpool.h.
The documentation for this class was generated from the following files:
- src/support/lockedpool.h
- src/support/lockedpool.cpp