* [PATCH] Optimize pattern filling by limiting small calls to memcpy.
@ 2012-02-02 1:39 Steven Lang
2012-02-02 8:48 ` Jens Axboe
0 siblings, 1 reply; 4+ messages in thread
From: Steven Lang @ 2012-02-02 1:39 UTC (permalink / raw)
To: fio
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.)
---
options.c | 4 ++++
1 files changed, 4 insertions(+), 0 deletions(-)
diff --git a/options.c b/options.c
index f9bd1a4..b6989d4 100644
--- a/options.c
+++ b/options.c
@@ -689,6 +689,10 @@ static int str_verify_pattern_cb(void *data,
const char *input)
}
}
}
+ 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
--
1.7.7.3
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH] Optimize pattern filling by limiting small calls to memcpy.
2012-02-02 1:39 [PATCH] Optimize pattern filling by limiting small calls to memcpy Steven Lang
@ 2012-02-02 8:48 ` Jens Axboe
2012-02-02 19:11 ` Steven Lang
0 siblings, 1 reply; 4+ messages in thread
From: Jens Axboe @ 2012-02-02 8:48 UTC (permalink / raw)
To: Steven Lang; +Cc: fio
On 02/02/2012 02:39 AM, Steven Lang wrote:
> 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.)
>
> ---
> options.c | 4 ++++
> 1 files changed, 4 insertions(+), 0 deletions(-)
>
> diff --git a/options.c b/options.c
> index f9bd1a4..b6989d4 100644
> --- a/options.c
> +++ b/options.c
> @@ -689,6 +689,10 @@ static int str_verify_pattern_cb(void *data,
> const char *input)
> }
> }
> }
> + 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
Looks like you are missing the interesting part of this patch :-)
But the idea definitely sounds good.
--
Jens Axboe
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH] Optimize pattern filling by limiting small calls to memcpy.
2012-02-02 8:48 ` Jens Axboe
@ 2012-02-02 19:11 ` Steven Lang
2012-02-02 19:20 ` Jens Axboe
0 siblings, 1 reply; 4+ messages in thread
From: Steven Lang @ 2012-02-02 19:11 UTC (permalink / raw)
To: Jens Axboe; +Cc: fio@vger.kernel.org
No, that's actually all of it; it's really that simple. It just takes
the pattern buffer, and replicates it until it it is at least half
full, which during verification drastically reduces the number of
calls to memcpy() for short multibyte patterns.
On Thu, Feb 2, 2012 at 12:48 AM, Jens Axboe <jaxboe@fusionio.com> wrote:
> On 02/02/2012 02:39 AM, Steven Lang wrote:
>> 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.)
>>
>> ---
>> options.c | 4 ++++
>> 1 files changed, 4 insertions(+), 0 deletions(-)
>>
>> diff --git a/options.c b/options.c
>> index f9bd1a4..b6989d4 100644
>> --- a/options.c
>> +++ b/options.c
>> @@ -689,6 +689,10 @@ static int str_verify_pattern_cb(void *data,
>> const char *input)
>> }
>> }
>> }
>> + 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
>
> Looks like you are missing the interesting part of this patch :-)
> But the idea definitely sounds good.
>
> --
> Jens Axboe
>
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH] Optimize pattern filling by limiting small calls to memcpy.
2012-02-02 19:11 ` Steven Lang
@ 2012-02-02 19:20 ` Jens Axboe
0 siblings, 0 replies; 4+ messages in thread
From: Jens Axboe @ 2012-02-02 19:20 UTC (permalink / raw)
To: Steven Lang; +Cc: fio@vger.kernel.org
On 2012-02-02 20:11, Steven Lang wrote:
> No, that's actually all of it; it's really that simple. It just takes
> the pattern buffer, and replicates it until it it is at least half
> full, which during verification drastically reduces the number of
> calls to memcpy() for short multibyte patterns.
Ah gotcha, I see what you mean now, what I missed was the assignment of
td->o.verify_pattern_bytes _after_ the extra fill on option init. Looks
good! I'll apply it.
--
Jens Axboe
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2012-02-02 19:20 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-02-02 1:39 [PATCH] Optimize pattern filling by limiting small calls to memcpy Steven Lang
2012-02-02 8:48 ` Jens Axboe
2012-02-02 19:11 ` Steven Lang
2012-02-02 19:20 ` Jens Axboe
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox