Added support for flexible huge page sizes on Linux.

This commit is contained in:
XMRig 2021-01-31 23:38:57 +07:00
parent 8faef28e7d
commit 09624c4f9b
No known key found for this signature in database
GPG key ID: 446A53638BE94409
11 changed files with 127 additions and 137 deletions

View file

@ -1,7 +1,7 @@
/* XMRig
* Copyright (c) 2018-2020 tevador <tevador@gmail.com>
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -39,6 +39,9 @@ class VirtualMemory
public:
XMRIG_DISABLE_COPY_MOVE_DEFAULT(VirtualMemory)
constexpr static size_t kDefaultHugePageSize = 2U * 1024U * 1024U;
constexpr static size_t kOneGiB = 1024U * 1024U * 1024U;
VirtualMemory(size_t size, bool hugePages, bool oneGbPages, bool usePool, uint32_t node = 0, size_t alignSize = 64);
~VirtualMemory();
@ -65,9 +68,11 @@ public:
static void destroy();
static void flushInstructionCache(void *p, size_t size);
static void freeLargePagesMemory(void *p, size_t size);
static void init(size_t poolSize, bool hugePages);
static void init(size_t poolSize, size_t hugePageSize);
static inline constexpr size_t align(size_t pos, size_t align = 2097152) { return ((pos - 1) / align + 1) * align; }
static inline constexpr size_t align(size_t pos, size_t align = kDefaultHugePageSize) { return ((pos - 1) / align + 1) * align; }
static inline size_t alignToHugePageSize(size_t pos) { return align(pos, hugePageSize()); }
static inline size_t hugePageSize() { return m_hugePageSize; }
private:
enum Flags {
@ -78,15 +83,17 @@ private:
FLAG_MAX
};
static void osInit(bool hugePages);
static void osInit(size_t hugePageSize);
bool allocateLargePagesMemory();
bool allocateOneGbPagesMemory();
void freeLargePagesMemory();
static size_t m_hugePageSize;
const size_t m_size;
size_t m_capacity;
const uint32_t m_node;
size_t m_capacity;
std::bitset<FLAG_MAX> m_flags;
uint8_t *m_scratchpad = nullptr;
};