Optimize pattern filling by limiting small calls to memcpy
authorSteven Lang <tirea@google.com>
Thu, 2 Feb 2012 19:22:04 +0000 (20:22 +0100)
committerJens Axboe <axboe@kernel.dk>
Thu, 2 Feb 2012 19:22:04 +0000 (20:22 +0100)
In looking at profiling the speed of fill_pattern(), it calls memcpy()
for the fill pattern repeatedly for multibyte patterns.  So for a 4
byte pattern with 8k IO, it calls memcpy() 2048 times.

Since there is already 512 bytes reserved for the pattern, I figured a
simple solution was to use it.  This patch replicates short patterns
so they can be more efficiently copied.  (Single byte patterns are
left alone since they can make use of the much more efficient memset()
call.)

The result is a 10x performance improvement on pattern filling. (With
this patch, it's still 3x slower than when it re-uses the already
filled pattern.)

Signed-off-by: Jens Axboe <axboe@kernel.dk>
options.c

index f62ab6d573cd3369cbeced32edec4a4fe4c666d4..8fb93ca7a0c2c6a331a75e5250c86f0d9e37e156 100644 (file)
--- a/options.c
+++ b/options.c
@@ -689,12 +689,24 @@ static int str_verify_pattern_cb(void *data, const char *input)
                        }
                }
        }
+
+       /*
+        * Fill the pattern all the way to the end. This greatly reduces
+        * the number of memcpy's we have to do when verifying the IO.
+        */
+       while (i > 1 && i * 2 <= MAX_PATTERN_SIZE) {
+               memcpy(&td->o.verify_pattern[i], &td->o.verify_pattern[0], i);
+               i *= 2;
+       }
+
        td->o.verify_pattern_bytes = i;
+
        /*
         * VERIFY_META could already be set
         */
        if (td->o.verify == VERIFY_NONE)
                td->o.verify = VERIFY_PATTERN;
+
        return 0;
 }