Skip to content

bpo-41843: Reenable use of sendfile in shutil module on Solaris #23893

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Doc/library/shutil.rst
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ the use of userspace buffers in Python as in "``outfd.write(infd.read())``".

On macOS `fcopyfile`_ is used to copy the file content (not metadata).

On Linux :func:`os.sendfile` is used.
On Linux and Solaris :func:`os.sendfile` is used.

On Windows :func:`shutil.copyfile` uses a bigger default buffer size (1 MiB
instead of 64 KiB) and a :func:`memoryview`-based variant of
Expand All @@ -529,6 +529,9 @@ file then shutil will silently fallback on using less efficient

.. versionchanged:: 3.8

.. versionchanged:: 3.14
Solaris now uses :func:`os.sendfile`.

.. _shutil-copytree-example:

copytree example
Expand Down
6 changes: 3 additions & 3 deletions Lib/shutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
# This should never be removed, see rationale in:
# https://bugs.python.org/issue43743#msg393429
_USE_CP_SENDFILE = (hasattr(os, "sendfile")
and sys.platform.startswith(("linux", "android")))
and sys.platform.startswith(("linux", "android", "solaris")))
_HAS_FCOPYFILE = posix and hasattr(posix, "_fcopyfile") # macOS

# CMD defaults in Windows 10
Expand Down Expand Up @@ -110,7 +110,7 @@ def _fastcopy_fcopyfile(fsrc, fdst, flags):
def _fastcopy_sendfile(fsrc, fdst):
"""Copy data from one regular mmap-like fd to another by using
high-performance sendfile(2) syscall.
This should work on Linux >= 2.6.33 only.
This should work on Linux >= 2.6.33, Android and Solaris.
"""
# Note: copyfileobj() is left alone in order to not introduce any
# unexpected breakage. Possible risks by using zero-copy calls
Expand Down Expand Up @@ -265,7 +265,7 @@ def copyfile(src, dst, *, follow_symlinks=True):
return dst
except _GiveupOnFastCopy:
pass
# Linux
# Linux / Android / Solaris
elif _USE_CP_SENDFILE:
try:
_fastcopy_sendfile(fsrc, fdst)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Solaris now uses :func:`os.sendfile` fast-copy syscall for more efficient
:mod:`shutil` file copy related functions.
Loading