From f871e9a7bb4eb823da481b99052636763ec8e710 Mon Sep 17 00:00:00 2001 From: Shantanu <12621235+hauntsaninja@users.noreply.github.com> Date: Mon, 10 Oct 2022 15:14:31 -0700 Subject: [PATCH] gh-44098: Release the GIL during mmap on Unix (GH-98146) This seems pretty straightforward. The issue mentions other calls in mmapmodule that we could release the GIL on, but those are in methods where we'd need to be careful to ensure that something sensible happens if those are called concurrently. In prior art, note that #12073 released the GIL for munmap. In a toy benchmark, I see the speedup you'd expect from doing this. Automerge-Triggered-By: GH:gvanrossum --- .../Library/2022-10-10-09-52-21.gh-issue-44098.okcqJt.rst | 1 + Modules/mmapmodule.c | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) create mode 100644 Misc/NEWS.d/next/Library/2022-10-10-09-52-21.gh-issue-44098.okcqJt.rst diff --git a/Misc/NEWS.d/next/Library/2022-10-10-09-52-21.gh-issue-44098.okcqJt.rst b/Misc/NEWS.d/next/Library/2022-10-10-09-52-21.gh-issue-44098.okcqJt.rst new file mode 100644 index 00000000000..4efea4a7c4f --- /dev/null +++ b/Misc/NEWS.d/next/Library/2022-10-10-09-52-21.gh-issue-44098.okcqJt.rst @@ -0,0 +1 @@ +Release the GIL when creating :class:`mmap.mmap` objects on Unix. diff --git a/Modules/mmapmodule.c b/Modules/mmapmodule.c index 5c05aa738ef..fdce783fdec 100644 --- a/Modules/mmapmodule.c +++ b/Modules/mmapmodule.c @@ -1318,9 +1318,9 @@ new_mmap_object(PyTypeObject *type, PyObject *args, PyObject *kwdict) } } - m_obj->data = mmap(NULL, map_size, - prot, flags, - fd, offset); + Py_BEGIN_ALLOW_THREADS + m_obj->data = mmap(NULL, map_size, prot, flags, fd, offset); + Py_END_ALLOW_THREADS if (devzero != -1) { close(devzero);