* memset (was: Redundant memset in AIO read_events)
@ 2003-07-10 10:04 Etienne Lorrain
2003-07-10 10:19 ` Arjan van de Ven
0 siblings, 1 reply; 4+ messages in thread
From: Etienne Lorrain @ 2003-07-10 10:04 UTC (permalink / raw)
To: linux-kernel
Note that using memset() is better reserved to initialise variable-size
structures or buffers. Even if memset() is extremely optimised,
it is still not as fast as not doing anything.
read_events(...) {
struct io_event ent;
memset(&ent, 0, sizeof(ent));
while (...) {
aio_read_evt(ctx, &ent);
}
...
}
Should be written (when "ent" has to be cleared):
read_events(...) {
struct io_event ent = {};
while (...) {
aio_read_evt(ctx, &ent);
}
...
}
Just compare the code generated by (using GCC):
struct io_event ent;
memset(&ent, 0, sizeof(ent));
ent.data = 0;
if (ent.obj != 0) printf ("bad");
And:
struct io_event ent = {};
ent.data = 0;
if (ent.obj != 0) printf ("bad");
and that is even without speaking of complete variable elimination
when the structure is not used, unknown pointer alignement when
memset function is not inlined, or aliasing optimisation.
Etienne.
___________________________________________________________
Do You Yahoo!? -- Une adresse @yahoo.fr gratuite et en français !
Yahoo! Mail : http://fr.mail.yahoo.com
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: memset (was: Redundant memset in AIO read_events)
2003-07-10 10:04 Etienne Lorrain
@ 2003-07-10 10:19 ` Arjan van de Ven
0 siblings, 0 replies; 4+ messages in thread
From: Arjan van de Ven @ 2003-07-10 10:19 UTC (permalink / raw)
To: Etienne Lorrain; +Cc: linux-kernel
[-- Attachment #1: Type: text/plain, Size: 629 bytes --]
On Thu, 2003-07-10 at 12:04, Etienne Lorrain wrote:
> Note that using memset() is better reserved to initialise variable-size
> structures or buffers. Even if memset() is extremely optimised,
> it is still not as fast as not doing anything.
this is not always true....
memset can be used as an optimized cache-warmup, which can avoid the
write-allocate behavior of normal writes, which means that if you memset
a structure first and then fill it, it can be halve the memory bandwidth
and thus half as fast. This assumes an optimized memset which we
*currently* don't have I think... but well, we can fix that ;)
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 189 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: memset (was: Redundant memset in AIO read_events)
[not found] ` <1057832361.5817.2.camel@laptop.fenrus.com.suse.lists.linux.kernel>
@ 2003-07-10 10:29 ` Andi Kleen
2003-07-10 10:33 ` Arjan van de Ven
0 siblings, 1 reply; 4+ messages in thread
From: Andi Kleen @ 2003-07-10 10:29 UTC (permalink / raw)
To: Arjan van de Ven; +Cc: linux-kernel
Arjan van de Ven <arjanv@redhat.com> writes:
> On Thu, 2003-07-10 at 12:04, Etienne Lorrain wrote:
> > Note that using memset() is better reserved to initialise variable-size
> > structures or buffers. Even if memset() is extremely optimised,
> > it is still not as fast as not doing anything.
>
> this is not always true....
> memset can be used as an optimized cache-warmup, which can avoid the
> write-allocate behavior of normal writes, which means that if you memset
> a structure first and then fill it, it can be halve the memory bandwidth
> and thus half as fast. This assumes an optimized memset which we
> *currently* don't have I think... but well, we can fix that ;)
You don't want to use such an memset unlike you're clearing areas
which are significantly bigger than all your cache (>several MB)
The problem is that the instruction that avoid write-allocate usually also force
the result out of cache. And for small data sets that is typically a loss
if you want to use the data later, because the later use eats full cache misses.
In the kernel such big buffers occur only very rarely, most operations are on
4K and less. For those only in cache operation is interesting.
-Andi
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: memset (was: Redundant memset in AIO read_events)
2003-07-10 10:29 ` memset (was: Redundant memset in AIO read_events) Andi Kleen
@ 2003-07-10 10:33 ` Arjan van de Ven
0 siblings, 0 replies; 4+ messages in thread
From: Arjan van de Ven @ 2003-07-10 10:33 UTC (permalink / raw)
To: Andi Kleen; +Cc: Arjan van de Ven, linux-kernel
On Thu, Jul 10, 2003 at 12:29:10PM +0200, Andi Kleen wrote:
> The problem is that the instruction that avoid write-allocate usually also force
> the result out of cache.
that's for the current implementation; rep stosl may get the WA-avoiding
behavior sometime without the negative cache effects.. someday maybe.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2003-07-10 10:18 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20030710100417.83333.qmail@web11801.mail.yahoo.com.suse.lists.linux.kernel>
[not found] ` <1057832361.5817.2.camel@laptop.fenrus.com.suse.lists.linux.kernel>
2003-07-10 10:29 ` memset (was: Redundant memset in AIO read_events) Andi Kleen
2003-07-10 10:33 ` Arjan van de Ven
2003-07-10 10:04 Etienne Lorrain
2003-07-10 10:19 ` Arjan van de Ven
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox