diff --git a/lib/kernel/kernel.c b/lib/kernel/kernel.c index bf79d8968..e500eb2fc 100644 --- a/lib/kernel/kernel.c +++ b/lib/kernel/kernel.c @@ -44,6 +44,13 @@ int kernel_get_cacheline_size() #endif } +#if defined(__linux__) || defined(__APPLE__) +int kernel_get_page_size() +{ + return sysconf(_SC_PAGESIZE); +} +#endif + #ifdef __linux__ int kernel_module_set_param(const char *module, const char *param, const char *value) @@ -164,11 +171,6 @@ out: return -1; /* not found or error */ } -int kernel_get_page_size() -{ - return sysconf(_SC_PAGESIZE); -} - /* There is no sysconf interface to get the hugepage size */ int kernel_get_hugepage_size() { diff --git a/lib/memory/hugepage.c b/lib/memory/hugepage.c index 2dea0cff2..9b3493659 100644 --- a/lib/memory/hugepage.c +++ b/lib/memory/hugepage.c @@ -33,10 +33,9 @@ /* Required to allocate hugepages on Apple OS X */ #ifdef __MACH__ #include -#elif defined(__linux__) - #include #endif +#include #include #include #include @@ -73,7 +72,7 @@ static struct memory_allocation * memory_hugepage_alloc(struct memory_type *m, s ma->address = mmap(NULL, ma->length, prot, flags, -1, 0); if (ma->address == MAP_FAILED) { //try again without hugepages as fallback solution, warn the user - + prot= PROT_READ | PROT_WRITE; //same flags as above without hugepages flags = MAP_PRIVATE | MAP_ANONYMOUS; @@ -83,7 +82,7 @@ static struct memory_allocation * memory_hugepage_alloc(struct memory_type *m, s } #endif //length has to be aligned with pagesize - ma->length = ALIGN(len, getpagesize()); + ma->length = ALIGN(len, kernel_get_page_size()); //try mmap again ma->address = mmap(NULL, ma->length, prot, flags, -1, 0); if(ma->address == MAP_FAILED){