mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-06-03 01:33:20 +02:00
support: Add LockedPool
Add a pool for locked memory chunks, replacing LockedPageManager. This is something I've been wanting to do for a long time. The current approach of locking objects where they happen to be on the stack or heap in-place causes a lot of mlock/munlock system call overhead, slowing down any handling of keys. Also locked memory is a limited resource on many operating systems (and using a lot of it bogs down the system), so the previous approach of locking every page that may contain any key information (but also other information) is wasteful.
This commit is contained in:
@@ -6,7 +6,8 @@
|
||||
#ifndef BITCOIN_SUPPORT_ALLOCATORS_SECURE_H
|
||||
#define BITCOIN_SUPPORT_ALLOCATORS_SECURE_H
|
||||
|
||||
#include "support/pagelocker.h"
|
||||
#include "support/lockedpool.h"
|
||||
#include "support/cleanse.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
@@ -39,20 +40,15 @@ struct secure_allocator : public std::allocator<T> {
|
||||
|
||||
T* allocate(std::size_t n, const void* hint = 0)
|
||||
{
|
||||
T* p;
|
||||
p = std::allocator<T>::allocate(n, hint);
|
||||
if (p != NULL)
|
||||
LockedPageManager::Instance().LockRange(p, sizeof(T) * n);
|
||||
return p;
|
||||
return static_cast<T*>(LockedPoolManager::Instance().alloc(sizeof(T) * n));
|
||||
}
|
||||
|
||||
void deallocate(T* p, std::size_t n)
|
||||
{
|
||||
if (p != NULL) {
|
||||
memory_cleanse(p, sizeof(T) * n);
|
||||
LockedPageManager::Instance().UnlockRange(p, sizeof(T) * n);
|
||||
}
|
||||
std::allocator<T>::deallocate(p, n);
|
||||
LockedPoolManager::Instance().free(p);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user