MCPcopy
hub / github.com/numpy/numpy / hugepage_setup

Function hugepage_setup

numpy/__init__.py:874–901  ·  view source on GitHub ↗

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

()

Source from the content-addressed store, hash-verified

872 del blas_fpe_check
873
874 def hugepage_setup():
875 """
876 We usually use madvise hugepages support, but on some old kernels it
877 is slow and thus better avoided. Specifically kernel version 4.6
878 had a bug fix which probably fixed this:
879 https://github.com/torvalds/linux/commit/7cf91a98e607c2f935dbcc177d70011e95b8faff
880 """
881 use_hugepage = os.environ.get("NUMPY_MADVISE_HUGEPAGE", None)
882 if sys.platform == "linux" and use_hugepage is None:
883 # If there is an issue with parsing the kernel version,
884 # set use_hugepage to 0. Usage of LooseVersion will handle
885 # the kernel version parsing better, but avoided since it
886 # will increase the import time.
887 # See: #16679 for related discussion.
888 try:
889 use_hugepage = 1
890 kernel_version = os.uname().release.split(".")[:2]
891 kernel_version = tuple(int(v) for v in kernel_version)
892 if kernel_version < (4, 6):
893 use_hugepage = 0
894 except ValueError:
895 use_hugepage = 0
896 elif use_hugepage is None:
897 # This is not Linux, so it should not matter, just enable anyway
898 use_hugepage = 1
899 else:
900 use_hugepage = int(use_hugepage)
901 return use_hugepage
902
903 # Note that this will currently only make a difference on Linux
904 _core.multiarray._set_madvise_hugepage(hugepage_setup())

Callers 1

__init__.pyFile · 0.85

Calls 2

splitMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…