Skip to content

Use raw syscalls for copy_file_range() and memfd_create() - #1216

Merged
zanieb merged 1 commit into
astral-sh:mainfrom
daandemeyer:push-zxtsqzsvpxvl
Aug 13, 2026
Merged

Use raw syscalls for copy_file_range() and memfd_create()#1216
zanieb merged 1 commit into
astral-sh:mainfrom
daandemeyer:push-zxtsqzsvpxvl

Conversation

@daandemeyer

Copy link
Copy Markdown
Contributor

glibc only grew the copy_file_range() and memfd_create() wrappers in 2.27, and CPython compiles os.copy_file_range() and os.memfd_create() out when the libc it is built against lacks them. We worked around that by forcing the configure checks on and weak linking the wrappers, which kept the functions out of the os module whenever the runtime glibc was older than 2.27, even on kernels implementing the syscalls.

Backport python/cpython#155520 instead, which calls the wrappers when they exist and issues the raw syscalls when they don't, so both functions work on any sufficiently new kernel regardless of the glibc in use. The UAPI header overlay already provides the NR constants and the MFD flags for all glibc targets. A single patch covers 3.10 through 3.15, so the weak linking patches and the 3.10 specific configure patch go away.

The distribution tests now assert that both functions are always present on Linux GNU targets instead of tying their availability to the runtime libc.

glibc only grew the copy_file_range() and memfd_create() wrappers in
2.27, and CPython compiles os.copy_file_range() and os.memfd_create()
out when the libc it is built against lacks them. We worked around that
by forcing the configure checks on and weak linking the wrappers, which
kept the functions out of the os module whenever the runtime glibc was
older than 2.27, even on kernels implementing the syscalls.

Backport python/cpython#155520 instead, which
calls the wrappers when they exist and issues the raw syscalls when they
don't, so both functions work on any sufficiently new kernel regardless
of the glibc in use. The UAPI header overlay already provides the
__NR_ constants and the MFD_ flags for all glibc targets. A single patch
covers 3.10 through 3.15, so the weak linking patches and the 3.10
specific configure patch go away.

The distribution tests now assert that both functions are always present
on Linux GNU targets instead of tying their availability to the runtime
libc.

Signed-off-by: Daan De Meyer <daan@amutable.com>
@jjhelmus jjhelmus added platform:linux Specific to the Linux platform arch:all Select all architectures build:all python:all Select all Python versions labels Aug 11, 2026
@jjhelmus

Copy link
Copy Markdown
Contributor

This seems like a reasonable approach and once merged upstream I'm in favor of switching.
I'm going to expand the CI matrix to get more complete test coverage.

@daandemeyer

Copy link
Copy Markdown
Contributor Author

Should have been merged upstream by the time you read this message.

@zanieb
zanieb merged commit 1661804 into astral-sh:main Aug 13, 2026
914 of 945 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

arch:all Select all architectures build:all platform:linux Specific to the Linux platform python:all Select all Python versions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants