Added 1GB hugepages support for Linux
This commit is contained in:
parent
caa2da8bb3
commit
1fbbae1e4a
28 changed files with 156 additions and 50 deletions
|
@ -60,7 +60,7 @@ const char *xmrig::rx_tag()
|
|||
}
|
||||
|
||||
|
||||
bool xmrig::Rx::init(const Job &job, const RxConfig &config, bool hugePages)
|
||||
bool xmrig::Rx::init(const Job &job, const RxConfig &config, bool hugePages, bool oneGbPages)
|
||||
{
|
||||
if (job.algorithm().family() != Algorithm::RANDOM_X) {
|
||||
return true;
|
||||
|
@ -70,7 +70,7 @@ bool xmrig::Rx::init(const Job &job, const RxConfig &config, bool hugePages)
|
|||
return true;
|
||||
}
|
||||
|
||||
d_ptr->queue.enqueue(job, config.nodeset(), config.threads(), hugePages, config.mode());
|
||||
d_ptr->queue.enqueue(job, config.nodeset(), config.threads(), hugePages, oneGbPages, config.mode());
|
||||
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -46,7 +46,7 @@ class RxDataset;
|
|||
class Rx
|
||||
{
|
||||
public:
|
||||
static bool init(const Job &job, const RxConfig &config, bool hugePages);
|
||||
static bool init(const Job &job, const RxConfig &config, bool hugePages, bool oneGbPages);
|
||||
static bool isReady(const Job &job);
|
||||
static RxDataset *dataset(const Job &job, uint32_t nodeId);
|
||||
static std::pair<uint32_t, uint32_t> hugePages();
|
||||
|
|
|
@ -69,11 +69,11 @@ public:
|
|||
}
|
||||
|
||||
|
||||
inline void createDataset(bool hugePages, RxConfig::Mode mode)
|
||||
inline void createDataset(bool hugePages, bool oneGbPages, RxConfig::Mode mode)
|
||||
{
|
||||
const uint64_t ts = Chrono::steadyMSecs();
|
||||
|
||||
m_dataset = new RxDataset(hugePages, true, mode);
|
||||
m_dataset = new RxDataset(hugePages, oneGbPages, true, mode);
|
||||
printAllocStatus(ts);
|
||||
}
|
||||
|
||||
|
@ -157,12 +157,12 @@ std::pair<uint32_t, uint32_t> xmrig::RxBasicStorage::hugePages() const
|
|||
}
|
||||
|
||||
|
||||
void xmrig::RxBasicStorage::init(const RxSeed &seed, uint32_t threads, bool hugePages, RxConfig::Mode mode)
|
||||
void xmrig::RxBasicStorage::init(const RxSeed &seed, uint32_t threads, bool hugePages, bool oneGbPages, RxConfig::Mode mode)
|
||||
{
|
||||
d_ptr->setSeed(seed);
|
||||
|
||||
if (!d_ptr->dataset()) {
|
||||
d_ptr->createDataset(hugePages, mode);
|
||||
d_ptr->createDataset(hugePages, oneGbPages, mode);
|
||||
}
|
||||
|
||||
d_ptr->initDataset(threads);
|
||||
|
|
|
@ -50,7 +50,7 @@ public:
|
|||
protected:
|
||||
RxDataset *dataset(const Job &job, uint32_t nodeId) const override;
|
||||
std::pair<uint32_t, uint32_t> hugePages() const override;
|
||||
void init(const RxSeed &seed, uint32_t threads, bool hugePages, RxConfig::Mode mode) override;
|
||||
void init(const RxSeed &seed, uint32_t threads, bool hugePages, bool oneGbPages, RxConfig::Mode mode) override;
|
||||
|
||||
private:
|
||||
RxBasicStoragePrivate *d_ptr;
|
||||
|
|
|
@ -29,7 +29,6 @@
|
|||
#include "backend/common/Tags.h"
|
||||
#include "base/io/log/Log.h"
|
||||
#include "crypto/common/VirtualMemory.h"
|
||||
#include "crypto/randomx/randomx.h"
|
||||
#include "crypto/rx/RxAlgo.h"
|
||||
#include "crypto/rx/RxCache.h"
|
||||
|
||||
|
@ -41,10 +40,10 @@
|
|||
static_assert(RANDOMX_FLAG_LARGE_PAGES == 1, "RANDOMX_FLAG_LARGE_PAGES flag mismatch");
|
||||
|
||||
|
||||
xmrig::RxDataset::RxDataset(bool hugePages, bool cache, RxConfig::Mode mode) :
|
||||
xmrig::RxDataset::RxDataset(bool hugePages, bool oneGbPages, bool cache, RxConfig::Mode mode) :
|
||||
m_mode(mode)
|
||||
{
|
||||
allocate(hugePages);
|
||||
allocate(hugePages, oneGbPages);
|
||||
|
||||
if (cache) {
|
||||
m_cache = new RxCache(hugePages);
|
||||
|
@ -123,11 +122,13 @@ size_t xmrig::RxDataset::size(bool cache) const
|
|||
std::pair<uint32_t, uint32_t> xmrig::RxDataset::hugePages(bool cache) const
|
||||
{
|
||||
constexpr size_t twoMiB = 2U * 1024U * 1024U;
|
||||
constexpr size_t oneGiB = 1024U * 1024U * 1024U;
|
||||
constexpr size_t cacheSize = VirtualMemory::align(RxCache::maxSize(), twoMiB) / twoMiB;
|
||||
size_t total = VirtualMemory::align(maxSize(), twoMiB) / twoMiB;
|
||||
size_t datasetPageSize = isOneGbPages() ? oneGiB : twoMiB;
|
||||
size_t total = VirtualMemory::align(maxSize(), datasetPageSize) / datasetPageSize;
|
||||
|
||||
uint32_t count = 0;
|
||||
if (isHugePages()) {
|
||||
if (isHugePages() || isOneGbPages()) {
|
||||
count += total;
|
||||
}
|
||||
|
||||
|
@ -159,7 +160,7 @@ void xmrig::RxDataset::setRaw(const void *raw)
|
|||
}
|
||||
|
||||
|
||||
void xmrig::RxDataset::allocate(bool hugePages)
|
||||
void xmrig::RxDataset::allocate(bool hugePages, bool oneGbPages)
|
||||
{
|
||||
if (m_mode == RxConfig::LightMode) {
|
||||
LOG_ERR(CLEAR "%s" RED_BOLD_S "fast RandomX mode disabled by config", rx_tag());
|
||||
|
@ -174,8 +175,14 @@ void xmrig::RxDataset::allocate(bool hugePages)
|
|||
}
|
||||
|
||||
if (hugePages) {
|
||||
m_flags = RANDOMX_FLAG_LARGE_PAGES;
|
||||
m_flags = oneGbPages ? RANDOMX_FLAG_1GB_PAGES : RANDOMX_FLAG_LARGE_PAGES;
|
||||
m_dataset = randomx_alloc_dataset(static_cast<randomx_flags>(m_flags));
|
||||
|
||||
if (oneGbPages && !m_dataset) {
|
||||
LOG_ERR(CLEAR "%s" RED_BOLD_S "Failed to allocate RandomX dataset using 1GB pages", rx_tag());
|
||||
m_flags = RANDOMX_FLAG_LARGE_PAGES;
|
||||
m_dataset = randomx_alloc_dataset(static_cast<randomx_flags>(m_flags));
|
||||
}
|
||||
}
|
||||
|
||||
if (!m_dataset) {
|
||||
|
|
|
@ -31,6 +31,7 @@
|
|||
#include "base/tools/Object.h"
|
||||
#include "crypto/common/Algorithm.h"
|
||||
#include "crypto/randomx/configuration.h"
|
||||
#include "crypto/randomx/randomx.h"
|
||||
#include "crypto/rx/RxConfig.h"
|
||||
|
||||
|
||||
|
@ -50,11 +51,12 @@ class RxDataset
|
|||
public:
|
||||
XMRIG_DISABLE_COPY_MOVE_DEFAULT(RxDataset)
|
||||
|
||||
RxDataset(bool hugePages, bool cache, RxConfig::Mode mode);
|
||||
RxDataset(bool hugePages, bool oneGbPages, bool cache, RxConfig::Mode mode);
|
||||
RxDataset(RxCache *cache);
|
||||
~RxDataset();
|
||||
|
||||
inline bool isHugePages() const { return m_flags & 1; }
|
||||
inline bool isHugePages() const { return m_flags & RANDOMX_FLAG_LARGE_PAGES; }
|
||||
inline bool isOneGbPages() const { return m_flags & RANDOMX_FLAG_1GB_PAGES; }
|
||||
inline randomx_dataset *get() const { return m_dataset; }
|
||||
inline RxCache *cache() const { return m_cache; }
|
||||
inline void setCache(RxCache *cache) { m_cache = cache; }
|
||||
|
@ -68,7 +70,7 @@ public:
|
|||
static inline constexpr size_t maxSize() { return RANDOMX_DATASET_MAX_SIZE; }
|
||||
|
||||
private:
|
||||
void allocate(bool hugePages);
|
||||
void allocate(bool hugePages, bool oneGbPages);
|
||||
|
||||
const RxConfig::Mode m_mode = RxConfig::FastMode;
|
||||
int m_flags = 0;
|
||||
|
|
|
@ -120,12 +120,12 @@ public:
|
|||
}
|
||||
|
||||
|
||||
inline void createDatasets(bool hugePages)
|
||||
inline void createDatasets(bool hugePages, bool oneGbPages)
|
||||
{
|
||||
const uint64_t ts = Chrono::steadyMSecs();
|
||||
|
||||
for (uint32_t node : m_nodeset) {
|
||||
m_threads.emplace_back(allocate, this, node, hugePages);
|
||||
m_threads.emplace_back(allocate, this, node, hugePages, oneGbPages);
|
||||
}
|
||||
|
||||
join();
|
||||
|
@ -188,7 +188,7 @@ public:
|
|||
|
||||
|
||||
private:
|
||||
static void allocate(RxNUMAStoragePrivate *d_ptr, uint32_t nodeId, bool hugePages)
|
||||
static void allocate(RxNUMAStoragePrivate *d_ptr, uint32_t nodeId, bool hugePages, bool oneGbPages)
|
||||
{
|
||||
const uint64_t ts = Chrono::steadyMSecs();
|
||||
|
||||
|
@ -198,7 +198,7 @@ private:
|
|||
return;
|
||||
}
|
||||
|
||||
auto dataset = new RxDataset(hugePages, false, RxConfig::FastMode);
|
||||
auto dataset = new RxDataset(hugePages, oneGbPages, false, RxConfig::FastMode);
|
||||
if (!dataset->get()) {
|
||||
printSkipped(nodeId, "failed to allocate dataset");
|
||||
|
||||
|
@ -346,12 +346,12 @@ std::pair<uint32_t, uint32_t> xmrig::RxNUMAStorage::hugePages() const
|
|||
}
|
||||
|
||||
|
||||
void xmrig::RxNUMAStorage::init(const RxSeed &seed, uint32_t threads, bool hugePages, RxConfig::Mode)
|
||||
void xmrig::RxNUMAStorage::init(const RxSeed &seed, uint32_t threads, bool hugePages, bool oneGbPages, RxConfig::Mode)
|
||||
{
|
||||
d_ptr->setSeed(seed);
|
||||
|
||||
if (!d_ptr->isAllocated()) {
|
||||
d_ptr->createDatasets(hugePages);
|
||||
d_ptr->createDatasets(hugePages, oneGbPages);
|
||||
}
|
||||
|
||||
d_ptr->initDatasets(threads);
|
||||
|
|
|
@ -53,7 +53,7 @@ public:
|
|||
protected:
|
||||
RxDataset *dataset(const Job &job, uint32_t nodeId) const override;
|
||||
std::pair<uint32_t, uint32_t> hugePages() const override;
|
||||
void init(const RxSeed &seed, uint32_t threads, bool hugePages, RxConfig::Mode mode) override;
|
||||
void init(const RxSeed &seed, uint32_t threads, bool hugePages, bool oneGbPages, RxConfig::Mode mode) override;
|
||||
|
||||
private:
|
||||
RxNUMAStoragePrivate *d_ptr;
|
||||
|
|
|
@ -94,7 +94,7 @@ std::pair<uint32_t, uint32_t> xmrig::RxQueue::hugePages()
|
|||
}
|
||||
|
||||
|
||||
void xmrig::RxQueue::enqueue(const RxSeed &seed, const std::vector<uint32_t> &nodeset, uint32_t threads, bool hugePages, RxConfig::Mode mode)
|
||||
void xmrig::RxQueue::enqueue(const RxSeed &seed, const std::vector<uint32_t> &nodeset, uint32_t threads, bool hugePages, bool oneGbPages, RxConfig::Mode mode)
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(m_mutex);
|
||||
|
||||
|
@ -114,7 +114,7 @@ void xmrig::RxQueue::enqueue(const RxSeed &seed, const std::vector<uint32_t> &no
|
|||
return;
|
||||
}
|
||||
|
||||
m_queue.emplace_back(seed, nodeset, threads, hugePages, mode);
|
||||
m_queue.emplace_back(seed, nodeset, threads, hugePages, oneGbPages, mode);
|
||||
m_seed = seed;
|
||||
m_state = STATE_PENDING;
|
||||
|
||||
|
@ -156,7 +156,7 @@ void xmrig::RxQueue::backgroundInit()
|
|||
Buffer::toHex(item.seed.data().data(), 8).data()
|
||||
);
|
||||
|
||||
m_storage->init(item.seed, item.threads, item.hugePages, item.mode);
|
||||
m_storage->init(item.seed, item.threads, item.hugePages, item.oneGbPages, item.mode);
|
||||
|
||||
lock = std::unique_lock<std::mutex>(m_mutex);
|
||||
|
||||
|
|
|
@ -53,8 +53,9 @@ class RxDataset;
|
|||
class RxQueueItem
|
||||
{
|
||||
public:
|
||||
RxQueueItem(const RxSeed &seed, const std::vector<uint32_t> &nodeset, uint32_t threads, bool hugePages, RxConfig::Mode mode) :
|
||||
RxQueueItem(const RxSeed &seed, const std::vector<uint32_t> &nodeset, uint32_t threads, bool hugePages, bool oneGbPages, RxConfig::Mode mode) :
|
||||
hugePages(hugePages),
|
||||
oneGbPages(oneGbPages),
|
||||
mode(mode),
|
||||
seed(seed),
|
||||
nodeset(nodeset),
|
||||
|
@ -62,6 +63,7 @@ public:
|
|||
{}
|
||||
|
||||
const bool hugePages;
|
||||
const bool oneGbPages;
|
||||
const RxConfig::Mode mode;
|
||||
const RxSeed seed;
|
||||
const std::vector<uint32_t> nodeset;
|
||||
|
@ -80,7 +82,7 @@ public:
|
|||
bool isReady(const Job &job);
|
||||
RxDataset *dataset(const Job &job, uint32_t nodeId);
|
||||
std::pair<uint32_t, uint32_t> hugePages();
|
||||
void enqueue(const RxSeed &seed, const std::vector<uint32_t> &nodeset, uint32_t threads, bool hugePages, RxConfig::Mode mode);
|
||||
void enqueue(const RxSeed &seed, const std::vector<uint32_t> &nodeset, uint32_t threads, bool hugePages, bool oneGbPages, RxConfig::Mode mode);
|
||||
|
||||
private:
|
||||
enum State {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue