summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--numpy/core/_add_newdocs.py9
-rw-r--r--numpy/core/multiarray.py2
-rw-r--r--numpy/core/src/multiarray/alloc.c19
-rw-r--r--numpy/core/src/multiarray/alloc.h3
-rw-r--r--numpy/core/src/multiarray/multiarraymodule.c2
5 files changed, 34 insertions, 1 deletions
diff --git a/numpy/core/_add_newdocs.py b/numpy/core/_add_newdocs.py
index baafc9127..304c3a61b 100644
--- a/numpy/core/_add_newdocs.py
+++ b/numpy/core/_add_newdocs.py
@@ -4865,6 +4865,15 @@ add_newdoc('numpy.core.multiarray', 'get_handler_version',
its memory, in which case you can traverse ``a.base`` for a memory handler.
""")
+add_newdoc('numpy.core.multiarray', '_get_madvise_hugepage',
+ """
+ _get_madvise_hugepage() -> bool
+
+ Get use of ``madvise (2)`` MADV_HUGEPAGE support when
+ allocating the array data. Returns the currently set value.
+ See `global_state` for more information.
+ """)
+
add_newdoc('numpy.core.multiarray', '_set_madvise_hugepage',
"""
_set_madvise_hugepage(enabled: bool) -> bool
diff --git a/numpy/core/multiarray.py b/numpy/core/multiarray.py
index 1a37ed3e1..ee88ce30b 100644
--- a/numpy/core/multiarray.py
+++ b/numpy/core/multiarray.py
@@ -16,7 +16,7 @@ from ._multiarray_umath import * # noqa: F403
from ._multiarray_umath import (
_fastCopyAndTranspose, _flagdict, from_dlpack, _insert, _reconstruct,
_vec_string, _ARRAY_API, _monotonicity, _get_ndarray_c_version,
- _set_madvise_hugepage,
+ _get_madvise_hugepage, _set_madvise_hugepage,
)
__all__ = [
diff --git a/numpy/core/src/multiarray/alloc.c b/numpy/core/src/multiarray/alloc.c
index 759a02aeb..6f18054ff 100644
--- a/numpy/core/src/multiarray/alloc.c
+++ b/numpy/core/src/multiarray/alloc.c
@@ -39,6 +39,25 @@ static int _madvise_hugepage = 1;
/*
+ * This function tells whether NumPy attempts to call `madvise` with
+ * `MADV_HUGEPAGE`. `madvise` is only ever used on linux, so the value
+ * of `_madvise_hugepage` may be ignored.
+ *
+ * It is exposed to Python as `np.core.multiarray._get_madvise_hugepage`.
+ */
+NPY_NO_EXPORT PyObject *
+_get_madvise_hugepage(PyObject *NPY_UNUSED(self), PyObject *NPY_UNUSED(args))
+{
+#ifdef NPY_OS_LINUX
+ if (_madvise_hugepage) {
+ Py_RETURN_TRUE;
+ }
+#endif
+ Py_RETURN_FALSE;
+}
+
+
+/*
* This function enables or disables the use of `MADV_HUGEPAGE` on Linux
* by modifying the global static `_madvise_hugepage`.
* It returns the previous value of `_madvise_hugepage`.
diff --git a/numpy/core/src/multiarray/alloc.h b/numpy/core/src/multiarray/alloc.h
index 13c828458..e82f2d947 100644
--- a/numpy/core/src/multiarray/alloc.h
+++ b/numpy/core/src/multiarray/alloc.h
@@ -8,6 +8,9 @@
#define NPY_TRACE_DOMAIN 389047
NPY_NO_EXPORT PyObject *
+_get_madvise_hugepage(PyObject *NPY_UNUSED(self), PyObject *NPY_UNUSED(args));
+
+NPY_NO_EXPORT PyObject *
_set_madvise_hugepage(PyObject *NPY_UNUSED(self), PyObject *enabled_obj);
NPY_NO_EXPORT void *
diff --git a/numpy/core/src/multiarray/multiarraymodule.c b/numpy/core/src/multiarray/multiarraymodule.c
index 5e51bcaa6..ce47276db 100644
--- a/numpy/core/src/multiarray/multiarraymodule.c
+++ b/numpy/core/src/multiarray/multiarraymodule.c
@@ -4488,6 +4488,8 @@ static struct PyMethodDef array_module_methods[] = {
METH_VARARGS, NULL},
{"_get_sfloat_dtype",
get_sfloat_dtype, METH_NOARGS, NULL},
+ {"_get_madvise_hugepage", (PyCFunction)_get_madvise_hugepage,
+ METH_NOARGS, NULL},
{"_set_madvise_hugepage", (PyCFunction)_set_madvise_hugepage,
METH_O, NULL},
{"_reload_guard", (PyCFunction)_reload_guard,