Bitcoin
Classes | Public Types | Public Member Functions | Static Public Attributes | Private Member Functions | Private Attributes | List of all members
LockedPool Class Reference

#include <lockedpool.h>

Inheritance diagram for LockedPool:
LockedPoolManager

Classes

class  LockedPageArena
 
struct  Stats
 

Public Types

typedef bool(* LockingFailed_Callback) ()
 

Public Member Functions

 LockedPool (std::unique_ptr< LockedPageAllocator > allocator, LockingFailed_Callback lf_cb_in=nullptr)
 
 ~LockedPool ()
 
 LockedPool (const LockedPool &other)=delete
 
LockedPooloperator= (const LockedPool &)=delete
 
void * alloc (size_t size)
 
void free (void *ptr)
 
Stats stats () const
 

Static Public Attributes

static const size_t ARENA_SIZE = 256*1024
 
static const size_t ARENA_ALIGN = 16
 

Private Member Functions

bool new_arena (size_t size, size_t align)
 

Private Attributes

std::unique_ptr< LockedPageAllocatorallocator
 
std::list< LockedPageArenaarenas
 
LockingFailed_Callback lf_cb
 
size_t cumulative_bytes_locked
 
std::mutex mutex
 

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.

Member Typedef Documentation

◆ LockingFailed_Callback

typedef bool(* LockedPool::LockingFailed_Callback) ()

Callback when allocation succeeds but locking fails.

Constructor & Destructor Documentation

◆ LockedPool() [1/2]

LockedPool::LockedPool ( std::unique_ptr< LockedPageAllocator allocator,
LockingFailed_Callback  lf_cb_in = nullptr 
)
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.

◆ ~LockedPool()

LockedPool::~LockedPool ( )

◆ LockedPool() [2/2]

LockedPool::LockedPool ( const LockedPool other)
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.

◆ 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.

◆ new_arena()

bool LockedPool::new_arena ( size_t  size,
size_t  align 
)
private

◆ operator=()

LockedPool& LockedPool::operator= ( const LockedPool )
delete

◆ stats()

LockedPool::Stats LockedPool::stats ( ) const

Get pool usage statistics

Member Data Documentation

◆ allocator

std::unique_ptr<LockedPageAllocator> LockedPool::allocator
private

◆ ARENA_ALIGN

const size_t LockedPool::ARENA_ALIGN = 16
static

Chunk alignment. Another compromise. Setting this too high will waste memory, setting it too low will facilitate fragmentation.

◆ ARENA_SIZE

const size_t LockedPool::ARENA_SIZE = 256*1024
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.

◆ arenas

std::list<LockedPageArena> LockedPool::arenas
private

◆ cumulative_bytes_locked

size_t LockedPool::cumulative_bytes_locked
private

◆ lf_cb

LockingFailed_Callback LockedPool::lf_cb
private

◆ mutex

std::mutex LockedPool::mutex
mutableprivate

Mutex protects access to this pool's data structures, including arenas.


The documentation for this class was generated from the following files: