scsi: target: direct completion support
Subsystems (13)
Mike Christie
maintainerPATCH 1/4 scsi: target: direct completion support
The following patches made over Linus's current tree allow users to tell the target layer to perform direct completions instead of always deferring to LIO's completion workqueue. When the frontend driver already has multiple worker threads (or you are doing a LUN per target with a single thread per target) then bypassing the LIO workqueue can increase performance 20-30%.
Mike Christie
maintainerPATCH 1/4 scsi: target: Add support for completing commands from backend context
To complete a command several drivers just drop their reference and add it to list to be processed by a driver specific thread. So there's no need to go from backend context to the LIO thread then to the driver's thread. When avoiding the LIO thread, IOPS can increase from 20-30% for workloads like:
fio --filename=/dev/sdb --direct=1 --rw=randrw --bs=8K \
--ioengine=libaio --iodepth=128 --numjobs=$jobs
where increasing jobs increases the performance improvement (this is using NVMe drives with LIO's submit_type=1 to directly submit).
This patch adds the infrastructure so drivers and userspace can control how to complete a command like is done for the submission path. In this patch there is no behavior change and we continue to defer to the LIO workqueue thread. In the next patches we will allow drivers to report what they support and allow userspace to control the behavior.
--- drivers/target/target_core_device.c | 1 + drivers/target/target_core_transport.c | 60 +++++++++++++++++++++----- include/target/target_core_base.h | 12 +++++- include/target/target_core_fabric.h | 12 ++++-- 4 files changed, 70 insertions(+), 15 deletions(-)
drivers/target/target_core_device.c +1 -0
@@ -813,6 +813,7 @@ struct se_device *target_alloc_device(struct se_hba *hba, const char *name)DA_UNMAP_ZEROES_DATA_DEFAULT ; dev->dev_attrib.max_write_same_len =DA_MAX_WRITE_SAME_LEN ; dev->dev_attrib.submit_type =TARGET_FABRIC_DEFAULT_SUBMIT ; + dev->dev_attrib.submit_type =TARGET_QUEUE_COMPL ;/* Skip allocating lun_stats since we can't export them. */ xcopy_lun = &dev->xcopy_lun;
drivers/target/target_core_transport.c +49 -11
77 lines not on this page · raw message
include/target/target_core_base.h +10 -0
@@ -108,6 +108,15 @@#define SE_MODE_PAGE_BUF 512#define SE_SENSE_BUF 96 +enum target_compl_type { +/* Use the fabric driver's default completion type */ +TARGET_FABRIC_DEFAULT_COMPL , +/* Complete from the backend calling context */ +TARGET_DIRECT_COMPL , +/* Defer completion to the LIO workqueue */ +TARGET_QUEUE_COMPL , +}; +enum target_submit_type {/* Use the fabric driver's default submission type */ TARGET_FABRIC_DEFAULT_SUBMIT ,
@@ -737,6 +746,7 @@ struct se_dev_attrib {u32 atomic_granularity;u32 atomic_max_with_boundary;u32 atomic_max_boundary; +u8 complete_type;u8 submit_type;struct se_device *da_dev;struct config_group da_group;
include/target/target_core_fabric.h +9 -3
@@ -118,15 +118,21 @@ struct target_core_fabric_ops {* its entirety before a command is aborted. */ unsigned int write_pending_must_be_called:1; +/* +* Set this if the driver does not require calling queue_data_in +* queue_status and check_stop_free from a worker thread when +* completing successful commands. +*/ + unsigned int direct_compl_supp:1;/* * Set this if the driver supports submitting commands to the backend * from target_submit/target_submit_cmd. */ unsigned int direct_submit_supp:1; -/* -* Set this to a target_submit_type value. -*/ +/* Set this to a target_submit_type value. */ u8 default_submit_type; +/* Set this to the target_compl_type value. */ +u8 default_compl_type; };int target_register_template (const struct target_core_fabric_ops *fo);
Signature · 1 line
2.43.0
Martin K. Petersen
AppliedRe: [PATCH 1/4] scsi: target: Add support for completing commands from backend context
Quoted 10 lines · Mike Christie
To complete a command several drivers just drop their reference and add it to list to be processed by a driver specific thread. So there's no need to go from backend context to the LIO thread then to the driver's thread. When avoiding the LIO thread, IOPS can increase from 20-30% for workloads like:
fio --filename=/dev/sdb --direct=1 --rw=randrw --bs=8K \
--ioengine=libaio --iodepth=128 --numjobs=$jobs[...]
Applied to 7.1/scsi-queue, thanks!
[1/4] scsi: target: Add support for completing commands from backend context
https://git.kernel.org/mkp/scsi/c/06933066d88a [2/4] scsi: target: Use driver completion preference by default https://git.kernel.org/mkp/scsi/c/89663fb2e538 [3/4] scsi: target: Allow userspace to set the completion type https://git.kernel.org/mkp/scsi/c/e1502d990c8e [4/4] vhost-scsi: Report direction completion support https://git.kernel.org/mkp/scsi/c/a4d72d2dd0cb
Signature · 1 line
Martin K. Petersen
Mike Christie
maintainerPATCH 2/4 scsi: target: Use driver completion preference by default
In reply to Mike ChristieThis has us use the driver's completion preference by default. There is no behavior changes with this patch and we queue completion to LIO's completion workqueue by default.
--- drivers/infiniband/ulp/srpt/ib_srpt.c | 1 + drivers/scsi/elx/efct/efct_lio.c | 2 ++ drivers/scsi/ibmvscsi_tgt/ibmvscsi_tgt.c | 1 + drivers/scsi/qla2xxx/tcm_qla2xxx.c | 2 ++ drivers/target/iscsi/iscsi_target_configfs.c | 1 + drivers/target/loopback/tcm_loop.c | 1 + drivers/target/sbp/sbp_target.c | 1 + drivers/target/target_core_device.c | 2 +- drivers/target/tcm_fc/tfc_conf.c | 1 + drivers/usb/gadget/function/f_tcm.c | 1 + drivers/vhost/scsi.c | 1 + drivers/xen/xen-scsiback.c | 1 + 12 files changed, 14 insertions(+), 1 deletion(-)
drivers/infiniband/ulp/srpt/ib_srpt.c +1 -0
@@ -3926,6 +3926,7 @@ static const struct target_core_fabric_ops srpt_template = { .tfc_wwn_attrs = srpt_wwn_attrs, .tfc_tpg_attrib_attrs = srpt_tpg_attrib_attrs, + .default_compl_type = TARGET_QUEUE_COMPL, .default_submit_type = TARGET_DIRECT_SUBMIT, .direct_submit_supp = 1, };
drivers/scsi/elx/efct/efct_lio.c +2 -0
@@ -1612,6 +1612,7 @@ static const struct target_core_fabric_ops efct_lio_ops = { .sess_get_initiator_sid = NULL, .tfc_tpg_base_attrs = efct_lio_tpg_attrs, .tfc_tpg_attrib_attrs = efct_lio_tpg_attrib_attrs, + .default_compl_type = TARGET_QUEUE_COMPL, .default_submit_type = TARGET_DIRECT_SUBMIT, .direct_submit_supp = 1, };
@@ -1650,6 +1651,7 @@ static const struct target_core_fabric_ops efct_lio_npiv_ops = { .tfc_tpg_base_attrs = efct_lio_npiv_tpg_attrs, .tfc_tpg_attrib_attrs = efct_lio_npiv_tpg_attrib_attrs, + .default_compl_type = TARGET_QUEUE_COMPL, .default_submit_type = TARGET_DIRECT_SUBMIT, .direct_submit_supp = 1, };
drivers/scsi/ibmvscsi_tgt/ibmvscsi_tgt.c +1 -0
@@ -3968,6 +3968,7 @@ static const struct target_core_fabric_ops ibmvscsis_ops = { .tfc_wwn_attrs = ibmvscsis_wwn_attrs, + .default_compl_type = TARGET_QUEUE_COMPL, .default_submit_type = TARGET_DIRECT_SUBMIT, .direct_submit_supp = 1, };
drivers/scsi/qla2xxx/tcm_qla2xxx.c +2 -0
@@ -1840,6 +1840,7 @@ static const struct target_core_fabric_ops tcm_qla2xxx_ops = { .tfc_tpg_base_attrs = tcm_qla2xxx_tpg_attrs, .tfc_tpg_attrib_attrs = tcm_qla2xxx_tpg_attrib_attrs, + .default_compl_type = TARGET_QUEUE_COMPL, .default_submit_type = TARGET_DIRECT_SUBMIT, .direct_submit_supp = 1, };
@@ -1880,6 +1881,7 @@ static const struct target_core_fabric_ops tcm_qla2xxx_npiv_ops = { .tfc_wwn_attrs = tcm_qla2xxx_wwn_attrs, + .default_compl_type = TARGET_QUEUE_COMPL, .default_submit_type = TARGET_DIRECT_SUBMIT, .direct_submit_supp = 1, };
drivers/target/iscsi/iscsi_target_configfs.c +1 -0
@@ -1591,6 +1591,7 @@ const struct target_core_fabric_ops iscsi_ops = { .write_pending_must_be_called = 1, + .default_compl_type = TARGET_QUEUE_COMPL, .default_submit_type = TARGET_DIRECT_SUBMIT, .direct_submit_supp = 1, };
drivers/target/loopback/tcm_loop.c +1 -0
@@ -1106,6 +1106,7 @@ static const struct target_core_fabric_ops loop_ops = { .tfc_wwn_attrs = tcm_loop_wwn_attrs, .tfc_tpg_base_attrs = tcm_loop_tpg_attrs, .tfc_tpg_attrib_attrs = tcm_loop_tpg_attrib_attrs, + .default_compl_type = TARGET_QUEUE_COMPL, .default_submit_type = TARGET_QUEUE_SUBMIT, .direct_submit_supp = 0, };
drivers/target/sbp/sbp_target.c +1 -0
@@ -2278,6 +2278,7 @@ static const struct target_core_fabric_ops sbp_ops = { .tfc_tpg_base_attrs = sbp_tpg_base_attrs, .tfc_tpg_attrib_attrs = sbp_tpg_attrib_attrs, + .default_compl_type = TARGET_QUEUE_COMPL, .default_submit_type = TARGET_DIRECT_SUBMIT, .direct_submit_supp = 1, };
drivers/target/target_core_device.c +1 -1
@@ -813,7 +813,7 @@ struct se_device *target_alloc_device(struct se_hba *hba, const char *name)DA_UNMAP_ZEROES_DATA_DEFAULT ; dev->dev_attrib.max_write_same_len =DA_MAX_WRITE_SAME_LEN ; dev->dev_attrib.submit_type =TARGET_FABRIC_DEFAULT_SUBMIT ; - dev->dev_attrib.submit_type =TARGET_QUEUE_COMPL ; + dev->dev_attrib.submit_type =TARGET_FABRIC_DEFAULT_COMPL ;/* Skip allocating lun_stats since we can't export them. */ xcopy_lun = &dev->xcopy_lun;
drivers/target/tcm_fc/tfc_conf.c +1 -0
@@ -433,6 +433,7 @@ static const struct target_core_fabric_ops ft_fabric_ops = { .tfc_wwn_attrs = ft_wwn_attrs, .tfc_tpg_nacl_base_attrs = ft_nacl_base_attrs, + .default_compl_type = TARGET_QUEUE_COMPL, .default_submit_type = TARGET_DIRECT_SUBMIT, .direct_submit_supp = 1, };
drivers/usb/gadget/function/f_tcm.c +1 -0
@@ -2015,6 +2015,7 @@ static const struct target_core_fabric_ops usbg_ops = { .tfc_wwn_attrs = usbg_wwn_attrs, .tfc_tpg_base_attrs = usbg_base_attrs, + .default_compl_type = TARGET_QUEUE_COMPL, .default_submit_type = TARGET_DIRECT_SUBMIT, .direct_submit_supp = 1, };
drivers/vhost/scsi.c +1 -0
@@ -2958,6 +2958,7 @@ static const struct target_core_fabric_ops vhost_scsi_ops = { .tfc_tpg_base_attrs = vhost_scsi_tpg_attrs, .tfc_tpg_attrib_attrs = vhost_scsi_tpg_attrib_attrs, + .default_compl_type = TARGET_QUEUE_COMPL, .default_submit_type = TARGET_QUEUE_SUBMIT, .direct_submit_supp = 1, };
drivers/xen/xen-scsiback.c +1 -0
@@ -1833,6 +1833,7 @@ static const struct target_core_fabric_ops scsiback_ops = { .tfc_tpg_base_attrs = scsiback_tpg_attrs, .tfc_tpg_param_attrs = scsiback_param_attrs, + .default_compl_type = TARGET_QUEUE_COMPL, .default_submit_type = TARGET_DIRECT_SUBMIT, .direct_submit_supp = 1, };
Signature · 1 line
2.43.0
Mike Christie
maintainerPATCH 3/4 scsi: target: Allow userspace to set the completion type
In reply to Mike ChristieThis allows userspace to request if we complete in the backend context or the frontend driver. It works the same as submission where you can write 0 to 2 to complete_type:
0 - Use the fabric driver's preference.
1 - Complete from the backend calling context if the fabric supports it.
2 - Queue the completion to LIO's completion workqueue.
--- drivers/target/target_core_configfs.c | 22 ++++++++++++++++++ drivers/target/target_core_fabric_configfs.c | 24 ++++++++++++++++++++ 2 files changed, 46 insertions(+)
drivers/target/target_core_configfs.c +22 -0
@@ -578,6 +578,7 @@ DEF_CONFIGFS_ATTRIB_SHOW(unmap_zeroes_data);DEF_CONFIGFS_ATTRIB_SHOW (max_write_same_len);DEF_CONFIGFS_ATTRIB_SHOW (emulate_rsoc);DEF_CONFIGFS_ATTRIB_SHOW (submit_type); +DEF_CONFIGFS_ATTRIB_SHOW (complete_type);DEF_CONFIGFS_ATTRIB_SHOW (atomic_max_len);DEF_CONFIGFS_ATTRIB_SHOW (atomic_alignment);DEF_CONFIGFS_ATTRIB_SHOW (atomic_granularity);
@@ -1269,6 +1270,24 @@ static ssize_t submit_type_store(struct config_item *item, const char *page,return count; } +static ssize_t complete_type_store (struct config_item *item,const char *page, +size_t count) +{ +struct se_dev_attrib *da =to_attrib (item); +int ret; +u8 val; + + ret =kstrtou8 (page,0 , &val); +if (ret <0 ) +return ret; + +if (val >TARGET_QUEUE_COMPL ) +return -EINVAL ; + + da->complete_type = val; +return count; +} + CONFIGFS_ATTR(, emulate_model_alias); CONFIGFS_ATTR(, emulate_dpo); CONFIGFS_ATTR(, emulate_fua_write);
@@ -1305,6 +1324,7 @@ CONFIGFS_ATTR(, max_write_same_len); CONFIGFS_ATTR(, alua_support); CONFIGFS_ATTR(, pgr_support); CONFIGFS_ATTR(, submit_type); +CONFIGFS_ATTR(, complete_type); CONFIGFS_ATTR_RO(, atomic_max_len); CONFIGFS_ATTR_RO(, atomic_alignment); CONFIGFS_ATTR_RO(, atomic_granularity);
@@ -1353,6 +1373,7 @@ struct configfs_attribute *sbc_attrib_attrs[] = { &attr_pgr_support, &attr_emulate_rsoc, &attr_submit_type, + &attr_complete_type, &attr_atomic_alignment, &attr_atomic_max_len, &attr_atomic_granularity,
@@ -1376,6 +1397,7 @@ struct configfs_attribute *passthrough_attrib_attrs[] = { &attr_alua_support, &attr_pgr_support, &attr_submit_type, + &attr_complete_type,NULL , };EXPORT_SYMBOL (passthrough_attrib_attrs);
drivers/target/target_core_fabric_configfs.c +24 -0
@@ -1065,6 +1065,28 @@ target_fabric_wwn_cmd_completion_affinity_store(struct config_item *item, }CONFIGFS_ATTR (target_fabric_wwn_, cmd_completion_affinity); +static ssize_t +target_fabric_wwn_default_complete_type_show (struct config_item *item, +char *page) +{ + struct se_wwn *wwn = container_of(to_config_group(item), struct se_wwn, + param_group); +return sysfs_emit (page,"%u\n" , + wwn->wwn_tf->tf_ops->default_compl_type); +} +CONFIGFS_ATTR_RO (target_fabric_wwn_, default_complete_type); + +static ssize_t +target_fabric_wwn_direct_complete_supported_show (struct config_item *item, +char *page) +{ + struct se_wwn *wwn = container_of(to_config_group(item), struct se_wwn, + param_group); +return sysfs_emit (page,"%u\n" , + wwn->wwn_tf->tf_ops->direct_compl_supp); +} +CONFIGFS_ATTR_RO (target_fabric_wwn_, direct_complete_supported); +static ssize_t target_fabric_wwn_default_submit_type_show (struct config_item *item,char *page)
@@ -1089,6 +1111,8 @@ CONFIGFS_ATTR_RO(target_fabric_wwn_, direct_submit_supported);static struct configfs_attribute *target_fabric_wwn_param_attrs[] = { &target_fabric_wwn_attr_cmd_completion_affinity, + &target_fabric_wwn_attr_default_complete_type, + &target_fabric_wwn_attr_direct_complete_supported, &target_fabric_wwn_attr_default_submit_type, &target_fabric_wwn_attr_direct_submit_supported,NULL ,
Signature · 1 line
2.43.0
Mike Christie
maintainerPATCH 4/4 vhost-scsi: Report direction completion support
In reply to Mike ChristieThis has vhost-scsi report that it supports direct completions.
When using a worker task per queue or group of queues with fast backends then enabling direct completion and submissions increases performance 20-30% with workloads like:
fio --filename=/dev/sdb --direct=1 --rw=randrw --bs=8K \
--ioengine=libaio --iodepth=128 --numjobs=$jobsAs jobs matches and passes the number of vCPUs in the VM then the benefit increases.
However, when using a single worker then queueing completions and submissions is best as the worker is busy handling mapping data and setting/tearing down commands.
--- drivers/vhost/scsi.c | 1 + 1 file changed, 1 insertion(+)
drivers/vhost/scsi.c +1 -0
@@ -2959,6 +2959,7 @@ static const struct target_core_fabric_ops vhost_scsi_ops = { .tfc_tpg_attrib_attrs = vhost_scsi_tpg_attrib_attrs, .default_compl_type = TARGET_QUEUE_COMPL, + .direct_compl_supp = 1, .default_submit_type = TARGET_QUEUE_SUBMIT, .direct_submit_supp = 1, };
Signature · 1 line
2.43.0
Martin K. Petersen
AppliedMike,
Quoted 6 lines
The following patches made over Linus's current tree allow users to tell the target layer to perform direct completions instead of always deferring to LIO's completion workqueue. When the frontend driver already has multiple worker threads (or you are doing a LUN per target with a single thread per target) then bypassing the LIO workqueue can increase performance 20-30%.
Applied to 7.1/scsi-staging, thanks!
Signature · 1 line
Martin K. Petersen