summaryrefslogtreecommitdiff
path: root/numpy/core
diff options
context:
space:
mode:
Diffstat (limited to 'numpy/core')
-rw-r--r--numpy/core/src/multiarray/alloc.c14
1 files changed, 9 insertions, 5 deletions
diff --git a/numpy/core/src/multiarray/alloc.c b/numpy/core/src/multiarray/alloc.c
index addc9f006..e0d2d6056 100644
--- a/numpy/core/src/multiarray/alloc.c
+++ b/numpy/core/src/multiarray/alloc.c
@@ -25,11 +25,8 @@
#include <assert.h>
-#ifdef HAVE_SYS_MMAN_H
+#ifdef NPY_OS_LINUX
#include <sys/mman.h>
-#if defined MADV_HUGEPAGE && defined HAVE_MADVISE
-#define HAVE_MADV_HUGEPAGE
-#endif
#endif
#define NBUCKETS 1024 /* number of buckets for data*/
@@ -74,12 +71,19 @@ _npy_alloc_cache(npy_uintp nelem, npy_uintp esz, npy_uint msz,
#ifdef _PyPyGC_AddMemoryPressure
_PyPyPyGC_AddMemoryPressure(nelem * esz);
#endif
-#ifdef HAVE_MADV_HUGEPAGE
+#ifdef NPY_OS_LINUX
/* allow kernel allocating huge pages for large arrays */
if (NPY_UNLIKELY(nelem * esz >= ((1u<<22u)))) {
npy_uintp offset = 4096u - (npy_uintp)p % (4096u);
npy_uintp length = nelem * esz - offset;
+#ifdef MADV_HUGEPAGE
madvise((void*)((npy_uintp)p + offset), length, MADV_HUGEPAGE);
+#else
+ // Use code 14 (MADV_HUGEPAGE) if it isn't defined. This gives
+ // a chance of enabling huge pages even if build with linux
+ // kernel < 2.6.38
+ madvise((void*)((npy_uintp)p + offset), length, 14);
+#endif
}
#endif
}