summaryrefslogtreecommitdiff
path: root/numpy/__init__.py
diff options
context:
space:
mode:
authorSebastian Berg <sebastian@sipsolutions.net>2020-03-17 13:07:56 -0500
committerSebastian Berg <sebastian@sipsolutions.net>2020-03-17 13:19:56 -0500
commit2d6edb3677a9d3e4a4c85c91809cd9f4b9b9efbb (patch)
tree041d50543915b69167fa31e8bd7acb4e1b127475 /numpy/__init__.py
parent4f2b219647ae6a7928590be2b709894ae2403274 (diff)
downloadnumpy-2d6edb3677a9d3e4a4c85c91809cd9f4b9b9efbb.tar.gz
ENH: Allow toggling madvise hugepage and fix default
By default this disables madvise hugepage on kernels before 4.6, since we expect that these typically see large performance regressions when using hugepages due to slow defragementation code presumably fixed by: https://github.com/torvalds/linux/commit/7cf91a98e607c2f935dbcc177d70011e95b8faff This adds support to set the behaviour at startup time through the ``NUMPY_MADVISE_HUGEPAGE`` environment variable. Fixes gh-15545
Diffstat (limited to 'numpy/__init__.py')
-rw-r--r--numpy/__init__.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/numpy/__init__.py b/numpy/__init__.py
index 1d8570f71..42adfc085 100644
--- a/numpy/__init__.py
+++ b/numpy/__init__.py
@@ -286,3 +286,24 @@ else:
error_message))
raise RuntimeError(msg)
del _mac_os_check
+
+ # We usually use madvise hugepages support, but on some old kernels it
+ # is slow and thus better avoided.
+ # Specifically kernel version 4.6 had a bug fix which probably fixed this:
+ # https://github.com/torvalds/linux/commit/7cf91a98e607c2f935dbcc177d70011e95b8faff
+ import os
+ use_hugepage = os.environ.get("NUMPY_MADVISE_HUGEPAGE", None)
+ if sys.platform == "linux" and use_hugepage is None:
+ use_hugepage = 1
+ kernel_version = os.uname().release.split(".")[:2]
+ kernel_version = tuple(int(v) for v in kernel_version)
+ if kernel_version < (4, 6):
+ use_hugepage = 0
+ elif use_hugepage is None:
+ # This is not Linux, so it should not matter, just enable anyway
+ use_hugepage = 1
+ else:
+ use_hugepage = int(use_hugepage)
+
+ # Note that this will currently only make a difference on Linux
+ core.multiarray._multiarray_umath._set_madvise_hugepage(use_hugepage)