Skip to content

Block storage copy offloading#768

Open
blktests-ci[bot] wants to merge 12 commits intolinus-master_basefrom
series/1085363=>linus-master
Open

Block storage copy offloading#768
blktests-ci[bot] wants to merge 12 commits intolinus-master_basefrom
series/1085363=>linus-master

Conversation

@blktests-ci
Copy link
Copy Markdown

@blktests-ci blktests-ci Bot commented Apr 24, 2026

Pull request for series with
subject: Block storage copy offloading
version: 1
url: https://patchwork.kernel.org/project/linux-block/list/?series=1085363

@blktests-ci
Copy link
Copy Markdown
Author

blktests-ci Bot commented Apr 24, 2026

Upstream branch: dd6c438
series: https://patchwork.kernel.org/project/linux-block/list/?series=1085363
version: 1

@blktests-ci
Copy link
Copy Markdown
Author

blktests-ci Bot commented Apr 29, 2026

Upstream branch: dca922e
series: https://patchwork.kernel.org/project/linux-block/list/?series=1085363
version: 1

@blktests-ci blktests-ci Bot force-pushed the series/1085363=>linus-master branch from 32053a2 to 9fa1572 Compare April 29, 2026 02:24
@blktests-ci blktests-ci Bot force-pushed the linus-master_base branch from 482ce5b to 5a9f7c7 Compare April 30, 2026 07:29
@blktests-ci
Copy link
Copy Markdown
Author

blktests-ci Bot commented Apr 30, 2026

Upstream branch: e75a43c
series: https://patchwork.kernel.org/project/linux-block/list/?series=1085363
version: 1

@blktests-ci blktests-ci Bot force-pushed the series/1085363=>linus-master branch from 9fa1572 to 447c9b8 Compare April 30, 2026 07:32
@blktests-ci blktests-ci Bot force-pushed the linus-master_base branch from 5a9f7c7 to 25a041f Compare May 3, 2026 02:07
@blktests-ci
Copy link
Copy Markdown
Author

blktests-ci Bot commented May 3, 2026

Upstream branch: 66edb90
series: https://patchwork.kernel.org/project/linux-block/list/?series=1085363
version: 1

@blktests-ci blktests-ci Bot force-pushed the series/1085363=>linus-master branch from 447c9b8 to 2db8ffe Compare May 3, 2026 02:41
@blktests-ci blktests-ci Bot force-pushed the linus-master_base branch from 25a041f to 6f75bd1 Compare May 4, 2026 10:57
@blktests-ci
Copy link
Copy Markdown
Author

blktests-ci Bot commented May 4, 2026

Upstream branch: 6d35786
series: https://patchwork.kernel.org/project/linux-block/list/?series=1085363
version: 1

@blktests-ci blktests-ci Bot force-pushed the series/1085363=>linus-master branch from 2db8ffe to 2693f04 Compare May 4, 2026 11:32
@blktests-ci blktests-ci Bot force-pushed the linus-master_base branch from 6f75bd1 to 1f0d33a Compare May 5, 2026 15:39
@blktests-ci
Copy link
Copy Markdown
Author

blktests-ci Bot commented May 5, 2026

Upstream branch: 6d35786
series: https://patchwork.kernel.org/project/linux-block/list/?series=1085363
version: 1

@blktests-ci blktests-ci Bot force-pushed the series/1085363=>linus-master branch from 2693f04 to 6628caa Compare May 5, 2026 16:03
@blktests-ci blktests-ci Bot force-pushed the linus-master_base branch from 1f0d33a to b1870f6 Compare May 10, 2026 15:59
nj-shetty and others added 9 commits May 10, 2026 16:27
Add the following request queue limits:
 - max_copy_hw_sectors: the maximum number of sectors supported by the
   block driver for a single offloaded copy operation.
 - max_copy_src_segments: the maximum number of source segments
   supported by the block driver for a single offloaded copy operation.
 - max_copy_dst_segments: the maximum number of destination segments
   supported by the block driver for a single offloaded copy operation.
 - max_user_copy_sectors: the maximum number of sectors configured by the
   user for a single offloaded copy operation.
 - max_copy_sectors: the maximum number of sectors for a single
   offloaded copy operation. This is the minimum of the above two
   parameters.

The default value for all these new limits is zero which means that copy
offloading is not supported unless if these limits are set by the block
driver.

ake the following two limits available in sysfs:
 - copy_max_bytes (RW)
 - copy_max_hw_bytes (RO)

These limits will be used by the function that implements copy
offloading to decide the bio size.

Signed-off-by: Nitesh Shetty <nj.shetty@samsung.com>
Signed-off-by: Kanchan Joshi <joshi.k@samsung.com>
Signed-off-by: Anuj Gupta <anuj20.g@samsung.com>
[ bvanassche: Added max_copy_{src,dst}_segments limits. Introduced
  blk_validate_copy_limits(). Introduced BLK_FEAT_STACKING_COPY_OFFL.
  Modified patch description. ]
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Introduce the REQ_OP_COPY_SRC and REQ_OP_COPY_DST operations. The source
and destination LBA range information is in separate bios because any
other approach would require a rewrite of the device mapper. These bios
are associated with each other via the new bi_copy_ctx pointer. A new
pointer has been introduced because the copy offloading context
information must be preserved when cloning a bio and the bi_private bio
member must not be copied when cloning a bio.

This patch supports the following approach for copy offloading:
1. Allocate a struct bio_copy_offload_ctx instance and set phase to
   BLKDEV_TRANSLATE_LBAS.
2. Allocate REQ_OP_COPY_SRC and REQ_OP_COPY_DST bios. Set the
   bi_copy_ctx member of these bios.
3. Set the bio_count member of struct bio_copy_offload_ctx.
4. Submit all REQ_OP_COPY_* bios.
5. In submit_bio(), do the following for REQ_OP_COPY_* bios:
   - If bio->bi_bdev is a stacking device, submit the bio. This will
     send the bio to the device mapper. The device mapper will clone the
     bio, translate the LBAs and will submit the cloned bio. That will
     result in a recursive submit_bio() call.
   - If bio->bi_bdev is not a stacking device, add the bio to the
     copy_ctx->bios list and decrement copy_ctx->bio_count.
6. Once copy_ctx->bio_count == 0, call copy_ctx->translation_complete().
7. In the implementation of copy_ctx->translation_complete(), change
   copy_ctx->phase from BLKDEV_TRANSLATE_LBAS into BLKDEV_COPY.
8. Submit the first REQ_OP_COPY_* bio of the copy_ctx->bios list.
9. Once this bio reaches the block driver associated with the bio,
   retrieve the other bios involved in the copy operation from the copy
   context data structure and convert all these bios into a copy offload
   operation.
10. Once this bio completes, also complete all the other bios involved
    in the copy offload operation.

This patch increases the size of struct bio from 104 to 112 bytes on 64-bit
systems.

To be discussed further: whether adding a new member in struct bio is
acceptable or whether the new pointer perhaps should be stored in front of
the bio. bioset_init() supports front padding.

Signed-off-by: Nitesh Shetty <nj.shetty@samsung.com>
Signed-off-by: Anuj Gupta <anuj20.g@samsung.com>
[ bvanassche: changed the approach of this patch from combining the
  COPY_SRC and COPY_DST operations immediately to translating the LBA
  information first. ]
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Introduce blkdev_copy_offload() for performing copy offloading. This
function implements the algorithm explained the description of the
previous patch. If the input parameters exceed what can be supported
with a single copy offload operation, multiple copy offload operations
are submitted.

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
For the devices which do not support copy offloading, add a function that
copies data by submitting READ and WRITE operations.

Onloaded copying is implemented by reading from the source block device
into memory and by writing this data to the destination block device.

Signed-off-by: Nitesh Shetty <nj.shetty@samsung.com>
Signed-off-by: Vincent Fu <vincent.fu@samsung.com>
Signed-off-by: Anuj Gupta <anuj20.g@samsung.com>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Make it easy for block drivers to iterate over the copy offload bios by
providing accessor functions for the copy offloading bios.

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Prepare for adding copy_file_range() support for block devices by making
the following changes:
 - Change file_inode(file) into file->f_mapping->host. Although only one
   inode is associated with regular files, two inodes are associated
   with block devices. file->f_mapping->host is the primary block device
   inode.
 - Change S_ISREG() into S_ISREG() || S_ISBLK().
 - Add an inode->i_mode & S_IFMT check that verifies that source and
   destination have the same type (block device or regular file).

Reviewed-by: Hannes Reinecke <hare@suse.de>
Signed-off-by: Anuj Gupta <anuj20.g@samsung.com>
Signed-off-by: Nitesh Shetty <nj.shetty@samsung.com>
[ bvanassche: rewrote patch description ]
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Add copy_file_range() support for block devices. If input and output block
devices have been opened with O_DIRECT and if copy offloading is supported
use blkdev_copy_offload(). Otherwise use splice_copy_file_range().

Reviewed-by: Hannes Reinecke <hare@suse.de>
Signed-off-by: Anuj Gupta <anuj20.g@samsung.com>
Signed-off-by: Nitesh Shetty <nj.shetty@samsung.com>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Add support for the NVMe Copy command. This command supports a single
destination range and up to 256 source ranges.

Add trace event support for nvme_copy_cmd.

Signed-off-by: Kanchan Joshi <joshi.k@samsung.com>
Signed-off-by: Nitesh Shetty <nj.shetty@samsung.com>
Signed-off-by: Javier González <javier.gonz@samsung.com>
Signed-off-by: Anuj Gupta <anuj20.g@samsung.com>
[ bvanassche: generalized Copy support from one to 256 source ranges; fixed
  an endianness issue in nvme_config_copy(); renamed rsvd91 into rsvd81 and
  verified the offset with pahole ]
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Support the Copy command for namespaces backed by a block device or by a
file. For namespaces backed by a block device, we call
blkdev_copy_offload() and fall back to blkdev_copy_onload() if necessary.
For namespaces backed by a file we call vfs_copy_file_range().

nvmet always reports that the Copy command is supported.

Tracing support is added for the Copy command.

Signed-off-by: Nitesh Shetty <nj.shetty@samsung.com>
Signed-off-by: Anuj Gupta <anuj20.g@samsung.com>
[ bvanassche: Increased namespace limits. ]
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
In dm_calculate_queue_limits(), clear the copy offload limits if the
device mapper driver does not support copy offloading. This is necessary
since blk_set_stacking_limits() sets the copy offload limits to their
maximum.

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Set BLK_FEAT_STACKING_COPY_OFFL and max_copy_hw_sectors to enable copy
offloading.

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
@blktests-ci
Copy link
Copy Markdown
Author

blktests-ci Bot commented May 10, 2026

Upstream branch: aa54b1d
series: https://patchwork.kernel.org/project/linux-block/list/?series=1085363
version: 1

Implementation is based on existing read and write infrastructure.
copy_max_bytes: A new configfs and module parameter is introduced, which
can be used to set hardware/driver supported maximum copy limit.
Only request based queue mode will support for copy offload.
Added tracefs support to copy IO tracing.

Suggested-by: Damien Le Moal <damien.lemoal@opensource.wdc.com>
Signed-off-by: Anuj Gupta <anuj20.g@samsung.com>
Signed-off-by: Nitesh Shetty <nj.shetty@samsung.com>
Signed-off-by: Vincent Fu <vincent.fu@samsung.com>
[ bvanassche: Split nullb_do_copy() into two functions. Added a
  cond_resched() call inside nullb_do_copy(). ]
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
@blktests-ci blktests-ci Bot force-pushed the series/1085363=>linus-master branch from 6628caa to a48632c Compare May 10, 2026 16:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants