Added 1GB hugepages support for Linux

This commit is contained in:
SChernykh 2019-12-05 19:39:47 +01:00
parent caa2da8bb3
commit 1fbbae1e4a
28 changed files with 156 additions and 50 deletions

View file

@ -57,4 +57,12 @@ namespace randomx {
freePagedMemory(ptr, count);
};
void* OneGbPageAllocator::allocMemory(size_t count) {
return allocOneGbPagesMemory(count);
}
void OneGbPageAllocator::freeMemory(void* ptr, size_t count) {
freePagedMemory(ptr, count);
};
}

View file

@ -43,4 +43,9 @@ namespace randomx {
static void freeMemory(void*, size_t);
};
struct OneGbPageAllocator {
static void* allocMemory(size_t);
static void freeMemory(void*, size_t);
};
}

View file

@ -333,7 +333,11 @@ extern "C" {
try {
dataset = new randomx_dataset();
if (flags & RANDOMX_FLAG_LARGE_PAGES) {
if (flags & RANDOMX_FLAG_1GB_PAGES) {
dataset->dealloc = &randomx::deallocDataset<randomx::OneGbPageAllocator>;
dataset->memory = (uint8_t*)randomx::OneGbPageAllocator::allocMemory(RANDOMX_DATASET_MAX_SIZE);
}
else if (flags & RANDOMX_FLAG_LARGE_PAGES) {
dataset->dealloc = &randomx::deallocDataset<randomx::LargePageAllocator>;
dataset->memory = (uint8_t*)randomx::LargePageAllocator::allocMemory(RANDOMX_DATASET_MAX_SIZE);
}

View file

@ -48,6 +48,7 @@ enum randomx_flags {
RANDOMX_FLAG_HARD_AES = 2,
RANDOMX_FLAG_FULL_MEM = 4,
RANDOMX_FLAG_JIT = 8,
RANDOMX_FLAG_1GB_PAGES = 16,
};

View file

@ -53,6 +53,16 @@ void* allocLargePagesMemory(std::size_t bytes) {
}
void* allocOneGbPagesMemory(std::size_t bytes) {
void* mem = xmrig::VirtualMemory::allocateOneGbPagesMemory(bytes);
if (mem == nullptr) {
throw std::runtime_error("Failed to allocate 1GB pages memory");
}
return mem;
}
void freePagedMemory(void* ptr, std::size_t bytes) {
xmrig::VirtualMemory::freeLargePagesMemory(ptr, bytes);
}

View file

@ -32,4 +32,5 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
void* allocExecutableMemory(std::size_t);
void* allocLargePagesMemory(std::size_t);
void* allocOneGbPagesMemory(std::size_t);
void freePagedMemory(void*, std::size_t);