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
This commit is contained in:
Shantanu 2022-10-10 15:14:31 -07:00 committed by GitHub
parent 6a757da080
commit f871e9a7bb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 3 deletions

View File

@ -0,0 +1 @@
Release the GIL when creating :class:`mmap.mmap` objects on Unix.

View File

@ -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);