Skip to content
This repository has been archived by the owner on Oct 2, 2024. It is now read-only.

use kernel fast paths for file copying #1742

Merged
merged 9 commits into from
Oct 27, 2023
Merged

use kernel fast paths for file copying #1742

merged 9 commits into from
Oct 27, 2023

Conversation

reidpr
Copy link
Collaborator

@reidpr reidpr commented Oct 19, 2023

ch-image does a lot of file copying. In particular, as of PR #1741, build cache large files that are stored OOB are copied instead of hard-linked.

The Linux kernel has two fast paths for copying regular files:

  1. Make a reflink copy, where the destination file gets a new inode but shares all the data extents of the source file in a copy-on-write manner. Some filesystems support this.

  2. Copy data in-kernel without passing through user-space. All filesystems support this.

Python ≥3.8 introduces os.copy_file_range() that wraps the underlying system call copy_file_range(2), which does #1 if possible and silently falls back to #2 if not.

This PR implements a fast-path copy that calls os.copy_file_range() if available and the source and destination are on the same filesystem. This should mitigate the performance loss in #1741 to some degree.

@reidpr reidpr added this to the 0.35 milestone Oct 19, 2023
@reidpr reidpr self-assigned this Oct 19, 2023
@reidpr reidpr requested a review from shanegoff October 25, 2023 16:17
Copy link
Contributor

@shanegoff shanegoff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything looks good to me.

@reidpr reidpr merged commit 203b4c5 into master Oct 27, 2023
@reidpr reidpr deleted the reflink-copy branch October 27, 2023 22:43
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants