Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

scsi: target: iblock: Add backend plug/unplug callouts

This patch adds plug/unplug callouts for iblock. For an initiator driver
like iSCSI which wants to pass multiple cmds to its xmit thread instead of
one cmd at a time, this increases IOPS by around 10% with vhost-scsi
(combined with the last patches we can see a total 40-50% increase). For
driver combos like tcm_loop and faster drivers like the iSER initiator, we
can still see IOPS increase by 20-30% when tcm_loop's nr_hw_queues setting
is also increased.

Link: https://lore.kernel.org/r/20210227170006.5077-23-michael.christie@oracle.com
Signed-off-by: Mike Christie <michael.christie@oracle.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>

authored by

Mike Christie and committed by
Martin K. Petersen
415ccd98 302990ac

+53 -1
+43 -1
drivers/target/target_core_iblock.c
··· 61 61 return NULL; 62 62 } 63 63 64 + ib_dev->ibd_plug = kcalloc(nr_cpu_ids, sizeof(*ib_dev->ibd_plug), 65 + GFP_KERNEL); 66 + if (!ib_dev->ibd_plug) 67 + goto free_dev; 68 + 64 69 pr_debug( "IBLOCK: Allocated ib_dev for %s\n", name); 65 70 66 71 return &ib_dev->dev; 72 + 73 + free_dev: 74 + kfree(ib_dev); 75 + return NULL; 67 76 } 68 77 69 78 static int iblock_configure_device(struct se_device *dev) ··· 180 171 struct se_device *dev = container_of(p, struct se_device, rcu_head); 181 172 struct iblock_dev *ib_dev = IBLOCK_DEV(dev); 182 173 174 + kfree(ib_dev->ibd_plug); 183 175 kfree(ib_dev); 184 176 } 185 177 ··· 196 186 if (ib_dev->ibd_bd != NULL) 197 187 blkdev_put(ib_dev->ibd_bd, FMODE_WRITE|FMODE_READ|FMODE_EXCL); 198 188 bioset_exit(&ib_dev->ibd_bio_set); 189 + } 190 + 191 + static struct se_dev_plug *iblock_plug_device(struct se_device *se_dev) 192 + { 193 + struct iblock_dev *ib_dev = IBLOCK_DEV(se_dev); 194 + struct iblock_dev_plug *ib_dev_plug; 195 + 196 + /* 197 + * Each se_device has a per cpu work this can be run from. Wwe 198 + * shouldn't have multiple threads on the same cpu calling this 199 + * at the same time. 200 + */ 201 + ib_dev_plug = &ib_dev->ibd_plug[smp_processor_id()]; 202 + if (test_and_set_bit(IBD_PLUGF_PLUGGED, &ib_dev_plug->flags)) 203 + return NULL; 204 + 205 + blk_start_plug(&ib_dev_plug->blk_plug); 206 + return &ib_dev_plug->se_plug; 207 + } 208 + 209 + static void iblock_unplug_device(struct se_dev_plug *se_plug) 210 + { 211 + struct iblock_dev_plug *ib_dev_plug = container_of(se_plug, 212 + struct iblock_dev_plug, se_plug); 213 + 214 + blk_finish_plug(&ib_dev_plug->blk_plug); 215 + clear_bit(IBD_PLUGF_PLUGGED, &ib_dev_plug->flags); 199 216 } 200 217 201 218 static unsigned long long iblock_emulate_read_cap_with_block_size( ··· 372 335 { 373 336 struct blk_plug plug; 374 337 struct bio *bio; 375 - 338 + /* 339 + * The block layer handles nested plugs, so just plug/unplug to handle 340 + * fabric drivers that didn't support batching and multi bio cmds. 341 + */ 376 342 blk_start_plug(&plug); 377 343 while ((bio = bio_list_pop(list))) 378 344 submit_bio(bio); ··· 907 867 .configure_device = iblock_configure_device, 908 868 .destroy_device = iblock_destroy_device, 909 869 .free_device = iblock_free_device, 870 + .plug_device = iblock_plug_device, 871 + .unplug_device = iblock_unplug_device, 910 872 .parse_cdb = iblock_parse_cdb, 911 873 .set_configfs_dev_params = iblock_set_configfs_dev_params, 912 874 .show_configfs_dev_params = iblock_show_configfs_dev_params,
+10
drivers/target/target_core_iblock.h
··· 4 4 5 5 #include <linux/atomic.h> 6 6 #include <linux/refcount.h> 7 + #include <linux/blkdev.h> 7 8 #include <target/target_core_base.h> 8 9 9 10 #define IBLOCK_VERSION "4.0" ··· 18 17 19 18 #define IBDF_HAS_UDEV_PATH 0x01 20 19 20 + #define IBD_PLUGF_PLUGGED 0x01 21 + 22 + struct iblock_dev_plug { 23 + struct se_dev_plug se_plug; 24 + struct blk_plug blk_plug; 25 + unsigned long flags; 26 + }; 27 + 21 28 struct iblock_dev { 22 29 struct se_device dev; 23 30 unsigned char ibd_udev_path[SE_UDEV_PATH_LEN]; ··· 33 24 struct bio_set ibd_bio_set; 34 25 struct block_device *ibd_bd; 35 26 bool ibd_readonly; 27 + struct iblock_dev_plug *ibd_plug; 36 28 } ____cacheline_aligned; 37 29 38 30 #endif /* TARGET_CORE_IBLOCK_H */