xfs_io: new functions
PATCH 2/3 xfs_io: implement preadv for vectored reads
In reply to Dave ChinnerFrom: Dave Chinner <[email protected]>
When looking at KVM based direct IO patterns, I noticed that it was using preadv and pwritev, and I could not use xfs_io to simulate these IO patterns. Extend the pread command to be able to issue vectored read IO to enable use to simulate KVM style direct IO.
Also document the new parameters as well as all the missing pread command parameters in the xfs_io(8) man page.
--- io/pread.c | 127 ++++++++++++++++++++++++++++++++++++++++++++++++----- man/man8/xfs_io.8 | 21 ++++++++- 2 files changed, 136 insertions(+), 12 deletions(-)
io/pread.c +116 -11
@@ -46,6 +46,8 @@ pread_help(void)" -R -- read at random offsets in the range of bytes\n" " -Z N -- zeed the random number generator (used when reading randomly)\n" " (heh, zorry, the -s/-S arguments were already in use in pwrite)\n" +" -V N -- use vectored IO with N iovecs of blocksize each (preadv)\n" +"\n" " When in \"random\" mode, the number of read operations will equal the\n" " number required to do a complete forward/backward scan of the range.\n" " Note that the offset within the range is chosen at random each time\n"
@@ -56,6 +58,42 @@ pread_help(void)void *buffer;size_t highwater;size_t buffersize; +int vectors; +struct iovec *iov; + +static int +alloc_iovec ( +size_t bsize, +int uflag, +unsigned int seed) +{ +int i; + + iov =calloc (vectors,sizeof (struct iovec )); +if (!iov) +return -1 ; + + buffersize =0 ; +for (i =0 ; i < vectors; i++) { + iov[i].iov_base =memalign (pagesize, bsize); + buffer =memalign (pagesize, bsize); +if (!buffer) { +perror ("memalign" ); + goto unwind; + } + iov[i].iov_len = bsize; +if (!uflag) +memset (iov[i].iov_base, seed, bsize); + } + buffersize = bsize * vectors; +return 0 ; +unwind: +for ( ; i >=0 ; i--) +free (iov[i].iov_base); +free (iov); + iov =NULL ; +return -1 ; +}int alloc_buffer(
@@ -63,6 +101,9 @@ alloc_buffer( int uflag, unsigned int seed) { + if (vectors) + return alloc_iovec(bsize, uflag, seed); +if (bsize > highwater) {if (buffer)free (buffer);
@@ -81,7 +122,8 @@ alloc_buffer( }void -dump_buffer ( +__dump_buffer ( +void *buf,off64_t offset,ssize_t len) {
@@ -105,6 +147,64 @@ dump_buffer( } } +void +dump_buffer ( +off64_t offset, +ssize_t len) +{ +int i, l; + +if (!vectors) { +__dump_buffer (buffer, offset, len); +return ; + } + +for (i =0 ; len >0 && i < vectors; i++) { + l =min (len, iov[i].iov_len); + +__dump_buffer (iov[i].iov_base, offset, l); + len -= l; + offset += l; + } +} + +static int +do_pread ( +int fd, +off64_t offset, +ssize_t count, +ssize_t buffer_size) +{ +int vecs =0 ; +ssize_t oldlen =0 ; +ssize_t bytes =0 ; + + +if (!vectors) +return pread64 (fd, buffer,min (count, buffer_size), offset); + +/* trim the iovec if necessary */ +if (count < buffersize) { +size_t len =0 ; +while (len + iov[vecs].iov_len < count) { + len += iov[vecs].iov_len; + vecs++; + } + oldlen = iov[vecs].iov_len; + iov[vecs].iov_len = count - len; + vecs++; + }else { + vecs = vectors; + } + bytes =preadv (fd, iov, vectors, offset); + +/* restore trimmed iov */ +if (oldlen) + iov[vecs -1 ].iov_len = oldlen; + +return bytes; +} + static int read_random( int fd,
@@ -132,7 +232,7 @@ read_random( *total =0 ;while (count >0 ) { off = ((random () % range) / buffersize) * buffersize; - bytes =pread64 (fd, buffer, buffersize, off); + bytes =do_pread (fd, off, buffersize, buffersize);if (bytes ==0 )break ;if (bytes <0 ) {
@@ -173,9 +273,8 @@ read_backward(/* Do initial unaligned read if needed */ if ((bytes_requested = (off % buffersize))) { - bytes_requested =min (cnt, bytes_requested); off -= bytes_requested; - bytes =pread (fd, buffer, bytes_requested, off); + bytes =do_pread (fd, off, bytes_requested, buffersize);if (bytes ==0 )return ops;if (bytes <0 ) {
@@ -193,7 +292,7 @@ read_backward(while (cnt > end) { bytes_requested =min (cnt, buffersize); off -= bytes_requested; - bytes =pread64 (fd, buffer, bytes_requested, off); + bytes =do_pread (fd, off, cnt, buffersize);if (bytes ==0 )break ;if (bytes <0 ) {
@@ -219,14 +318,12 @@ read_forward(int onlyone, int eof) { - size_t bytes_requested; ssize_t bytes;int ops =0 ; *total =0 ;while (count >0 || eof) { - bytes_requested =min (count, buffersize); - bytes =pread64 (fd, buffer, bytes_requested, offset); + bytes =do_pread (fd, offset, count, buffersize);if (bytes ==0 )break ;if (bytes <0 ) {
@@ -237,7 +334,7 @@ read_forward(if (verbose)dump_buffer (offset, bytes); *total += bytes; -if (onlyone || bytes < bytes_requested) +if (onlyone || bytes <min (count, buffersize))break ; offset += bytes; count -= bytes;
@@ -278,7 +375,7 @@ pread_f(init_cvtnum (&fsblocksize, &fssectsize); bsize = fsblocksize; -while ((c =getopt (argc, argv,"b:BCFRquvZ:" )) !=EOF ) { +while ((c =getopt (argc, argv,"b:BCFRquvV:Z:" )) !=EOF ) {switch (c) {case 'b' : tmp =cvtnum (fsblocksize, fssectsize, optarg);
@@ -309,6 +406,14 @@ pread_f(case 'v' : vflag =1 ;break ; +case 'V' : + vectors =strtoul (optarg, &sp,0 ); +if (!sp || sp == optarg) { +printf (_ ("non-numberic vector count == %s\n" ), + optarg); +return 0 ; + } +break ;case 'Z' : zeed =strtoul (optarg, &sp,0 );if (!sp || sp == optarg) {
@@ -393,7 +498,7 @@ pread_init(void) pread_cmd.argmin =2 ; pread_cmd.argmax =-1 ; pread_cmd.flags =CMD_NOMAP_OK |CMD_FOREIGN_OK ; - pread_cmd.args =_ ("[-b bs] [-v] off len" ); + pread_cmd.args =_ ("[-b bs] [-v] [-i N] [-FBR [-Z N]] off len" ); pread_cmd.oneline =_ ("reads a number of bytes at a specified offset" ); pread_cmd.help = pread_help;
man/man8/xfs_io.8 +20 -1
@@ -131,7 +131,7 @@ See the .B close command. .TP -.BI "pread [ \-b " bsize " ] [ \-v ] " "offset length" +.BI "pread [ \-b " bsize " ] [ \-v ] [ \-FBR [ \-Z " seed " ] ] [ \-V " vectors " ] " "offset length" Reads a range of bytes in a specified blocksize from the given .IR offset . .RS 1.0i
@@ -145,6 +145,25 @@ requests will be split. The default blocksize is 4096 bytes. .B \-v dump the contents of the buffer after reading, by default only the count of bytes actually read is dumped. +.TP +.B \-F +read the buffers in a forwards sequential direction. +.TP +.B \-B +read the buffers in a reserve sequential direction. +.TP +.B \-R +read the buffers in the give range in a random order. +.TP +.B \-Z seed +specify the random number seed used for random reads. +.TP +.B \-V vectors +Use the vectored IO read syscall +.BR preadv (2) +with a number of blocksize length iovecs. The number of iovecs is set by the +.I vectors +parameter. .PD .RE .TP
Signature · 6 lines
1.7.10 _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs
cover xfs_io: new functions
This is just a couple of additional functions for xfs_io I have had sitting around for a while. The first is an interface to sync_file_range() for better control of file writeback. The second and third introduce vectored pread/pwrite so that I could simulate the same style of vectored IO that KVM does via direct IO (hint - tracing indicated that the generic direct IO code doesn't handle this particularly efficiently).
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
PATCH 3/3 xfs_io: implement pwritev for vectored writes
From: Dave Chinner <[email protected]>
When looking at KVM based direct IO patterns, I noticed that it was using preadv and pwritev, and I could not use xfs_io to simulate these IO patterns. Extend the pwrite command to be able to issue vectored write IO to enable use to simulate KVM style direct IO.
Also document the new parameters as well as all the missing pwrite command parameters in the xfs_io(8) man page.
--- io/io.h | 2 ++ io/pwrite.c | 61 +++++++++++++++++++++++++++++++++++++++++++++-------- man/man8/xfs_io.8 | 31 ++++++++++++++++++++++++++- 3 files changed, 84 insertions(+), 10 deletions(-)
io/io.h +2 -0
@@ -82,6 +82,8 @@ extern unsigned int recurse_dir;extern void *buffer;extern size_t buffersize; +extern int vectors; +extern struct iovec *iov;extern int alloc_buffer (size_t ,int ,unsigned int );extern int read_buffer (int ,off64_t ,long long ,long long *,int ,int );
io/pwrite.c +52 -9
125 lines not on this page · raw message
man/man8/xfs_io.8 +30 -1
@@ -172,7 +172,7 @@ See the .B pread command. .TP -.BI "pwrite [ \-i " file " ] [ \-d ] [ \-s " skip " ] [ \-b " size " ] [ \-S " seed " ] " "offset length" +.BI "pwrite [ \-i " file " ] [ \-d ] [ \-s " skip " ] [ \-b " size " ] [ \-S " seed " ] [ \-FBR [ \-Z " zeed " ] ] [ \-wW ] [ \-V " vectors " ] " "offset length" Writes a range of bytes in a specified blocksize from the given .IR offset . The bytes written can be either a set pattern or read in from another
@@ -203,6 +203,35 @@ requests will be split. The default blocksize is 4096 bytes. used to set the (repeated) fill pattern which is used when the data to write is not coming from a file. The default buffer fill pattern value is 0xcdcdcdcd. +.TP +.B \-F +write the buffers in a forwards sequential direction. +.TP +.B \-B +write the buffers in a reserve sequential direction. +.TP +.B \-R +write the buffers in the give range in a random order. +.TP +.B \-Z seed +specify the random number seed used for random write +.TP +.B \-w +call +.BR fdatasync (2) +once all writes are complete (included in timing results) +.TP +.B \-W +call +.BR fsync (2) +once all writes are complete (included in timing results) +.TP +.B \-V vectors +Use the vectored IO write syscall +.BR pwritev (2) +with a number of blocksize length iovecs. The number of iovecs is set by the +.I vectors +parameter. .RE .PD .TP
Signature · 6 lines
1.7.10 _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs
PATCH 1/3 xfs_io: add sync_file_range support
In reply to Dave ChinnerFrom: Dave Chinner <[email protected]>
Add sync_file_range support to xfs_io to allow fine grained control of data writeback and syncing on a given file.
--- io/Makefile | 5 +++ io/init.c | 1 + io/io.h | 6 +++ io/sync_file_range.c | 107 ++++++++++++++++++++++++++++++++++++++++++++++++++ man/man8/xfs_io.8 | 19 +++++++++ 5 files changed, 138 insertions(+) create mode 100644 io/sync_file_range.c
io/Makefile +5 -0
@@ -58,6 +58,11 @@ CFILES += inject.c resblks.c LCFLAGS += -DHAVE_INJECT -DHAVE_RESBLKS endif +ifeq ($(PKG_PLATFORM),linux) +CFILES += sync_file_range.c +LCFLAGS += -DHAVE_SYNC_FILE_RANGE +endif + ifeq ($(ENABLE_READLINE),yes) LLDLIBS += $(LIBREADLINE) $(LIBTERMCAP) endif
io/init.c +1 -0
@@ -78,6 +78,7 @@ init_commands(void)sendfile_init ();shutdown_init ();truncate_init (); +sync_range_init (); } static int
io/io.h +6 -0
@@ -141,3 +141,9 @@ extern void fiemap_init(void);#else #define fiemap_init () do { } while (0)#endif + +#ifdef HAVE_SYNC_FILE_RANGE +extern void sync_range_init (void ); +#else +#define sync_range_init () do { } while (0) +#endif
io/sync_file_range.c new file +107 -0
107 lines not on this page · raw message
man/man8/xfs_io.8 +19 -0
@@ -273,6 +273,25 @@ See the .B fsync command. .TP +.BI "sync_range [ \-a | \-b | \-w ] offset length " +On platforms which support it, allows control of syncing a range of the file to +disk. With no options, SYNC_FILE_RANGE_WRITE is implied on the range supplied. +.RS 1.0i +.PD 0 +.TP 0.4i +.B \-a +wait for IO in the given range to finish after writing +(SYNC_FILE_RANGE_WAIT_AFTER). +.TP +.B \-b +wait for IO in the given range to finish before writing +(SYNC_FILE_RANGE_WAIT_BEFORE). +.TP +.B \-w +start writeback of dirty data in the given range (SYNC_FILE_RANGE_WRITE). +.RE +.PD +.TP .BI resvsp " offset length" Allocates reserved, unwritten space for part of a file using the XFS_IOC_RESVSP system call described in the
Signature · 6 lines
1.7.10 _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs
Re: [PATCH 1/3] xfs_io: add sync_file_range support
Quoted 6 lines · Dave Chinner
From: Dave Chinner <[email protected]>
Add
sync_file_rangesupport toxfs_ioto allow fine grained control of data writeback and syncing on a given file.Reviewed-by Dave Chinner <[email protected]>
Looks good,
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
Re: [PATCH 2/3] xfs_io: implement preadv for vectored reads
In reply to Dave ChinnerQuoted 11 lines · Dave Chinner
From: Dave Chinner <[email protected]>
When looking at KVM based direct IO patterns, I noticed that it was using preadv and pwritev, and I could not use
xfs_ioto simulate these IO patterns. Extend the pread command to be able to issue vectored read IO to enable use to simulate KVM style direct IO.Also document the new parameters as well as all the missing pread command parameters in the
xfs_io(8)man page.Signed-off-by Dave Chinner <[email protected]>
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
Re: [PATCH 3/3] xfs_io: implement pwritev for vectored writes
In reply to Dave ChinnerQuoted 9 lines · Dave Chinner
From: Dave Chinner <[email protected]>
When looking at KVM based direct IO patterns, I noticed that it was using preadv and pwritev, and I could not use
xfs_ioto simulate these IO patterns. Extend the pwrite command to be able to issue vectored write IO to enable use to simulate KVM style direct IO.Also document the new parameters as well as all the missing pwrite command parameters in the
xfs_io(8)man page.
Looks good,
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
Re: [PATCH 2/3] xfs_io: implement preadv for vectored reads
In reply to Dave ChinnerQuoted 7 lines · Dave Chinner
From: Dave Chinner<[email protected]>
When looking at KVM based direct IO patterns, I noticed that it was using preadv and pwritev, and I could not use
xfs_ioto simulate these IO patterns. Extend the pread command to be able to issue vectored read IO to enable use to simulate KVM style direct IO.
Quoted 5 lines
Also document the new parameters as well as all the missing pread command parameters in the
xfs_io(8)man page.Signed-off-by Dave Chinner<[email protected]>---
+int vectors;
Quoted 7 lines
io/pread.c +7
-0+struct iovec *iov; + +static int +alloc_iovec ( +size_t bsize, +int uflag, +unsigned int seed)
io/pread.c pread_help(void) · line 78
Quoted 10 lines
io/pread.c +10
-0+{ +int i; + + iov =calloc (vectors,sizeof (struct iovec )); +if (!iov) +return -1 ; + + buffersize =0 ; +for (i =0 ; i< vectors; i++) { + iov[i].iov_base =memalign (pagesize, bsize);
^^^^^
Okay, make sense.
io/pread.c pread_help(void) · line 80
Quoted 2 lines
io/pread.c +2
-0+ buffer =memalign (pagesize, bsize); +if (!buffer) {
^^^^^^
Here I am bit confused. Did you want to allocate to the buffer for the iovec case?
Thank-you,
Mark.
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
Quoted 9 lines · Dave Chinner
This is just a couple of additional functions for
xfs_ioI have had sitting around for a while. The first is an interface tosync_file_range()for better control of file writeback. The second and third introduce vectored pread/pwrite so that I could simulate the same style of vectored IO that KVM does via direct IO (hint - tracing indicated that the generic direct IO code doesn't handle this particularly efficiently)._____________________________________________
This series has been committed to
git://oss.sgi.com/xfs/cmds/xfsprogs.git
-Mark.
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
Quoted 14 lines · Mark Tinguely
Quoted 9 lines · Dave Chinner
This is just a couple of additional functions for
xfs_ioI have had sitting around for a while. The first is an interface tosync_file_range()for better control of file writeback. The second and third introduce vectored pread/pwrite so that I could simulate the same style of vectored IO that KVM does via direct IO (hint - tracing indicated that the generic direct IO code doesn't handle this particularly efficiently)._____________________________________________
This series has been committed to
git://oss.sgi.com/xfs/cmds/xfsprogs.git
Quoted 7 lines
-Mark.
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
Looks like this might need some config-fu:
pread.o: In function `do_pread':
/src/git/xfsprogs/io/pread.c:198: undefined reference to preadv' /src/git/xfsprogs/io/pread.c:198: undefined reference to preadv' pwrite.o: In function `do_pwrite':
/src/git/xfsprogs/io/pwrite.c:85: undefined reference to pwritev' /src/git/xfsprogs/io/pwrite.c:85: undefined reference to pwritev' sync_file_range.o: In function `sync_range_f':
/src/git/xfsprogs/io/sync_file_range.c:87: undefined reference to `sync_file_range'
(on a Centos5 box)
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
Quoted 35 lines · Eric Sandeen
Quoted 14 lines · Mark Tinguely
Quoted 9 lines · Dave Chinner
This is just a couple of additional functions for
xfs_ioI have had sitting around for a while. The first is an interface tosync_file_range()for better control of file writeback. The second and third introduce vectored pread/pwrite so that I could simulate the same style of vectored IO that KVM does via direct IO (hint - tracing indicated that the generic direct IO code doesn't handle this particularly efficiently)._____________________________________________
This series has been committed to
git://oss.sgi.com/xfs/cmds/xfsprogs.gitQuoted 7 lines
-Mark.
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfsLooks like this might need some config-fu:
pread.o: In function `do_pread':
/src/git/xfsprogs/io/pread.c:198: undefined reference topreadv' /src/git/xfsprogs/io/pread.c:198: undefined reference topreadv' pwrite.o: In function `do_pwrite':
/src/git/xfsprogs/io/pwrite.c:85: undefined reference topwritev' /src/git/xfsprogs/io/pwrite.c:85: undefined reference topwritev' sync_file_range.o: In function `sync_range_f':
/src/git/xfsprogs/io/sync_file_range.c:87: undefined reference to `sync_file_range'
Quoted 1 line
(on a Centos5 box)
Thanks Eric, I will take a look at it.
--Mark.
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
Quoted 36 lines · Mark Tinguely
Quoted 35 lines · Eric Sandeen
Quoted 14 lines · Mark Tinguely
Quoted 9 lines · Dave Chinner
This is just a couple of additional functions for
xfs_ioI have had sitting around for a while. The first is an interface tosync_file_range()for better control of file writeback. The second and third introduce vectored pread/pwrite so that I could simulate the same style of vectored IO that KVM does via direct IO (hint - tracing indicated that the generic direct IO code doesn't handle this particularly efficiently)._____________________________________________
This series has been committed to
git://oss.sgi.com/xfs/cmds/xfsprogs.gitQuoted 7 lines
-Mark.
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfsLooks like this might need some config-fu:
pread.o: In function `do_pread':
/src/git/xfsprogs/io/pread.c:198: undefined reference topreadv' /src/git/xfsprogs/io/pread.c:198: undefined reference topreadv' pwrite.o: In function `do_pwrite':
/src/git/xfsprogs/io/pwrite.c:85: undefined reference topwritev' /src/git/xfsprogs/io/pwrite.c:85: undefined reference topwritev' sync_file_range.o: In function `sync_range_f':
/src/git/xfsprogs/io/sync_file_range.c:87: undefined reference to `sync_file_range'
Quoted 4 lines
Quoted 1 line
(on a Centos5 box)
Thanks Eric, I will take a look at it.
I actually started (sorry, should have just done it before sending the mail)
I'll take care of it, I'm halfway there.
-Eric
Quoted 2 lines
--Mark.
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
Quoted 40 lines · Eric Sandeen
Quoted 39 lines · Mark Tinguely
Quoted 36 lines · Eric Sandeen
Quoted 14 lines · Mark Tinguely
Quoted 9 lines · Dave Chinner
This is just a couple of additional functions for
xfs_ioI have had sitting around for a while. The first is an interface tosync_file_range()for better control of file writeback. The second and third introduce vectored pread/pwrite so that I could simulate the same style of vectored IO that KVM does via direct IO (hint - tracing indicated that the generic direct IO code doesn't handle this particularly efficiently)._____________________________________________
This series has been committed to
git://oss.sgi.com/xfs/cmds/xfsprogs.gitQuoted 7 lines
-Mark.
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfsLooks like this might need some config-fu:
pread.o: In function `do_pread':
/src/git/xfsprogs/io/pread.c:198: undefined reference topreadv' /src/git/xfsprogs/io/pread.c:198: undefined reference topreadv' pwrite.o: In function `do_pwrite':
/src/git/xfsprogs/io/pwrite.c:85: undefined reference topwritev' /src/git/xfsprogs/io/pwrite.c:85: undefined reference topwritev' sync_file_range.o: In function `sync_range_f':
/src/git/xfsprogs/io/sync_file_range.c:87: undefined reference to `sync_file_range'(on a Centos5 box)
Quoted 11 lines
Quoted 1 line
Thanks Eric, I will take a look at it.
I actually started (sorry, should have just done it before sending the mail)
I'll take care of it, I'm halfway there.
-Eric
Quoted 2 lines
--Mark.
Excellent. That is easy!
--Mark.
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs