The scsi_debug driver is essentially a ramdisk dressed up as a SCSI host with one or more SCSI devices attached. Like all low level SCSI drivers, the scsi_debug driver receives and provides data to the SCSI mid-level (and the block layer) using scatterlists whose interface is found in include/linux/scatterlist.h . After trying kmalloc() then vmalloc() based storage for the scsi_debug driver, it was found that certain SCSI commands can be optimized if instead one or more scatterlists is used as its backing store. The specific SCSI command that benefits the most is VERIFY(BYTCHK=1) whose NVMe equivalent is COMPARE. These commands have data-out buffers provided by an application that are compared by the storage device with the LBA and count (of blocks) given in the command. In this case the sgl_equal_sgl() function can be used instead of setting up a temporary buffer. The implementation of the more common SCSI READ and WRITE commands are simplified by using the sgl_copy_sgl() function. The first patch in this series removes an undocumented 4 GB limit in the existing sgl_alloc_order() function. In the final patch of this series, the scsi_debug driver uses the new facilities in scatterlist to replace its vmalloc() backing store with a sgl_alloc_order() based store. Also several loops based on memcpy() and memcmp() are replaced by the new scatterlist copy and 'equal' functions. Changes since v1 (sent to linux-scsi list on 20221023) - in sgl_alloc_order() add check that order argument is less then MAX_ORDER; protects following call to round_up() - in sdeb_sgl_cmp_buf() within scsi_debug.c remove call to sg_miter_stop() as suggested by reviewer Douglas Gilbert (5): sgl_alloc_order: remove 4 GiB limit scatterlist: add sgl_copy_sgl() function scatterlist: add sgl_equal_sgl() function scatterlist: add sgl_memset() scsi_debug: change store from vmalloc to sgl drivers/scsi/Kconfig | 3 +- drivers/scsi/scsi_debug.c | 442 ++++++++++++++++++++++++------------ include/linux/scatterlist.h | 33 ++- lib/scatterlist.c | 255 ++++++++++++++++++--- 4 files changed, 562 insertions(+), 171 deletions(-) -- 2.37.2