From ba91cd997dbf96fc7ed82894b82e68566601703e Mon Sep 17 00:00:00 2001 From: hauntsaninja Date: Mon, 10 Oct 2022 02:42:13 -0700 Subject: [PATCH 1/3] gh-44098: Release the GIL during mmap 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 speed up you'd expect from doing this. --- Modules/mmapmodule.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Modules/mmapmodule.c b/Modules/mmapmodule.c index 5c05aa738ef564..fdce783fdec5e2 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); From 1be0a0481f48df7a6c413b1711f0a3ff627f3f09 Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Mon, 10 Oct 2022 09:52:23 +0000 Subject: [PATCH 2/3] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../next/Library/2022-10-10-09-52-21.gh-issue-44098.okcqJt.rst | 1 + 1 file changed, 1 insertion(+) 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 00000000000000..70cdb1724a1a3a --- /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. From 7fb2b98d428e4f5e6dde440f275ba349abcedd73 Mon Sep 17 00:00:00 2001 From: hauntsaninja Date: Mon, 10 Oct 2022 14:48:31 -0700 Subject: [PATCH 3/3] update news entry --- .../next/Library/2022-10-10-09-52-21.gh-issue-44098.okcqJt.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 index 70cdb1724a1a3a..4efea4a7c4fccc 100644 --- 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 @@ -1 +1 @@ -Release the GIL when creating :class:`mmap.mmap` objects. +Release the GIL when creating :class:`mmap.mmap` objects on Unix.