Support trim with multiple ranges
A message that is not in the archive (sent off-list or not yet received): CGME20240215100103epcas5p3271477465b0155deb7483f26858087ec@epcas5p3.samsung.com
v2 cover Support trim with multiple ranges
NVMe specification allow multiple ranges for the dataset management command. The block ioctl only accepts a single entry for trim, but with nvme character device we can send multiple ranges.
The first patch in this series adds an option num_range to send multiple range per trim request. This will only work if the data direction is solely trim i.e. trim or randtrim.
The next two patches in this series updates io_uring_cmd ioengine with the required changes.
Note: The first patch which changes the io_u request for multiple ranges can be used in future for NVMe copy command which copies multiple source range entries to single destination.
Changes since v1:
- Remove unnecessary else conditions and bump server version as suggested by Jens.
- Separate function to fill buffer with source range entries as suggested by Jens.
- Debug log for trim offsets and man page update for num_range as suggested by Vincent.
Ankit Kumar (3):
trim: add support for multiple ranges engines/nvme: pass offset and len instead of io_u engines/io_uring: add multi range dsm support
HOWTO.rst | 9 +++ backend.c | 20 ++++- cconv.c | 2 + engines/io_uring.c | 34 +++++++-- engines/nvme.c | 72 +++++++++++------- engines/nvme.h | 7 +- examples/uring-cmd-trim-multi-range.fio | 21 ++++++ fio.1 | 7 ++ fio.h | 18 +++++ init.c | 13 ++++ io_u.c | 97 +++++++++++++++++++++---- io_u.h | 4 + ioengines.h | 2 + options.c | 11 +++ server.h | 2 +- thread_options.h | 3 + 16 files changed, 266 insertions(+), 56 deletions(-) create mode 100644 examples/uring-cmd-trim-multi-range.fio
Signature · 1 line
2.25.1
PATCH v2 1/3 trim: add support for multiple ranges
NVMe specification allow multiple ranges for the dataset management commands. Currently the block ioctl only allows a single range for trim, however multiple ranges can be specified using nvme character device.
Add an option num_range to send multiple range per trim request, which only works if the data direction is solely trim i.e. trim or randtrim. Add FIO_MULTI_RANGE_TRIM as the ioengine flag, to restrict the usage of this new option.
For multi range trim request this modifies the way IO buffers are used. The buffer length will depend on number of trim ranges and the actual buffer will contains start and length of each range entry.
This increases fio server version (FIO_SERVER_VER) to 103.
--- HOWTO.rst | 9 +++++ backend.c | 20 ++++++++-- cconv.c | 2 + fio.1 | 7 ++++ fio.h | 18 +++++++++ init.c | 13 +++++++ io_u.c | 97 ++++++++++++++++++++++++++++++++++++++++-------- io_u.h | 4 ++ ioengines.h | 2 + options.c | 11 ++++++ server.h | 2 +- thread_options.h | 3 ++ 12 files changed, 168 insertions(+), 20 deletions(-)
HOWTO.rst +9 -0
@@ -2534,6 +2534,15 @@ with the caveat that when used on the command line, they must come after the Specifies logical block application tag mask value, if namespace is formatted to use end to end protection information. Default: 0xffff. +.. option:: num_range=int : [io_uring_cmd] + + For trim command this will be the number of ranges to trim per I/O + request. The number of logical blocks per range is determined by the + :option:`bs` option which should be a multiple of logical block size. + This cannot be used with read or write. Note that setting this + option > 1, :option:`log_offset` will not be able to log all the + offsets. Default: 1. + .. option:: cpuload=int : [cpuio] Attempt to use the specified percentage of CPU cycles. This is a mandatory
backend.c +17 -3
@@ -1333,7 +1333,7 @@ static int init_io_u(struct thread_data *td)int init_io_u_buffers (struct thread_data *td) {struct io_u *io_u; -unsigned long long max_bs, min_write; +unsigned long long max_bs, min_write, trim_bs =0 ;int i, max_units;int data_xfer =1 ;char *p;
@@ -1344,7 +1344,18 @@ int init_io_u_buffers(struct thread_data *td) td->orig_buffer_size = (unsigned long long ) max_bs * (unsigned long long ) max_units; -if (td_ioengine_flagged (td,FIO_NOIO ) || !(td_read (td) ||td_write (td))) +if (td_trim (td) && td->o.num_range >1 ) { + trim_bs = td->o.num_range *sizeof (struct trim_range ); + td->orig_buffer_size = trim_bs + * (unsigned long long ) max_units; + } + +/* +* For reads, writes, and multi-range trim operations we need a +* data buffer +*/ +if (td_ioengine_flagged (td,FIO_NOIO ) || + !(td_read (td) ||td_write (td) || (td_trim (td) && td->o.num_range >1 ))) data_xfer =0 ;/*
@@ -1396,7 +1407,10 @@ int init_io_u_buffers(struct thread_data *td)fill_verify_pattern (td, io_u->buf, max_bs, io_u,0 ,0 ); } } - p += max_bs; +if (td_trim (td) && td->o.num_range >1 ) + p += trim_bs; +else + p += max_bs; }return 0 ;
cconv.c +2 -0
@@ -111,6 +111,7 @@ int convert_thread_options_to_cpu(struct thread_options *o, o->serialize_overlap =le32_to_cpu (top->serialize_overlap); o->size =le64_to_cpu (top->size); o->io_size =le64_to_cpu (top->io_size); + o->num_range =le32_to_cpu (top->num_range); o->size_percent =le32_to_cpu (top->size_percent); o->io_size_percent =le32_to_cpu (top->io_size_percent); o->fill_device =le32_to_cpu (top->fill_device);
@@ -609,6 +610,7 @@ void convert_thread_options_to_net(struct thread_options_pack *top, top->size =__cpu_to_le64 (o->size); top->io_size =__cpu_to_le64 (o->io_size); + top->num_range =__cpu_to_le32 (o->num_range); top->verify_backlog =__cpu_to_le64 (o->verify_backlog); top->start_delay =__cpu_to_le64 (o->start_delay); top->start_delay_high =__cpu_to_le64 (o->start_delay_high);
fio.1 +7 -0
@@ -2293,6 +2293,13 @@ end to end protection information. Default: 0x1234. Specifies logical block application tag mask value, if namespace is formatted to use end to end protection information. Default: 0xffff. .TP +.BI (io_uring_cmd)num_range \fR=\fPint +For trim command this will be the number of ranges to trim per I/O request. +The number of logical blocks per range is determined by the \fBbs\fR option +which should be a multiple of logical block size. This cannot be used with +read or write. Note that setting this option > 1, \fBlog_offset\fR will not be +able to log all the offsets. Default: 1. +.TP .BI (cpuio)cpuload \fR=\fPint Attempt to use the specified percentage of CPU cycles. This is a mandatory option when using cpuio I/O engine.
fio.h +18 -0
@@ -71,6 +71,16 @@struct fio_sem ; +#define MAX_TRIM_RANGE 256 + +/* +* Range for trim command +*/ +struct trim_range { +unsigned long long start; +unsigned long long len; +}; +/* * offset generator types */
@@ -609,6 +619,14 @@ static inline void fio_ro_check(const struct thread_data *td, struct io_u *io_u) !(io_u->ddir == DDIR_TRIM && !td_trim(td))); } +static inline bool multi_range_trim (struct thread_data *td,struct io_u *io_u) +{ +if (io_u->ddir ==DDIR_TRIM && td->o.num_range >1 ) +return true; + +return false; +} +static inline bool should_fsync (struct thread_data *td) {if (td->last_was_sync)
init.c +13 -0
@@ -618,6 +618,19 @@ static int fixup_options(struct thread_data *td) ret |=1 ; } +if (td_trimwrite (td) && o->num_range >1 ) { +log_err ("fio: trimwrite cannot be used with multiple" +" ranges.\n" ); + ret |=1 ; + } + +if (td_trim (td) && o->num_range >1 && + !td_ioengine_flagged (td,FIO_MULTI_RANGE_TRIM )) { +log_err ("fio: can't use multiple ranges with IO engine %s\n" , + td->io_ops->name); + ret |=1 ; + } +#ifndef CONFIG_PSHARED if (!o->use_thread) { log_info("fio: this platform does not support process shared"
io_u.c +81 -16
127 lines not on this page · raw message
io_u.h +4 -0
@@ -80,6 +80,10 @@ struct io_u {struct io_piece *ipo; +/* +* number of trim ranges for this IO. +*/ +unsigned int number_trim;unsigned long long resid;unsigned int error;
ioengines.h +2 -0
@@ -97,6 +97,8 @@ enum fio_ioengine_flags {FIO_RO_NEEDS_RW_OPEN =1 <<18 ,/* open files in rw mode even if we have a read job; only affects ioengines using generic_open_file */ +FIO_MULTI_RANGE_TRIM + = 1 << 19, /* ioengine supports trim with more than one range */ };/*
options.c +11 -0
@@ -2395,6 +2395,17 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { .category = FIO_OPT_C_IO, .group = FIO_OPT_G_INVALID, }, + { + .name = "num_range", + .lname = "Number of ranges", + .type = FIO_OPT_INT, + .off1 = offsetof(struct thread_options, num_range), + .maxval = MAX_TRIM_RANGE, + .help = "Number of ranges for trim command", + .def = "1", + .category = FIO_OPT_C_IO, + .group = FIO_OPT_G_INVALID, + }, { .name = "bs", .lname = "Block size",
server.h +1 -1
@@ -51,7 +51,7 @@ struct fio_net_cmd_reply { };enum { -FIO_SERVER_VER =102 , +FIO_SERVER_VER =103 ,FIO_SERVER_MAX_FRAGMENT_PDU =1024 ,FIO_SERVER_MAX_CMD_MB =2048 ,
thread_options.h +3 -0
@@ -353,6 +353,8 @@ struct thread_options {unsigned long long offset_increment;unsigned long long number_ios; +unsigned int num_range; +unsigned int sync_file_range;unsigned long long latency_target;
@@ -711,6 +713,7 @@ struct thread_options_pack {uint32_t fdp_plis[FIO_MAX_PLIS ];uint32_t fdp_nrpli; +uint32_t num_range;/* * verify_pattern followed by buffer_pattern from the unpacked struct */
Signature · 1 line
2.25.1
PATCH v2 2/3 engines/nvme: pass offset and len instead of io_u
In reply to Ankit KumarRemove io_u dependency while calculating start and number of lba. This is a prep patch for multi-range trim support where an io_u entry will contain multiple start offset and buffer len.
--- engines/nvme.c | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-)
engines/nvme.c +19 -19
@@ -8,20 +8,20 @@#include "../crc/crc-t10dif.h" #include "../crc/crc64.h" -static inline __u64 get_slba (struct nvme_data *data,struct io_u *io_u) +static inline __u64 get_slba (struct nvme_data *data,__u64 offset) {if (data->lba_ext) -return io_u->offset / data->lba_ext; -else -return io_u->offset >> data->lba_shift; +return offset / data->lba_ext; + +return offset >> data->lba_shift; } -static inline __u32 get_nlb (struct nvme_data *data,struct io_u *io_u) +static inline __u32 get_nlb (struct nvme_data *data,__u64 len) {if (data->lba_ext) -return io_u->xfer_buflen / data->lba_ext -1 ; -else -return (io_u->xfer_buflen >> data->lba_shift) -1 ; +return len / data->lba_ext -1 ; + +return (len >> data->lba_shift) -1 ; } static void fio_nvme_generate_pi_16b_guard(struct nvme_data *data,
@@ -32,8 +32,8 @@ static void fio_nvme_generate_pi_16b_guard(struct nvme_data *data,struct nvme_16b_guard_pif *pi;unsigned char *buf = io_u->xfer_buf;unsigned char *md_buf = io_u->mmap_data; -__u64 slba =get_slba (data, io_u); -__u32 nlb =get_nlb (data, io_u) +1 ; +__u64 slba =get_slba (data, io_u->offset); +__u32 nlb =get_nlb (data, io_u->xfer_buflen) +1 ;__u32 lba_num =0 ;__u16 guard =0 ;
@@ -99,8 +99,8 @@ static int fio_nvme_verify_pi_16b_guard(struct nvme_data *data,struct fio_file *f = io_u->file;unsigned char *buf = io_u->xfer_buf;unsigned char *md_buf = io_u->mmap_data; -__u64 slba =get_slba (data, io_u); -__u32 nlb =get_nlb (data, io_u) +1 ; +__u64 slba =get_slba (data, io_u->offset); +__u32 nlb =get_nlb (data, io_u->xfer_buflen) +1 ;__u32 lba_num =0 ;__u16 unmask_app, unmask_app_exp, guard =0 ;
@@ -185,8 +185,8 @@ static void fio_nvme_generate_pi_64b_guard(struct nvme_data *data,unsigned char *buf = io_u->xfer_buf;unsigned char *md_buf = io_u->mmap_data;uint64_t guard =0 ; -__u64 slba =get_slba (data, io_u); -__u32 nlb =get_nlb (data, io_u) +1 ; +__u64 slba =get_slba (data, io_u->offset); +__u32 nlb =get_nlb (data, io_u->xfer_buflen) +1 ;__u32 lba_num =0 ;if (data->pi_loc) {
@@ -251,9 +251,9 @@ static int fio_nvme_verify_pi_64b_guard(struct nvme_data *data,struct fio_file *f = io_u->file;unsigned char *buf = io_u->xfer_buf;unsigned char *md_buf = io_u->mmap_data; -__u64 slba =get_slba (data, io_u); +__u64 slba =get_slba (data, io_u->offset);__u64 ref, ref_exp, guard =0 ; -__u32 nlb =get_nlb (data, io_u) +1 ; +__u32 nlb =get_nlb (data, io_u->xfer_buflen) +1 ;__u32 lba_num =0 ;__u16 unmask_app, unmask_app_exp;
@@ -368,8 +368,8 @@ int fio_nvme_uring_cmd_prep(struct nvme_uring_cmd *cmd, struct io_u *io_u,return -ENOTSUP ; } - slba =get_slba (data, io_u); - nlb =get_nlb (data, io_u); + slba =get_slba (data, io_u->offset); + nlb =get_nlb (data, io_u->xfer_buflen);/* cdw10 and cdw11 represent starting lba */ cmd->cdw10 = slba &0xffffffff ;
@@ -400,7 +400,7 @@ void fio_nvme_pi_fill(struct nvme_uring_cmd *cmd, struct io_u *io_u,struct nvme_data *data =FILE_ENG_DATA (io_u->file);__u64 slba; - slba =get_slba (data, io_u); + slba =get_slba (data, io_u->offset); cmd->cdw12 |= opts->io_flags;if (data->pi_type && !(opts->io_flags &NVME_IO_PRINFO_PRACT )) {
Signature · 1 line
2.25.1
PATCH v2 3/3 engines/io_uring: add multi range dsm support
In reply to Ankit KumarUpdate the io_uring_cmd ioengine to support multiple ranges for trim. This includes allocating buffer for multiple ranges, and changes to the nvme trim helper functions.
Add an example on how to use multi range trim.
--- engines/io_uring.c | 34 ++++++++++++++++++++----- engines/nvme.c | 34 ++++++++++++++++++------- engines/nvme.h | 7 ++++- examples/uring-cmd-trim-multi-range.fio | 21 +++++++++++++++ 4 files changed, 79 insertions(+), 17 deletions(-) create mode 100644 examples/uring-cmd-trim-multi-range.fio
engines/io_uring.c +27 -7
@@ -81,7 +81,7 @@ struct ioring_data {struct cmdprio cmdprio; -struct nvme_dsm_range *dsm; +struct nvme_dsm *dsm; };struct ioring_options {
@@ -385,6 +385,9 @@ static int fio_ioring_cmd_prep(struct thread_data *td, struct io_u *io_u)struct fio_file *f = io_u->file;struct nvme_uring_cmd *cmd;struct io_uring_sqe *sqe; +struct nvme_dsm *dsm; +void *ptr = ld->dsm; +unsigned int dsm_size;/* only supports nvme_uring_cmd */ if (o->cmd_type !=FIO_URING_CMD_NVME )
@@ -423,9 +426,13 @@ static int fio_ioring_cmd_prep(struct thread_data *td, struct io_u *io_u) } cmd = (struct nvme_uring_cmd *)sqe->cmd; + dsm_size =sizeof (*ld->dsm) + td->o.num_range *sizeof (struct nvme_dsm_range ); + ptr += io_u->index * dsm_size; + dsm = (struct nvme_dsm *)ptr; +return fio_nvme_uring_cmd_prep (cmd, io_u, o->nonvectored ?NULL : &ld->iovecs[io_u->index], - &ld->dsm[io_u->index]); + dsm); }static struct io_u *fio_ioring_event (struct thread_data *td,int event)
@@ -1133,8 +1140,11 @@ static int fio_ioring_init(struct thread_data *td) {struct ioring_options *o = td->eo;struct ioring_data *ld; +struct nvme_dsm *dsm; +void *ptr; +unsigned int dsm_size;unsigned long long md_size; -int ret; +int ret, i;/* sqthread submission requires registered files */ if (o->sqpoll_thread)
@@ -1195,10 +1205,19 @@ static int fio_ioring_init(struct thread_data *td)* in zbd mode where trim means zone reset. */ if (!strcmp (td->io_ops->name,"io_uring_cmd" ) &&td_trim (td) && - td->o.zone_mode ==ZONE_MODE_ZBD ) + td->o.zone_mode ==ZONE_MODE_ZBD ) { td->io_ops->flags |=FIO_ASYNCIO_SYNC_TRIM ; -else - ld->dsm =calloc (td->o.iodepth,sizeof (*ld->dsm)); + }else { + dsm_size =sizeof (*ld->dsm) + + td->o.num_range *sizeof (struct nvme_dsm_range ); + ld->dsm =calloc (td->o.iodepth, dsm_size); + ptr = ld->dsm; +for (i =0 ; i < td->o.iodepth; i++) { + dsm = (struct nvme_dsm *)ptr; + dsm->nr_ranges = td->o.num_range; + ptr += dsm_size; + } + }return 0 ; }
@@ -1466,7 +1485,8 @@ static struct ioengine_ops ioengine_uring_cmd = { .name = "io_uring_cmd", .version = FIO_IOOPS_VERSION, .flags =FIO_NO_OFFLOAD |FIO_MEMALIGN |FIO_RAWIO | - FIO_ASYNCIO_SETS_ISSUE_TIME, +FIO_ASYNCIO_SETS_ISSUE_TIME | + FIO_MULTI_RANGE_TRIM, .init = fio_ioring_init, .post_init = fio_ioring_cmd_post_init, .io_u_init = fio_ioring_io_u_init,
engines/nvme.c +25 -9
@@ -329,24 +329,40 @@ next:return 0 ; }void fio_nvme_uring_cmd_trim_prep (struct nvme_uring_cmd *cmd,struct io_u *io_u, -struct nvme_dsm_range *dsm) +struct nvme_dsm *dsm) {struct nvme_data *data =FILE_ENG_DATA (io_u->file); +struct trim_range *range; +uint8_t *buf_point; +int i; cmd->opcode = nvme_cmd_dsm; cmd->nsid = data->nsid; - cmd->cdw10 =0 ; cmd->cdw11 =NVME_ATTRIBUTE_DEALLOCATE ; - cmd->addr = (__u64 ) (uintptr_t ) dsm; - cmd->data_len =sizeof (*dsm); - - dsm->slba =get_slba (data, io_u); -/* nlb is a 1-based value for deallocate */ - dsm->nlb =get_nlb (data, io_u) +1 ; + cmd->addr = (__u64) (uintptr_t) (&dsm->range[0 ]); + +if (dsm->nr_ranges ==1 ) { + dsm->range[0 ].slba =get_slba (data, io_u->offset); +/* nlb is a 1-based value for deallocate */ + dsm->range[0 ].nlb =get_nlb (data, io_u->xfer_buflen) +1 ; + cmd->cdw10 =0 ; + cmd->data_len =sizeof (struct nvme_dsm_range ); + }else { + buf_point = io_u->xfer_buf; +for (i =0 ; i < io_u->number_trim; i++) { + range = (struct trim_range *)buf_point; + dsm->range[i].slba =get_slba (data, range->start); +/* nlb is a 1-based value for deallocate */ + dsm->range[i].nlb =get_nlb (data, range->len) +1 ; + buf_point +=sizeof (struct trim_range ); + } + cmd->cdw10 = io_u->number_trim -1 ; + cmd->data_len = io_u->number_trim *sizeof (struct nvme_dsm_range ); + } }int fio_nvme_uring_cmd_prep (struct nvme_uring_cmd *cmd,struct io_u *io_u, -struct iovec *iov,struct nvme_dsm_range *dsm) +struct iovec *iov,struct nvme_dsm *dsm) {struct nvme_data *data =FILE_ENG_DATA (io_u->file);__u64 slba;
engines/nvme.h +6 -1
@@ -408,6 +408,11 @@ struct nvme_dsm_range {__le64 slba; }; +struct nvme_dsm { +__u32 nr_ranges; +struct nvme_dsm_range range[]; +}; +struct nvme_cmd_ext_io_opts {__u32 io_flags;__u16 apptag;
@@ -421,7 +426,7 @@ int fio_nvme_get_info(struct fio_file *f, __u64 *nlba, __u32 pi_act, struct nvme_data *data);int fio_nvme_uring_cmd_prep (struct nvme_uring_cmd *cmd,struct io_u *io_u, -struct iovec *iov,struct nvme_dsm_range *dsm); +struct iovec *iov,struct nvme_dsm *dsm);void fio_nvme_pi_fill (struct nvme_uring_cmd *cmd,struct io_u *io_u,struct nvme_cmd_ext_io_opts *opts);
examples/uring-cmd-trim-multi-range.fio new file +21 -0
@@ -0,0 +1,21 @@ +# Multi-range trim command test with io_uring_cmd I/O engine for nvme-ns +# generic character device. +# +[global] +filename=/dev/ng0n1 +ioengine=io_uring_cmd +cmd_type=nvme +size=10M +iodepth=32 +thread=1 +stonewall=1 + +[write_bs] +bs=4096 +rw=randtrim +num_range=8 + +[write_bssplit] +bssplit=4k/10:64k/50:32k/40 +rw=trim +num_range=8
Signature · 1 line
2.25.1
Jens Axboe
AppliedQuoted 9 lines · Ankit Kumar
NVMe specification allow multiple ranges for the dataset management command. The block ioctl only accepts a single entry for trim, but with nvme character device we can send multiple ranges.
The first patch in this series adds an option
num_rangeto send multiple range per trim request. This will only work if the data direction is solely trim i.e. trim or randtrim.[...]
Applied, thanks!
[1/3] trim: add support for multiple ranges
commit: b3251e31bae2c2ec7c8db0e7e7511eb03b8b0190
[2/3] engines/nvme: pass offset and len instead of io_u
commit: 0d610785a8072eba146dd05f2928a1a89da49bd5
[3/3] engines/io_uring: add multi range dsm support
commit: 5d4ee0de9d6afaa74c7c15c3d4f210a06d4e2139Best regards,
Signature · 1 line
Jens Axboe