Skip to content

mmap: creating a file-backed map calls fcntl(fd, F_FULLFSYNC) on macOS with the GIL held #162356

Closed

Description

@maurycy

Feature or enhancement

On macOS, mmap.mmap(fd, ...) calls fcntl(fd, F_FULLFSYNC) before every file-backed mapping, even with a read-only descriptor. It holds the GIL during the call and the result gets ignored:

cpython/Modules/mmapmodule.c

Lines 1881 to 1892 in 865d8d8

#ifdef __APPLE__
/* Issue #11277: fsync(2) is not enough on OS X - a special, OS X specific
fcntl(2) is necessary to force DISKSYNC and get around mmap(2) bug */
if (fd != -1)
(void)fcntl(fd, F_FULLFSYNC);
#endif
if (fd != -1) {
Py_BEGIN_ALLOW_THREADS
fstat_result = _Py_fstat_noraise(fd, &status);
Py_END_ALLOW_THREADS
}

The call was added in #55486 (buildbot crash). On a 32-bit kernel, the HFS+ function hfs_vnop_blockmap() truncated the remaining length of a range awaiting zero-fill to size_t. At 4 GiB the length wrapped to zero, so reading the mapped page raised SIGBUS. A full sync forced HFS+ to zero-fill the range before mapping:

https://github.com/apple-oss-distributions/xnu/blob/161efb48ee9912c6935f205e7ac9c370edb09318/bsd/hfs/hfs_readwrite.c#L2526-L2529

I reproduced the crash on macOS 10.7.5 with the i386 kernel. Since 10.8, macOS has used only 64-bit kernels, where 4 GiB fits in size_t. And PEP 11 lists only x86_64 and aarch64 as supported macOS targets.

Has this already been discussed elsewhere?

No response given

Links to previous discussion of this feature:

Linked PRs

Activity

  1. maurycy commented on Nov 21, 2026

    @maurycy
    ContributorAuthor

    This is a duplicate of #113861

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-featureA feature request or enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions