memtests for ioengines using mmap
cover memtests for ioengines using mmap
Add memtest workloads for an ioengine using mmap to run within the memory mapped region (not to/from another transfer buffer in regular memory). Useful for persistent memory testing.
Tests include:
memcpy = copy with libc memcpy() (d = s)(one read, one write) memscan = read memory to registers (one read)
memset = write memory from registers with libc memset() (one write) wmemset = write memory from registers with libc wmemset() (one write) streamcopy = STREAM copy (d = s)(one read, one write) streamadd = STREAM add (d = s1 + s2)(two reads, add, one write) streamscale = STREAM scale (d = 3 * s1)(one read, multiply, one write) streamtriad = STREAM triad (d = s1 + 3 * s2)(two reads, add and
multiply, one write)
Open issues:
* make memscan architecture-independent (or make the test unavailable in non-x86). The initial generic memcsum attempt still results in the compiler generating memory writes.
* ensure fio is not allocating/filling unused xfer_buf
* ensure Read and Write statistics make sense for each memtest (e.g. streamadd should count 2x reads and 1x writes)
* make use_glibc_nt functional (needs to be earlier, may not even be possible)
* combine map_populate, glibc_nt, etc. to avoid creating too many top-level fio options
* add to dev-dax and libpmem ioengines
Robert Elliott (3):
memcpytest: Add more sizes
memcpytest: add more memcpy tests
ioengines: add memtest workloads for ioengines using mmap
HOWTO | 37 +++++ debug.h | 1 + engines/dev-dax.c | 12 +- engines/libpmem.c | 18 +-- engines/mmap.c | 142 +++++++++++++++++-- fio.1 | 37 +++++ init.c | 4 + io_ddir.h | 27 +++- io_u.c | 3 +- io_u.h | 9 +- lib/memcpy.c | 411 ++++++++++++++++++++++++++++++++++++++++++++++++------ lib/memcpy.h | 4 + options.c | 91 ++++++++++++ thread_options.h | 7 + 14 files changed, 733 insertions(+), 70 deletions(-)
Signature · 1 line
2.14.3
PATCH 1/3 memcpytest: Add more sizes
From: Robert Elliott <[email protected]>
Run memcpy tests over much larger sizes (L3 cache size and larger), and reduce the number of iterations.
--- lib/memcpy.c | 88 +++++++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 78 insertions(+), 10 deletions(-)
lib/memcpy.c +78 -10
@@ -8,9 +8,17 @@#include "../gettime.h" #include "../fio.h" -#define BUF_SIZE 32 * 1024 * 1024ULL +/* largest last-level CPU cache size of an x86 in 2018 in bytes */ +#define LLC_SIZE (45* 1024 * 1024ULL) -#define NR_ITERS 64 +#define BUF_SIZE (LLC_SIZE * 4ULL) + +/* alignment in bytes for the buffers. Ensure that functions like +* libc memcpy can use most optimal paths (512 B for x86_64 AVX2). +*/ +#define BUF_ALIGN 512 + +#define NR_ITERS 8struct memcpy_test {const char *name;
@@ -21,15 +29,27 @@ struct memcpy_test {static struct memcpy_test tests[] = { { - .name ="8 bytes" , + .name =" 4 bytes" , + .size =4 , + }, + { + .name =" 8 bytes" , .size =8 , }, { - .name ="16 bytes" , + .name =" 16 bytes" , .size =16 , }, { - .name ="96 bytes" , + .name =" 32 bytes" , + .size =32 , + }, + { + .name =" 64 bytes" , + .size =64 , + }, + { + .name =" 96 bytes" , .size =96 , }, {
@@ -45,25 +65,73 @@ static struct memcpy_test tests[] = { .size = 512, }, { - .name = "2048 bytes", + .name = " 2 KiB", .size = 2048, }, { - .name = "8192 bytes", + .name = " 4 KiB", + .size = 4096, + }, + { + .name = " 8 KiB", .size = 8192, }, { - .name = "131072 bytes", + .name = "128 KiB", .size = 131072, }, { - .name = "262144 bytes", + .name = "256 KiB", .size = 262144, }, { - .name = "524288 bytes", + .name = "512 KiB", .size = 524288, }, + { + .name = " 8 MiB", + .size = 8 * 1024 * 1024, + }, + { + .name = "6x 1.375 MiB", + .size = 8650752, + }, + { + .name = " 9 MiB", + .size = 9 * 1024 * 1024, + }, + { + .name = " 16 MiB", + .size = 16 * 1024 * 1024, /* 3/4 L3 size is 16.5 */ + }, + { + .name = " 17 MiB", + .size = 17 * 1024 * 1024, /* 3/4 L3 size is 16.5 */ + }, + { + .name = " 22 MiB", + .size = 22 * 1024 * 1024, /* L3 size */ + }, + { + .name = " 32 MiB", + .size = 32 * 1024 * 1024, /* >L3 size */ + }, + { + .name = " 40 MiB", + .size = 40 * 1024 * 1024, + }, + { + .name = " 48 MiB", + .size = 48 * 1024 * 1024, /* larger than most L3 */ + }, + { + .name = "128 MiB", + .size = 128 * 1024 * 1024, /* much larger than L3 */ + }, + { + .name = "full buffer", + .size = BUF_SIZE, + }, { .name = NULL, },
Signature · 1 line
2.14.3
PATCH 2/3 memcpytest: add more memcpy tests
In reply to Robert ElliottFrom: Robert Elliott <[email protected]>
Add more memcpy tests:
memcpy = copy with libc memcpy() (d = s)(one read, one write)
memcsum = read memory to registers (one read)
memset = write memory from registers with libc memset() (one write) wmemset = write memory from registers with libc wmemset() (one write) streamcopy = STREAM copy (d = s)(one read, one write)
streamadd = STREAM add (d = s1 + s2)(two reads, add, one write) streamscale = STREAM scale (d = 3 * s1)(one read, multiply, one write) streamtriad = STREAM triad (d = s1 + 3 * s2)(two reads, add and multiply, one write)
--- engines/dev-dax.c | 12 +- engines/libpmem.c | 18 +-- engines/mmap.c | 13 ++- lib/memcpy.c | 323 +++++++++++++++++++++++++++++++++++++++++++++++++----- lib/memcpy.h | 4 + 5 files changed, 320 insertions(+), 50 deletions(-)
engines/dev-dax.c +6 -6
@@ -73,19 +73,19 @@ static int fio_devdax_file(struct thread_data *td, struct fio_file *f, size_t length, off_t off) {struct fio_devdax_data *fdd =FILE_ENG_DATA (f); -int flags =0 ; +int prot =0 ;if (td_rw (td)) - flags =PROT_READ |PROT_WRITE ; + prot =PROT_READ |PROT_WRITE ;else if (td_write (td)) { - flags =PROT_WRITE ; + prot =PROT_WRITE ;if (td->o.verify !=VERIFY_NONE ) - flags |=PROT_READ ; + prot |=PROT_READ ; }else - flags =PROT_READ ; + prot =PROT_READ ; - fdd->devdax_ptr =mmap (NULL , length, flags,MAP_SHARED , f->fd, off); + fdd->devdax_ptr =mmap (NULL , length, prot,MAP_SHARED , f->fd, off);if (fdd->devdax_ptr ==MAP_FAILED ) { fdd->devdax_ptr =NULL ;td_verror (td, errno,"mmap" );
engines/libpmem.c +9 -9
@@ -318,31 +318,31 @@ static int fio_libpmem_file(struct thread_data *td, struct fio_file *f, size_t length, off_t off) {struct fio_libpmem_data *fdd =FILE_ENG_DATA (f); -int flags =0 ; +int prot =0 ;void *addr =NULL ;dprint (FD_IO ,"DEBUG fio_libpmem_file\n" );if (td_rw (td)) - flags =PROT_READ |PROT_WRITE ; + prot =PROT_READ |PROT_WRITE ;else if (td_write (td)) { - flags =PROT_WRITE ; + prot =PROT_WRITE ;if (td->o.verify !=VERIFY_NONE ) - flags |=PROT_READ ; + prot |=PROT_READ ; }else - flags =PROT_READ ; + prot =PROT_READ ;dprint (FD_IO ,"f->file_name = %s td->o.verify = %d \n" , f->file_name, td->o.verify); -dprint (FD_IO ,"length = %ld flags = %d f->fd = %d off = %ld \n" , - length, flags, f->fd,off); +dprint (FD_IO ,"length = %ld prot = %d f->fd = %d off = %ld \n" , + length, prot, f->fd,off); addr =util_map_hint (length,0 );dprint (FD_IO ,"DEBUG mmap addr=%p length=0x%lx prot=0x%x\n" , - addr, length, flags); - fdd->libpmem_ptr =mmap (addr, length, flags,MAP_SHARED , f->fd, off); + addr, length, prot); + fdd->libpmem_ptr =mmap (addr, length, prot,MAP_SHARED , f->fd, off);if (fdd->libpmem_ptr ==MAP_FAILED ) { fdd->libpmem_ptr =NULL ;td_verror (td, errno,"mmap" );
engines/mmap.c +7 -6
@@ -31,19 +31,20 @@ static int fio_mmap_file(struct thread_data *td, struct fio_file *f, size_t length, off_t off) {struct fio_mmap_data *fmd =FILE_ENG_DATA (f); -int flags =0 ; +int prot =0 ; +int flags =MAP_SHARED ;if (td_rw (td) && !td->o.verify_only) - flags =PROT_READ |PROT_WRITE ; + prot =PROT_READ |PROT_WRITE ;else if (td_write (td) && !td->o.verify_only) { - flags =PROT_WRITE ; + prot =PROT_WRITE ;if (td->o.verify !=VERIFY_NONE ) - flags |=PROT_READ ; + prot |=PROT_READ ; }else - flags =PROT_READ ; + prot =PROT_READ ; - fmd->mmap_ptr =mmap (NULL , length, flags,MAP_SHARED , f->fd, off); + fmd->mmap_ptr =mmap (NULL , length, prot, flags, f->fd, off);if (fmd->mmap_ptr ==MAP_FAILED ) { fmd->mmap_ptr =NULL ;td_verror (td, errno,"mmap" );
lib/memcpy.c +294 -29
431 lines not on this page · raw message
lib/memcpy.h +4 -0
@@ -2,5 +2,9 @@#define FIO_MEMCPY_H int fio_memcpy_test (const char *type); +void streamcopy (void *dst,void const *src,size_t len); +void streamscale (void *dst,void const *src,size_t len); +void streamadd (void *dst,void const *src,void const *src2,size_t len); +void streamtriad (void *dst,void const *src,void const *src2,size_t len);#endif
Signature · 1 line
2.14.3
Re: [PATCH 2/3] memcpytest: add more memcpy tests
Quoted 11 lines · Robert Elliott
From: Robert Elliott <[email protected]>
Add more memcpy tests:
memcpy = copy with libcmemcpy()(d = s)(one read, one write)
memcsum = read memory to registers (one read)
memset = write memory from registers with libcmemset()(one write) wmemset = write memory from registers with libcwmemset()(one write) streamcopy = STREAM copy (d = s)(one read, one write)
streamadd = STREAM add (d = s1 + s2)(two reads, add, one write) streamscale = STREAM scale (d = 3 * s1)(one read, multiply, one write) streamtriad = STREAM triad (d = s1 + 3 * s2)(two reads, add and multiply, one write)
The engine changes in here don't seem related?
lib/memcpy.c enum { · line 214
Quoted 6 lines
lib/memcpy.c +6
-0+static void flush_caches (struct memcpy_type *t,struct memcpy_test *test) +{ +__builtin___clear_cache (test->src, test->src +BUF_SIZE ); +__builtin___clear_cache (test->src2, test->src2 +BUF_SIZE ); +__builtin___clear_cache (test->dst, test->dst +BUF_SIZE ); +}
Is this going to work on all platforms? I'm fine with adding it, but we'll probably need a configure test to ensure we don't break various builds.
Signature · 1 line
Jens Axboe
PATCH 3/3 ioengines: add memtest workloads for ioengines using mmap
In reply to Robert ElliottFrom: Robert Elliott <[email protected]>
Add memtest workloads for an ioengine using mmap to run within the memory mapped region (not to/from another transfer buffer in regular memory). Useful for persistent memory testing.
Tests include:
memcpy = copy with libc memcpy() (d = s)(one read, one write)
memscan = read memory to registers (one read)
memset = write memory from registers with libc memset() (one write) wmemset = write memory from registers with libc wmemset() (one write) streamcopy = STREAM copy (d = s)(one read, one write)
streamadd = STREAM add (d = s1 + s2)(two reads, add, one write) streamscale = STREAM scale (d = 3 * s1)(one read, multiply, one write) streamtriad = STREAM triad (d = s1 + 3 * s2)(two reads, add and multiply, one write)
NOTE: memscan function is x86-specific, not ready for inclusion yet.
--- HOWTO | 37 ++++++++++++++++ debug.h | 1 + engines/mmap.c | 127 +++++++++++++++++++++++++++++++++++++++++++++++++++++-- fio.1 | 37 ++++++++++++++++ init.c | 4 ++ io_ddir.h | 27 ++++++++++-- io_u.c | 3 +- io_u.h | 9 +++- options.c | 91 +++++++++++++++++++++++++++++++++++++++ thread_options.h | 7 +++ 10 files changed, 334 insertions(+), 9 deletions(-)
HOWTO +37 -0
@@ -992,6 +992,9 @@ I/O type Sequential writes. **trim** Sequential trims (Linux block devices only). + **memtest** + Memory test (ioengines using mmap only). + Specified with memtest=. **randread** Random reads. **randwrite**
@@ -1019,6 +1022,40 @@ I/O type For instance, using ``rw=write:4k`` will skip 4k for every write. Also see the :option:`rw_sequencer` option. +.. option:: memtest=str + + Type of memory test to perform if rw=memtest is specified. + For use with ioengines supporting mmap() - performs the tests within the + memory mapped region. Useful for persistent memory testing. + + Accepted values are: + + **memcpy** + copy with libc memcpy() (d = s)(one read, one write) + **memscan** (default) + read memory to registers (one read) + **memset** + write memory from registers with libc memset() (one write) + **wmemset** + write memory from registers with libc wmemset() (one write) + **streamcopy** + STREAM copy (d = s)(one read, one write) + **streamadd** + STREAM add (d = s1 + s2)(two reads, add, one write) + **streamscale** + STREAM scale (d = 3 * s1)(one read, multiply, one write) + **streamtriad** + STREAM triad (d = s1 + 3 * s2)(two reads, add and multiply, one write) + + If library functions are provided by glibc, memcpy() honors this + environment variable: + export GLIBC_TUNABLES=glibc.tune.x86_non_temporal_threshold=131072 + to select the threshold for choosing non-temporal stores (e.g., vmovnt) + rather than normal stores (e.g., rep movsb). + + Additional tunables might also be needed: + export GLIBC_TUNABLES=glibc.tune.x86_non_temporal_threshold=131072:glibc.tune.hwcaps=AVX2_Usable,ERMS,-Prefer_No_VZEROUPPER,AVX_Fast_Unaligned_Load + .. option:: rw_sequencer=str If an offset modifier is given by appending a number to the ``rw=<str>``
debug.h +1 -0
@@ -23,6 +23,7 @@ enum {FD_COMPRESS ,FD_STEADYSTATE ,FD_HELPERTHREAD , +FD_MEMTEST , FD_DEBUG_MAX, };
engines/mmap.c +124 -3
171 lines not on this page · raw message
fio.1 +37 -0
@@ -769,6 +769,9 @@ Random writes. .B randtrim Random trims (Linux block devices only). .TP +.B memtest +Memory test (for ioengines using mmap only). +.TP .B rw,readwrite Sequential mixed reads and writes. .TP
@@ -818,6 +821,40 @@ behaves in a similar fashion, except it sends the same offset 8 number of times before generating a new offset. .RE .TP +.BI memtest \fR=\fPstr "\fR +Type of memory test to perform if rw=memtest is specified. +For use with ioengines supporting mmap() - performs the tests within the +mapped region. Useful for persistent memory testing. +Accepted values are: +.RS +.RS +.TP +.B memcpy +.thcopy with libc memcpy() (d = s)(one read, one write) +.TP +.B memscan (default) +read memory to registers (one read) +.TP +.B memset +write memory from registers with libc memset() (one write) +.TP +.B wmemset +write memory from registers with libc wmemset() (one write) +.TP +.B streamcopy +STREAM copy (d = s)(one read, one write) +.TP +.B streamadd +STREAM add (d = s1 + s2)(two reads, add, one write) +.TP +.B streamscale +STREAM scale (d = 3 * s1)(one read, multiply, one write) +.TP +.B streamtriad +STREAM triad (d = s1 + 3 * s2)(two reads, add and multiply, one write) +.RE +.RE +.TP .BI unified_rw_reporting \fR=\fPbool Fio normally reports statistics on a per data direction basis, meaning that reads, writes, and trims are accounted and reported separately. If this
init.c +4 -0
@@ -2251,6 +2251,10 @@ struct debug_level debug_levels[] = { .help = "Helper thread logging", .shift = FD_HELPERTHREAD, }, + { .name = "mmap", + .help = "mmap-based memory test logging", + .shift = FD_MEMTEST, + }, { .name = NULL, }, };
io_ddir.h +23 -4
@@ -37,6 +37,7 @@ enum td_ddir {TD_DDIR_RANDRW =TD_DDIR_RW |TD_DDIR_RAND ,TD_DDIR_RANDTRIM =TD_DDIR_TRIM |TD_DDIR_RAND ,TD_DDIR_TRIMWRITE =TD_DDIR_TRIM |TD_DDIR_WRITE , + TD_DDIR_LAST = TD_DDIR_TRIMWRITE + 1 };#define td_read (td) ((td)->o.td_ddir & TD_DDIR_READ)
@@ -61,14 +62,32 @@ static inline int ddir_rw(enum fio_ddir ddir)static inline const char *ddir_str (enum td_ddir ddir) { -static const char *__str[] = {NULL ,"read" ,"write" ,"rw" ,"rand" , -"randread" ,"randwrite" ,"randrw" , -"trim" ,NULL ,"trimwrite" ,NULL ,"randtrim" }; +static const char *__str[] = { +NULL ,"read" ,"write" ,"rw" ,// 0x0 - 0x3 +"rand" ,"randread" ,"randwrite" ,"randrw" ,// 0x4 - 0x7 RAND +NULL ,NULL ,"trimwrite" ,NULL ,// 0x8 - 0xB TRIM +"randtrim" ,NULL ,NULL ,NULL ,// 0xC - 0xF RAND, TRIM + }; -return __str[ddir]; +if (ddir <TD_DDIR_LAST ) +return __str[ddir]; +else +return NULL ; }#define ddir_rw_sum (arr) \ ((arr)[DDIR_READ] + (arr)[DDIR_WRITE] + (arr)[DDIR_TRIM]) +enum td_memtest { +TD_MEMTEST_MEMCPY , +TD_MEMTEST_MEMSCAN , +TD_MEMTEST_MEMSET , +TD_MEMTEST_WMEMSET , +TD_MEMTEST_STREAM_COPY , +TD_MEMTEST_STREAM_ADD , +TD_MEMTEST_STREAM_SCALE , +TD_MEMTEST_STREAM_TRIAD , +}; +#endif +
io_u.c +2 -1
@@ -968,6 +968,7 @@ static int fill_io_u(struct thread_data *td, struct io_u *io_u)if (td_ioengine_flagged (td,FIO_NOIO )) goto out; + io_u->memtest = td->o.td_memtest;set_rw_ddir (td, io_u);/*
@@ -1791,7 +1792,7 @@ struct io_u *get_io_u(struct thread_data *td) f->last_start[io_u->ddir] = io_u->offset; f->last_pos[io_u->ddir] = io_u->offset + io_u->buflen; -if (io_u->ddir ==DDIR_WRITE ) { +if (io_u->ddir ==DDIR_WRITE && !io_u->memtest) {if (td->flags &TD_F_REFILL_BUFFERS ) { io_u_fill_buffer(td, io_u, td->o.min_bs[DDIR_WRITE],
io_u.h +8 -1
@@ -37,6 +37,7 @@ struct io_u {struct fio_file *file;unsigned int flags;enum fio_ddir ddir; +unsigned int memtest;/* * For replay workloads, we may want to account as a different
@@ -152,7 +153,13 @@ static inline void dprint_io_u(struct io_u *io_u, const char *p) {struct fio_file *f = io_u->file; -if (f) +if (f && io_u->memtest) +dprint (FD_IO ,"%s: io_u %p: off=0x%llx,len=0x%lx,ddir=%d,memtest=%d,file=%s\n" , + p, io_u, + (unsigned long long ) io_u->offset, + io_u->buflen, io_u->ddir, io_u->memtest, + f->file_name); +else if (f) dprint(FD_IO, "%s: io_u %p: off=0x%llx,len=0x%lx,ddir=%d,file=%s\n", p, io_u, (unsigned long long) io_u->offset,
options.c +91 -0
115 lines not on this page · raw message
thread_options.h +7 -0
@@ -58,6 +58,7 @@ struct thread_options {char *ioengine_so_path;char *mmapfile;enum td_ddir td_ddir; +enum td_memtest td_memtest;unsigned int rw_seq;unsigned int kb_base;unsigned int unit_base;
@@ -191,6 +192,8 @@ struct thread_options {unsigned long long lockmem;enum fio_memtype mem_type;unsigned int mem_align; +unsigned int use_map_populate; +unsigned int use_glibc_nt;unsigned long long max_latency;
@@ -338,6 +341,8 @@ struct thread_options_pack {uint8_t ioengine[FIO_TOP_STR_MAX ];uint8_t mmapfile[FIO_TOP_STR_MAX ];uint32_t td_ddir; +uint32_t td_memtest; +uint32_t reserved;uint32_t rw_seq;uint32_t kb_base;uint32_t unit_base;
@@ -469,6 +474,8 @@ struct thread_options_pack {uint64_t lockmem;uint32_t mem_type;uint32_t mem_align; +uint32_t use_map_populate; +uint32_t use_glibc_nt;uint32_t stonewall;uint32_t new_group;
Signature · 1 line
2.14.3