Skip to content

Commit f871e9a

Browse files
authored
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
1 parent 6a757da commit f871e9a

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Release the GIL when creating :class:`mmap.mmap` objects on Unix.

Modules/mmapmodule.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1318,9 +1318,9 @@ new_mmap_object(PyTypeObject *type, PyObject *args, PyObject *kwdict)
13181318
}
13191319
}
13201320

1321-
m_obj->data = mmap(NULL, map_size,
1322-
prot, flags,
1323-
fd, offset);
1321+
Py_BEGIN_ALLOW_THREADS
1322+
m_obj->data = mmap(NULL, map_size, prot, flags, fd, offset);
1323+
Py_END_ALLOW_THREADS
13241324

13251325
if (devzero != -1) {
13261326
close(devzero);

0 commit comments

Comments
 (0)