Huge pages support on OS X.

This commit is contained in:
Admin 2017-05-27 10:34:42 +03:00 committed by Admin
parent 8a70202a98
commit 7741c341c7
2 changed files with 38 additions and 3 deletions

View file

@ -87,7 +87,13 @@ if ("${CMAKE_BUILD_TYPE}" STREQUAL "")
endif()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -maes -Wno-pointer-to-int-cast")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -Ofast -funroll-loops -fvariable-expansion-in-unroller -ftree-loop-if-convert-stores -fmerge-all-constants -fbranch-target-load-optimize2")
if (CMAKE_C_COMPILER_ID MATCHES "Clang")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -Ofast -funroll-loops -fvariable-expansion-in-unroller -fmerge-all-constants")
else()
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -Ofast -funroll-loops -fvariable-expansion-in-unroller -ftree-loop-if-convert-stores -fmerge-all-constants -fbranch-target-load-optimize2")
endif()
#set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -gdwarf-2")
#set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -fprofile-generate")
#set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -fprofile-use -fprofile-correction")

View file

@ -24,6 +24,7 @@
#include <stdlib.h>
#include <mm_malloc.h>
#include <sys/mman.h>
#include <mach/vm_statistics.h>
#include "persistent_memory.h"
#include "options.h"
@ -36,12 +37,40 @@ int persistent_memory_flags = 0;
const char * persistent_memory_allocate() {
const int ratio = (opt_double_hash && opt_algo != ALGO_CRYPTONIGHT_LITE) ? 2 : 1;
const int size = MEMORY * (opt_n_threads * ratio + 1);
persistent_memory_flags |= MEMORY_HUGEPAGES_AVAILABLE;
persistent_memory = mmap(0, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, VM_FLAGS_SUPERPAGE_SIZE_2MB, 0);
if (persistent_memory == MAP_FAILED) {
persistent_memory = _mm_malloc(size, 16);
return persistent_memory;
}
persistent_memory_flags |= MEMORY_HUGEPAGES_ENABLED;
if (madvise(persistent_memory, size, MADV_RANDOM | MADV_WILLNEED) != 0) {
applog(LOG_ERR, "madvise failed");
}
if (mlock(persistent_memory, size) == 0) {
persistent_memory_flags |= MEMORY_LOCK;
}
persistent_memory = _mm_malloc(size, 16);
return persistent_memory;
}
void persistent_memory_free() {
_mm_free(persistent_memory);
const int size = MEMORY * (opt_n_threads + 1);
if (persistent_memory_flags & MEMORY_HUGEPAGES_ENABLED) {
if (persistent_memory_flags & MEMORY_LOCK) {
munlock(persistent_memory, size);
}
munmap(persistent_memory, size);
}
else {
_mm_free(persistent_memory);
}
}