Implemented unified cryptonight and RandomX scratchpad memory.
This commit is contained in:
parent
5699147aab
commit
20313cbc56
30 changed files with 434 additions and 297 deletions
|
@ -29,6 +29,7 @@
|
|||
#include <sys/mman.h>
|
||||
|
||||
|
||||
#include "crypto/common/portable/mm_malloc.h"
|
||||
#include "crypto/common/VirtualMemory.h"
|
||||
|
||||
|
||||
|
@ -37,6 +38,47 @@
|
|||
#endif
|
||||
|
||||
|
||||
xmrig::VirtualMemory::VirtualMemory(size_t size, bool hugePages, size_t align) :
|
||||
m_size(VirtualMemory::align(size))
|
||||
{
|
||||
if (hugePages) {
|
||||
m_scratchpad = static_cast<uint8_t*>(allocateLargePagesMemory(m_size));
|
||||
if (m_scratchpad) {
|
||||
m_flags |= HUGEPAGES;
|
||||
|
||||
madvise(m_scratchpad, size, MADV_RANDOM | MADV_WILLNEED);
|
||||
|
||||
if (mlock(m_scratchpad, m_size) == 0) {
|
||||
m_flags |= LOCK;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
m_scratchpad = static_cast<uint8_t*>(_mm_malloc(m_size, align));
|
||||
}
|
||||
|
||||
|
||||
xmrig::VirtualMemory::~VirtualMemory()
|
||||
{
|
||||
if (!m_scratchpad) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (isHugePages()) {
|
||||
if (m_flags & LOCK) {
|
||||
munlock(m_scratchpad, m_size);
|
||||
}
|
||||
|
||||
freeLargePagesMemory(m_scratchpad, m_size);
|
||||
}
|
||||
else {
|
||||
_mm_free(m_scratchpad);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void *xmrig::VirtualMemory::allocateExecutableMemory(size_t size)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue