aboutsummaryrefslogtreecommitdiff
path: root/src/support/allocators
diff options
context:
space:
mode:
authorWladimir J. van der Laan <[email protected]>2016-09-18 09:55:14 +0200
committerWladimir J. van der Laan <[email protected]>2016-10-27 13:17:25 +0200
commit4536148b15595229d0563fb60913b23cb78788ed (patch)
treea59197c39e82d2d16e78ed85940e18227c4105b5 /src/support/allocators
parentwallet: Get rid of LockObject and UnlockObject calls in key.h (diff)
downloaddiscoin-4536148b15595229d0563fb60913b23cb78788ed.tar.xz
discoin-4536148b15595229d0563fb60913b23cb78788ed.zip
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.
Diffstat (limited to 'src/support/allocators')
-rw-r--r--src/support/allocators/secure.h12
1 files changed, 4 insertions, 8 deletions
diff --git a/src/support/allocators/secure.h b/src/support/allocators/secure.h
index 1ec40fe83..67064314e 100644
--- a/src/support/allocators/secure.h
+++ b/src/support/allocators/secure.h
@@ -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);
}
};