Skip to content

Commit 4536148

Browse files
committed
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.
1 parent f4d1fc2 commit 4536148

File tree

7 files changed

+832
-328
lines changed

7 files changed

+832
-328
lines changed

src/Makefile.am

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ BITCOIN_CORE_H = \
133133
support/allocators/secure.h \
134134
support/allocators/zeroafterfree.h \
135135
support/cleanse.h \
136-
support/pagelocker.h \
136+
support/lockedpool.h \
137137
sync.h \
138138
threadsafety.h \
139139
timedata.h \
@@ -310,7 +310,7 @@ libbitcoin_common_a_SOURCES = \
310310
libbitcoin_util_a_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES)
311311
libbitcoin_util_a_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
312312
libbitcoin_util_a_SOURCES = \
313-
support/pagelocker.cpp \
313+
support/lockedpool.cpp \
314314
chainparamsbase.cpp \
315315
clientversion.cpp \
316316
compat/glibc_sanity.cpp \

src/support/allocators/secure.h

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
#ifndef BITCOIN_SUPPORT_ALLOCATORS_SECURE_H
77
#define BITCOIN_SUPPORT_ALLOCATORS_SECURE_H
88

9-
#include "support/pagelocker.h"
9+
#include "support/lockedpool.h"
10+
#include "support/cleanse.h"
1011

1112
#include <string>
1213

@@ -39,20 +40,15 @@ struct secure_allocator : public std::allocator<T> {
3940

4041
T* allocate(std::size_t n, const void* hint = 0)
4142
{
42-
T* p;
43-
p = std::allocator<T>::allocate(n, hint);
44-
if (p != NULL)
45-
LockedPageManager::Instance().LockRange(p, sizeof(T) * n);
46-
return p;
43+
return static_cast<T*>(LockedPoolManager::Instance().alloc(sizeof(T) * n));
4744
}
4845

4946
void deallocate(T* p, std::size_t n)
5047
{
5148
if (p != NULL) {
5249
memory_cleanse(p, sizeof(T) * n);
53-
LockedPageManager::Instance().UnlockRange(p, sizeof(T) * n);
5450
}
55-
std::allocator<T>::deallocate(p, n);
51+
LockedPoolManager::Instance().free(p);
5652
}
5753
};
5854

0 commit comments

Comments
 (0)