scsi_debug: change store from vmalloc to sgl
PATCH 1/1 scsi_debug: change store from vmalloc to sgl
A long time ago this driver's store was allocated by kmalloc() or alloc_pages(). When this was switched to vmalloc() the author noticed slower ramdisk access times and more variability in repeated tests. So try going back with sgl_alloc_order() to get uniformly sized allocations in a sometimes large scatter gather _array_. That array is the basis of keeping O(1) access to the store.
Using sgl_alloc_order() and friends requires CONFIG_SGL_ALLOC so add a 'select' to the Kconfig file.
Remove kcalloc() in resp_verify() as sgl_s can now be compared directly without forming an intermediate buffer. This is a performance win for the SCSI VERIFY command implementation.
Make the SCSI COMPARE AND WRITE command yield the offset of the first miscompared byte when the compare fails (as required by T10).
This patch depends on: "[PATCH v4 0/4] scatterlist: add new capabilities".
--- drivers/scsi/Kconfig | 3 +- drivers/scsi/scsi_debug.c | 438 +++++++++++++++++++++++++------------- 2 files changed, 297 insertions(+), 144 deletions(-)
drivers/scsi/Kconfig +2 -1
@@ -1233,13 +1233,14 @@ config SCSI_DEBUG tristate "SCSI debugging host and device simulator" depends on SCSI select CRC_T10DIF + select SGL_ALLOC help This pseudo driver simulates one or more hosts (SCSI initiators), each with one or more targets, each with one or more logical units. Defaults to one of each, creating a small RAM disk device. Many parameters found in the /sys/bus/pseudo/drivers/scsi_debug directory can be tweaked at run time. - See <http://sg.danny.cz/sg/sdebug26.html> for more information. + See <http://sg.danny.cz/sg/scsi_debug.html> for more information. Mainly used for testing and best as a module. If unsure, say N. config SCSI_MESH
drivers/scsi/scsi_debug.c +295 -143
706 lines not on this page · raw message
Signature · 1 line
2.25.1
Quoted 14 lines · Douglas Gilbert
A long time ago this driver's store was allocated by
kmalloc()oralloc_pages(). When this was switched tovmalloc()the author noticed slower ramdisk access times and more variability in repeated tests. So try going back withsgl_alloc_order()to get uniformly sized allocations in a sometimes large scatter gather _array_. That array is the basis of keeping O(1) access to the store.Using
sgl_alloc_order()and friends requiresCONFIG_SGL_ALLOCso add a 'select' to theKconfigfile.Remove
kcalloc()inresp_verify()assgl_scan now be compared directly without forming an intermediate buffer. This is a performance win for the SCSI VERIFY command implementation.
Quoted 6 lines
Make the SCSI COMPARE AND WRITE command yield the offset of the first miscompared byte when the compare fails (as required by T10).
This patch depends on: "[PATCH v4 0/4] scatterlist: add new capabilities".
Hi Doug,
Although I'm fine with this patch: has it been considered to use huge pages instead of allocating a scatterlist? Would that have the same or even better performance advantages?
Thanks,
Bart.
Quoted 19 lines · Bart Van Assche
Quoted 18 lines · Douglas Gilbert
A long time ago this driver's store was allocated by
kmalloc()oralloc_pages(). When this was switched tovmalloc()the author noticed slower ramdisk access times and more variability in repeated tests. So try going back withsgl_alloc_order()to get uniformly sized allocations in a sometimes large scatter gather _array_. That array is the basis of keeping O(1) access to the store.Using
sgl_alloc_order()and friends requiresCONFIG_SGL_ALLOCso add a 'select' to theKconfigfile.Remove
kcalloc()inresp_verify()assgl_scan now be compared directly without forming an intermediate buffer. This is a performance win for the SCSI VERIFY command implementation.Make the SCSI COMPARE AND WRITE command yield the offset of the first miscompared byte when the compare fails (as required by T10).
Quoted 8 lines
Quoted 2 lines
This patch depends on: "[PATCH v4 0/4] scatterlist: add new capabilities".
Hi Doug,
Although I'm fine with this patch: has it been considered to use huge pages instead of allocating a scatterlist? Would that have the same or even better performance advantages?
The scsi_debug driver having its store as a scatterlist has the distinct advantage that the data-in and data-out buffers coming through from the block layer and the scsi mid-level are also in the form of scatterlists. Hence most of the media access SCSI commands that the driver simulates boil down to just a handful of sgl to sgl operations. The very ones that I am trying to add to the scatterlist API.
If there is some advantage of using huge pages for a store, then I would prefer that to be done in the scatterlist API. Say a new allocator like sgl_alloc_huge() that forms a scatter gather array of huge pages.
I did have a quick look at huge pages and the existing kernel infrastructure seemed to be aimed at user space usage rather than driver usage.
Doug Gilbert
kernel test robot
build botThank you for the patch! Yet something to improve:
Hi Douglas,
Thank you for the patch! Yet something to improve:
[auto build test ERROR on scsi/for-next]
[also build test ERROR on mkp-scsi/for-next v5.10-rc3 next-20201106] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Douglas-Gilbert/scsi_debug-change-store-from-vmalloc-to-sgl/20201106-084105 base: https://git.kernel.org/pub/scm/linux/kernel/git/jejb/scsi.git for-next config: riscv-allyesconfig (attached as .config) compiler: riscv64-linux-gcc (GCC) 9.3.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/210cfb290b96c8543a20986a703b6134692e069a
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Douglas-Gilbert/scsi_debug-change-store-from-vmalloc-to-sgl/20201106-084105 git checkout 210cfb290b96c8543a20986a703b6134692e069a
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=riscv
If you fix the issue, kindly add following tag as appropriate
All errors (new ones prefixed by >>):
drivers/scsi/scsi_debug.c: In function 'do_device_access':
>> drivers/scsi/scsi_debug.c:2970:9: error: implicit declaration of function 'sgl_copy_sgl' [-Werror=implicit-function-declaration]
2970 | ret = sgl_copy_sgl(store_sgl, sip->n_elem - sgl_i, rem,
| ^~~~~~~~~~~~
drivers/scsi/scsi_debug.c: In function 'comp_write_worker':
>> drivers/scsi/scsi_debug.c:3034:9: error: implicit declaration of function 'sgl_compare_sgl_idx' [-Werror=implicit-function-declaration]
3034 | equ = sgl_compare_sgl_idx(store_sgl, sip->n_elem - sgl_i, rem,
| ^~~~~~~~~~~~~~~~~~~
drivers/scsi/scsi_debug.c: In function 'unmap_region':
>> drivers/scsi/scsi_debug.c:3505:5: error: implicit declaration of function 'sgl_memset'; did you mean 'memset'? [-Werror=implicit-function-declaration]
3505 | sgl_memset(store_sgl, sip->n_elem - sgl_i, rem, val,
| ^~~~~~~~~~
| memsetcc1: some warnings being treated as errors
vim +/sgl_copy_sgl +2970 drivers/scsi/scsi_debug.c
2938
2939 /* Returns number of bytes copied or -1 if error. */
2940 static int do_device_access(struct sdeb_store_info *sip, struct scsi_cmnd *scp,
2941 u32 data_inout_off, u64 lba, u32 n_blks, bool do_write)
2942 {
2943 int ret;
2944 u32 lb_size = sdebug_sector_size;
2945 u64 block, sgl_i, rem, lba_start, rest = 0;
2946 enum dma_data_direction dir;
2947 struct scsi_data_buffer *sdb = &scp->sdb;
2948 struct scatterlist *store_sgl;
2949
2950 if (do_write) {
2951 dir = DMA_TO_DEVICE;
2952 write_since_sync = true;
2953 } else {
2954 dir = DMA_FROM_DEVICE;
2955 }
2956
2957 if (!sdb->length || !sip)
2958 return 0;
2959 if (scp->sc_data_direction != dir)
2960 return -1;
2961 block = do_div(lba, sdebug_store_sectors);
2962 if (block + n_blks > sdebug_store_sectors)
2963 rest = block + n_blks - sdebug_store_sectors;
2964 lba_start = block * lb_size;
2965 sgl_i = lba_start >> sip->elem_pow2;
2966 rem = lba_start - (sgl_i ? (sgl_i << sip->elem_pow2) : 0);
2967 store_sgl = sip->sgl + sgl_i; /* O(1) to each store sg element */
2968
2969 if (do_write)
> 2970 ret = sgl_copy_sgl(store_sgl, sip->n_elem - sgl_i, rem,
2971 sdb->table.sgl, sdb->table.nents, data_inout_off,
2972 (n_blks - rest) * lb_size);
2973 else
2974 ret = sgl_copy_sgl(sdb->table.sgl, sdb->table.nents, data_inout_off,
2975 store_sgl, sip->n_elem - sgl_i, rem,
2976 (n_blks - rest) * lb_size);
2977
2978 if (ret != (n_blks - rest) * lb_size)
2979 return ret;
2980
2981 if (rest == 0)
2982 goto fini;
2983 if (do_write)
2984 ret += sgl_copy_sgl(sip->sgl, sip->n_elem, 0, sdb->table.sgl, sdb->table.nents,
2985 data_inout_off + ((n_blks - rest) * lb_size), rest * lb_size);
2986 else
2987 ret += sgl_copy_sgl(sdb->table.sgl, sdb->table.nents,
2988 data_inout_off + ((n_blks - rest) * lb_size),
2989 sip->sgl, sip->n_elem, 0, rest * lb_size);
2990 fini:
2991 return ret;
2992 }
2993
2994 /* Returns number of bytes copied or -1 if error. */
2995 static int do_dout_fetch(struct scsi_cmnd *scp, u32 num, u8 *doutp)
2996 {
2997 struct scsi_data_buffer *sdb = &scp->sdb;
2998
2999 if (!sdb->length)
3000 return 0;
3001 if (scp->sc_data_direction != DMA_TO_DEVICE)
3002 return -1;
3003 return sg_copy_buffer(sdb->table.sgl, sdb->table.nents, doutp,
3004 num * sdebug_sector_size, 0, true);
3005 }
3006
3007 /* If sip->storep+lba compares equal to arr(num) or scp->sdb, then if miscomp_idxp is non-NULL,
3008 * copy top half of arr into sip->storep+lba and return true. If comparison fails then return
3009 * false and write the miscompare_idx via miscomp_idxp. Thsi is the COMAPARE AND WRITE case.
3010 * For VERIFY(BytChk=1), set arr to NULL which causes a sgl (store) to sgl (data-out buffer)
3011 * compare to be done. VERIFY(BytChk=3) sets arr to a valid address and sets miscomp_idxp
3012 * to NULL.
3013 */
3014 static bool comp_write_worker(struct sdeb_store_info *sip, u64 lba, u32 num,
3015 const u8 *arr, struct scsi_cmnd *scp, size_t *miscomp_idxp)
3016 {
3017 bool equ;
3018 u64 block, lba_start, sgl_i, rem, rest = 0;
3019 u32 store_blks = sdebug_store_sectors;
3020 const u32 lb_size = sdebug_sector_size;
3021 u32 top_half = num * lb_size;
3022 struct scsi_data_buffer *sdb = &scp->sdb;
3023 struct scatterlist *store_sgl;
3024
3025 block = do_div(lba, store_blks);
3026 if (block + num > store_blks)
3027 rest = block + num - store_blks;
3028 lba_start = block * lb_size;
3029 sgl_i = lba_start >> sip->elem_pow2;
3030 rem = lba_start - (sgl_i ? (sgl_i << sip->elem_pow2) : 0);
3031 store_sgl = sip->sgl + sgl_i; /* O(1) to each store sg element */
3032
3033 if (!arr) { /* sgl to sgl compare */
> 3034 equ = sgl_compare_sgl_idx(store_sgl, sip->n_elem - sgl_i, rem, 3035 sdb->table.sgl, sdb->table.nents, 0,
3036 (num - rest) * lb_size, miscomp_idxp);
3037 if (!equ)
3038 return equ;
3039 if (rest > 0)
3040 equ = sgl_compare_sgl_idx(sip->sgl, sip->n_elem, 0, sdb->table.sgl,
3041 sdb->table.nents, (num - rest) * lb_size,
3042 rest * lb_size, miscomp_idxp);
3043 } else {
3044 equ = sdeb_sgl_cmp_buf(store_sgl, sip->n_elem - sgl_i, arr,
3045 (num - rest) * lb_size, 0);
3046 if (!equ)
3047 return equ;
3048 if (rest > 0)
3049 equ = sdeb_sgl_cmp_buf(sip->sgl, sip->n_elem, arr,
3050 (num - rest) * lb_size, 0);
3051 }
3052 if (!equ || !miscomp_idxp)
3053 return equ;
3054
3055 /* Copy "top half" of dout (args: 4, 5 and 6) into store sgl (args 1, 2 and 3) */
3056 sgl_copy_sgl(store_sgl, sip->n_elem - sgl_i, rem,
3057 sdb->table.sgl, sdb->table.nents, top_half,
3058 (num - rest) * lb_size);
3059 if (rest > 0) { /* for virtual_gb need to handle wrap-around of store */
3060 u32 src_off = top_half + ((num - rest) * lb_size);
3061
3062 sgl_copy_sgl(sip->sgl, sip->n_elem, 0,
3063 sdb->table.sgl, sdb->table.nents, src_off,
3064 rest * lb_size);
3065 }
3066 return true;
3067 }
3068
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
Quoted 24 lines · kernel test robot
Hi Douglas,
Thank you for the patch! Yet something to improve:
[auto build test ERROR on scsi/for-next]
[also build test ERROR on mkp-scsi/for-next v5.10-rc3 next-20201106] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]url: https://github.com/0day-ci/linux/commits/Douglas-Gilbert/scsi_debug-change-store-from-vmalloc-to-sgl/20201106-084105 base: https://git.kernel.org/pub/scm/linux/kernel/git/jejb/scsi.git for-next config: riscv-allyesconfig (attached as .config) compiler: riscv64-linux-gcc (GCC) 9.3.0reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/210cfb290b96c8543a20986a703b6134692e069a
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Douglas-Gilbert/scsi_debug-change-store-from-vmalloc-to-sgl/20201106-084105 git checkout210cfb290b96c8543a20986a703b6134692e069a
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=riscv
Quoted 8 lines
If you fix the issue, kindly add following tag as appropriate
Reported-by kernel test robot <[email protected]>All errors (new ones prefixed by >>):
drivers/scsi/scsi_debug.c: In function 'do_device_access':Quoted 1 line
Quoted 1 line
drivers/scsi/scsi_debug.c:2970:9: error: implicit declaration of function 'sgl_copy_sgl' [-Werror=implicit-function-declaration]2970 | ret = sgl_copy_sgl(store_sgl, sip->n_elem - sgl_i, rem,
Hi Robot,
Perhaps you can't read English. This patch submission says:
'This patch depends on: "[PATCH v4 0/4] scatterlist: add new
capabilities".'
And that patchset has been submitted to the linux-block list for consideration.
Doug Gilbert
Quoted 150 lines
| ^~~~~~~~~~~~
drivers/scsi/scsi_debug.c: In function 'comp_write_worker':Quoted 1 line
Quoted 1 line
drivers/scsi/scsi_debug.c:3034:9: error: implicit declaration of function 'sgl_compare_sgl_idx' [-Werror=implicit-function-declaration]3034 | equ = sgl_compare_sgl_idx(store_sgl, sip->n_elem - sgl_i, rem, | ^~~~~~~~~~~~~~~~~~~ drivers/scsi/scsi_debug.c: In function 'unmap_region':Quoted 1 line
Quoted 1 line
drivers/scsi/scsi_debug.c:3505:5: error: implicit declaration of function 'sgl_memset'; did you mean 'memset'? [-Werror=implicit-function-declaration]3505 | sgl_memset(store_sgl, sip->n_elem - sgl_i, rem, val, | ^~~~~~~~~~ | memsetcc1: some warnings being treated as errors
vim +/sgl_copy_sgl +2970
drivers/scsi/scsi_debug.c2938 2939 /* Returns number of bytes copied or -1 if error. */ 2940 static int do_device_access(struct sdeb_store_info *sip, struct scsi_cmnd *scp, 2941 u32 data_inout_off, u64 lba, u32 n_blks, bool do_write) 2942 { 2943 int ret; 2944 u32 lb_size = sdebug_sector_size; 2945 u64 block, sgl_i, rem, lba_start, rest = 0; 2946 enum dma_data_direction dir; 2947 struct scsi_data_buffer *sdb = &scp->sdb; 2948 struct scatterlist *store_sgl; 2949 2950 if (do_write) { 2951 dir = DMA_TO_DEVICE; 2952 write_since_sync = true; 2953 } else { 2954 dir = DMA_FROM_DEVICE; 2955 } 2956 2957 if (!sdb->length || !sip) 2958 return 0; 2959 if (scp->sc_data_direction != dir) 2960 return -1; 2961 block = do_div(lba, sdebug_store_sectors); 2962 if (block + n_blks > sdebug_store_sectors) 2963 rest = block + n_blks - sdebug_store_sectors; 2964 lba_start = block * lb_size; 2965 sgl_i = lba_start >> sip->elem_pow2; 2966 rem = lba_start - (sgl_i ? (sgl_i << sip->elem_pow2) : 0); 2967 store_sgl = sip->sgl + sgl_i; /* O(1) to each store sg element */ 2968 2969 if (do_write)Quoted 1 line
2970 ret = sgl_copy_sgl(store_sgl,
sip->n_elem-sgl_i, rem,2971
sdb->table.sgl,sdb->table.nents,data_inout_off,2972 (n_blks - rest) * lb_size); 2973 else 2974 ret = sgl_copy_sgl(sdb->table.sgl, sdb->table.nents, data_inout_off, 2975 store_sgl, sip->n_elem - sgl_i, rem, 2976 (n_blks - rest) * lb_size); 2977 2978 if (ret != (n_blks - rest) * lb_size) 2979 return ret; 2980 2981 if (rest == 0) 2982 goto fini; 2983 if (do_write) 2984 ret += sgl_copy_sgl(sip->sgl, sip->n_elem, 0, sdb->table.sgl, sdb->table.nents, 2985 data_inout_off + ((n_blks - rest) * lb_size), rest * lb_size); 2986 else 2987 ret += sgl_copy_sgl(sdb->table.sgl, sdb->table.nents, 2988 data_inout_off + ((n_blks - rest) * lb_size), 2989 sip->sgl, sip->n_elem, 0, rest * lb_size); 2990 fini: 2991 return ret; 2992 } 2993 2994 /* Returns number of bytes copied or -1 if error. */ 2995 static int do_dout_fetch(struct scsi_cmnd *scp, u32 num, u8 *doutp) 2996 { 2997 struct scsi_data_buffer *sdb = &scp->sdb; 2998 2999 if (!sdb->length) 3000 return 0; 3001 if (scp->sc_data_direction != DMA_TO_DEVICE) 3002 return -1; 3003 return sg_copy_buffer(sdb->table.sgl, sdb->table.nents, doutp, 3004 num * sdebug_sector_size, 0, true); 3005 } 3006 3007 /* If sip->storep+lba compares equal to arr(num) or scp->sdb, then if miscomp_idxp is non-NULL, 3008 * copy top half of arr into sip->storep+lba and return true. If comparison fails then return 3009 * false and write the miscompare_idx via miscomp_idxp. Thsi is the COMAPARE AND WRITE case. 3010 * For VERIFY(BytChk=1), set arr to NULL which causes a sgl (store) to sgl (data-out buffer) 3011 * compare to be done. VERIFY(BytChk=3) sets arr to a valid address and sets miscomp_idxp 3012 * to NULL. 3013 */ 3014 static bool comp_write_worker(struct sdeb_store_info *sip, u64 lba, u32 num, 3015 const u8 *arr, struct scsi_cmnd *scp, size_t *miscomp_idxp) 3016 { 3017 bool equ; 3018 u64 block, lba_start, sgl_i, rem, rest = 0; 3019 u32 store_blks = sdebug_store_sectors; 3020 const u32 lb_size = sdebug_sector_size; 3021 u32 top_half = num * lb_size; 3022 struct scsi_data_buffer *sdb = &scp->sdb; 3023 struct scatterlist *store_sgl; 3024 3025 block = do_div(lba, store_blks); 3026 if (block + num > store_blks) 3027 rest = block + num - store_blks; 3028 lba_start = block * lb_size; 3029 sgl_i = lba_start >> sip->elem_pow2; 3030 rem = lba_start - (sgl_i ? (sgl_i << sip->elem_pow2) : 0); 3031 store_sgl = sip->sgl + sgl_i; /* O(1) to each store sg element */ 3032 3033 if (!arr) { /* sgl to sgl compare */Quoted 1 line
3034 equ = sgl_compare_sgl_idx(store_sgl,
sip->n_elem-sgl_i, rem,3035
sdb->table.sgl,sdb->table.nents, 0,3036 (num - rest) * lb_size, miscomp_idxp); 3037 if (!equ) 3038 return equ; 3039 if (rest > 0) 3040 equ = sgl_compare_sgl_idx(sip->sgl, sip->n_elem, 0, sdb->table.sgl, 3041 sdb->table.nents, (num - rest) * lb_size, 3042 rest * lb_size, miscomp_idxp); 3043 } else { 3044 equ = sdeb_sgl_cmp_buf(store_sgl, sip->n_elem - sgl_i, arr, 3045 (num - rest) * lb_size, 0); 3046 if (!equ) 3047 return equ; 3048 if (rest > 0) 3049 equ = sdeb_sgl_cmp_buf(sip->sgl, sip->n_elem, arr, 3050 (num - rest) * lb_size, 0); 3051 } 3052 if (!equ || !miscomp_idxp) 3053 return equ; 3054 3055 /* Copy "top half" of dout (args: 4, 5 and 6) into store sgl (args 1, 2 and 3) */ 3056 sgl_copy_sgl(store_sgl, sip->n_elem - sgl_i, rem, 3057 sdb->table.sgl, sdb->table.nents, top_half, 3058 (num - rest) * lb_size); 3059 if (rest > 0) { /* for virtual_gb need to handle wrap-around of store */ 3060 u32 src_off = top_half + ((num - rest) * lb_size); 3061 3062 sgl_copy_sgl(sip->sgl, sip->n_elem, 0, 3063 sdb->table.sgl, sdb->table.nents, src_off, 3064 rest * lb_size); 3065 } 3066 return true; 3067 } 3068---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/[email protected]