diff options
author | Charles Harris <charlesr.harris@gmail.com> | 2019-08-20 12:49:23 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-08-20 12:49:23 -0600 |
commit | 950dd4e15ea0976bb671148440e036c3ae2dc11d (patch) | |
tree | 5a6eaac9454bd1dbe0dd77c62f3fcfc00a018557 | |
parent | 810d31543d5743fb069848f019f5ca6cc3b677df (diff) | |
parent | 92fa9858db4a17f6818b4241a6d94ffbe7ba1170 (diff) | |
download | numpy-950dd4e15ea0976bb671148440e036c3ae2dc11d.tar.gz |
Merge pull request #14216 from pentschev/enable-hugepages-in-all-builds
ENH: Enable huge pages in all Linux builds
-rw-r--r-- | numpy/core/src/multiarray/alloc.c | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/numpy/core/src/multiarray/alloc.c b/numpy/core/src/multiarray/alloc.c index addc9f006..a7f34cbe5 100644 --- a/numpy/core/src/multiarray/alloc.c +++ b/numpy/core/src/multiarray/alloc.c @@ -25,10 +25,14 @@ #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 +#ifndef MADV_HUGEPAGE +/* + * Use code 14 (MADV_HUGEPAGE) if it isn't defined. This gives a chance of + * enabling huge pages even if built with linux kernel < 2.6.38 + */ +#define MADV_HUGEPAGE 14 #endif #endif @@ -74,11 +78,15 @@ _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; + /** + * Intentionally not checking for errors that may be returned by + * older kernel versions; optimistically tries enabling huge pages. + */ madvise((void*)((npy_uintp)p + offset), length, MADV_HUGEPAGE); } #endif |