[LU-11621] Add copy_file_range() API and use it for lfs migrate and mirror resync Created: 05/Nov/18  Updated: 15/Nov/23

Status: Open
Project: Lustre
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Improvement Priority: Minor
Reporter: Andreas Dilger Assignee: James A Simmons
Resolution: Unresolved Votes: 0
Labels: None

Issue Links:
Related
is related to LU-6081 hsm: add file migrate support Open
is related to LU-6051 "lfs_migrate" improvements Resolved
is related to LU-10278 lfs migrate: make use of direct i/o o... Resolved
is related to LU-10810 SEEK_HOLE and SEEK_DATA support for l... Resolved
is related to LU-17124 fiemap FIEMAP_FLAG_SYNC flag expects ... Resolved
is related to LU-13945 copy_file_range() compat definition l... Resolved
is related to LU-14208 sanity-hsm test 55 fails with 'reques... Resolved
Rank (Obsolete): 9223372036854775807

 Description   

The copy_file_range() API was added in kernel 4.4 and allows copying data between files without copying the data into userspace and then copying it back to the kernel again. This should significantly speed up file copy operations, for applications which support this interface, and for Lustre tools such as lfs migrate and lfs mirror resync that may be copying a lot of file data. While migrate and resync use O_DIRECT to avoid the data copy to/from userspace, this has other unfortunate effects such as causing sync read and write operations and has often been slower than doing the data copy with async writes (e.g. LU-10278).

The copy_file_range() API in theory allows server-side offload of data copies between files in the same filesystem (and in the near future possibly between different filesystems), which is implemented for NFS and CIFS, and this could be tied into the HSM copytool via LU-6081 to avoid the need to copy the data to/from the client. The copytool itself could also be modified to use copy_file_range() to avoid the data copy on the HSM agent node to improve efficiency once the basic API is available.

This ticket should focus on implementing the basic API and its use with a few of the built-in tools, and separate tickets can be used to implement this in the lhsmtool-posix copytool and pushing the copy action over to HSM agent nodes.

commit 29732938a6289a15e907da234d6692a2ead71855
Author:     Zach Brown <zab@redhat.com>
AuthorDate: Tue Nov 10 16:53:30 2015 -0500

    vfs: add copy_file_range syscall and vfs helper
    
    Add a copy_file_range() system call for offloading copies between
    regular files.
    
    This gives an interface to underlying layers of the storage stack which
    can copy without reading and writing all the data.  There are a few
    candidates that should support copy offloading in the nearer term:
    
    - btrfs shares extent references with its clone ioctl
    - NFS has patches to add a COPY command which copies on the server
    - SCSI has a family of XCOPY commands which copy in the device
    
    This system call avoids the complexity of also accelerating the creation
    of the destination file by operating on an existing destination file
    descriptor, not a path.
    
    Currently the high level vfs entry point limits copy offloading to files
    on the same mount and super (and not in the same file).  This can be
    relaxed if we get implementations which can copy between file systems
    safely.

Later patches implement the ->copy_file_range method for various filesystems:

3db11b2eecc0 btrfs: add .copy_file_range file operation
2e72448b07dc NFS: Add COPY nfs operation
9fe26045e98f xfs: add clone file and clone range vfs functions
620d8745b35d cifs: Introduce cifs_copy_file_range()


 Comments   
Comment by James A Simmons [ 05/Nov/18 ]

Believe it no not I was planning on using this API to do my file presentation project. We can "create" new files out of various components of already existing files. I can take this up. The tricky part will be the non-aligned copies with components. 

Comment by Gerrit Updater [ 18/May/20 ]

James Simmons (jsimmons@infradead.org) uploaded a new patch: https://review.whamcloud.com/38651
Subject: LU-11621 utils: optimize lhsmtool_posix with copy_file_range()
Project: fs/lustre-release
Branch: master
Current Patch Set: 1
Commit: 04bd4a2da275a8c9878a5a2961f0c6ad64af9ee5

Comment by James A Simmons [ 22/May/20 ]

More work is coming

Comment by Gerrit Updater [ 27/May/20 ]

Oleg Drokin (green@whamcloud.com) merged in patch https://review.whamcloud.com/38651/
Subject: LU-11621 utils: optimize lhsmtool_posix with copy_file_range()
Project: fs/lustre-release
Branch: master
Current Patch Set:
Commit: ccac422cf9dd3b2390d1c70cd42eff06d2f53be3

Comment by Gerrit Updater [ 09/Jun/20 ]

James Simmons (jsimmons@infradead.org) uploaded a new patch: https://review.whamcloud.com/38883
Subject: LU-11621 utils: optimize migrate_copy_data() with copy_file_range()
Project: fs/lustre-release
Branch: master
Current Patch Set: 1
Commit: eb8f28a159a2e9ebd27416fd62030787d5729a9e

Comment by Gerrit Updater [ 10/Jul/20 ]

James Simmons (jsimmons@infradead.org) uploaded a new patch: https://review.whamcloud.com/39337
Subject: LU-11621 utils: optimize lustre_rsync with copy_file_range()
Project: fs/lustre-release
Branch: master
Current Patch Set: 1
Commit: f5aa44ebdd24a2e511eca6ced8a0e0da7738f842

Comment by Gerrit Updater [ 05/Nov/20 ]

James Simmons (jsimmons@infradead.org) uploaded a new patch: https://review.whamcloud.com/40548
Subject: LU-11621 utils: add special code to profile performance
Project: fs/lustre-release
Branch: master
Current Patch Set: 1
Commit: ecef87f84b0e277d230db5b847357da84ca83e92

Generated at Sat Feb 10 02:45:28 UTC 2024 using Jira 9.4.14#940014-sha1:734e6822bbf0d45eff9af51f82432957f73aa32c.