public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* Does pci_alloc_consisent really need to zero memory?
@ 2002-05-30  9:11 Adam J. Richter
  2002-05-30  9:49 ` David S. Miller
  0 siblings, 1 reply; 7+ messages in thread
From: Adam J. Richter @ 2002-05-30  9:11 UTC (permalink / raw)
  To: linux-kernel

	Is it really necessary for pci_alloc_consistent() to
fill the memory that it returns with all zeroes?  I don't
see anything in Documentation/DMA-mapping.txt that specifies
it.  I have been on the lookout for drivers that rely on it
for the past couple of months, and I haven't seen any.  It's
only one line of code in arch/i386/kernel/pci-dma.c, but it
is potentially a lot of cycles, even if only zeroes the
space you requested (rather than the full pages that it
actually allocates).

	If nobody objects in the next half day or so (or asks
me to follow some other course of action), I'll submit a patch for
2.5 for all architectures.

Adam J. Richter     __     ______________   575 Oroville Road
adam@yggdrasil.com     \ /                  Milpitas, California 95035
+1 408 309-6081         | g g d r a s i l   United States of America
                         "Free Software For The Rest Of Us."

^ permalink raw reply	[flat|nested] 7+ messages in thread
* Re: Does pci_alloc_consisent really need to zero memory?
@ 2002-05-30 11:41 Adam J. Richter
  2002-05-30 11:30 ` David S. Miller
  2002-06-03 16:45 ` Pavel Machek
  0 siblings, 2 replies; 7+ messages in thread
From: Adam J. Richter @ 2002-05-30 11:41 UTC (permalink / raw)
  To: davem; +Cc: linux-kernel

Dave S. Miller writes:
>pci_alloc_consistent is so rare, I doubt it [clearing the memory it
>returns] matters performance wise.

	In my efforts to port almost all of the scsi drivers to your
DMA-mapping interface, I have converted some kmalloc's that
are frequently called with pci_alloc_consistent (I have not
submitted these changes, because I think there is an unrelated
bug in my changes).  Come to think of it, you advised me to go
that route, as opposed to using pci_map_single(), when I asked about
it with respect to advansys.c.  I'd like to have as little
performance penalty for this as possible.  That also makes it
marginally easier to encourge movement to your DMA-mapping interface.

	While it is normally good programming practice for
routines to always return deterministic results (same initial
values in memory), I think that in a performance-oriented
software component like the kernel, it's better programming practice
to have primitives that do no more than they need to, that run as
fast as possible, and behave consistently (no other remaining memory
allocators in linux-2.5 do this, right?).

	Also as a general practice, I especially would like to
be paranoid about unnecessary memory copying or filling.  I like
to grep for memcpy's and memset's and ask "is this call really
necessary?" Core CPU speed improvements have out pace memory bus
improvements.  Today, a 2GHz CPU and with a 2GB/sec memory channel
(typical new computer) can only sustain clearing 1 byte per CPU
cycle (although much of that can accumulate in a write-behind
cache, but then you've just flushed a lot of your cache
unnecessarily, and that generates some memory traffic, etc.).
Plus, CPU's often execute more than one instruction per cycle,
so each byte might burn the time in which 1.4 instructions
could be executed, and other devices may want that memory
bandwidth too (I/O devices, another CPU, built-in video).

	Maybe if you could point out an example of some
code that actually depends on pci_alloc_consistent return
zeroes, I be able to see what I missed and be able to
track down similar cases.  There are plenty of drivers
that do pci_alloc_consistent and then memset.  So, whichever
way the semantics of pci_alloc_consistent are defined, some
drivers ought to be modified.

Adam J. Richter     __     ______________   575 Oroville Road
adam@yggdrasil.com     \ /                  Milpitas, California 95035
+1 408 309-6081         | g g d r a s i l   United States of America
                         "Free Software For The Rest Of Us."

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2002-06-03 19:05 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-05-30  9:11 Does pci_alloc_consisent really need to zero memory? Adam J. Richter
2002-05-30  9:49 ` David S. Miller
2002-05-30 11:05   ` Emmanuel Michon
2002-05-30 10:54     ` David S. Miller
  -- strict thread matches above, loose matches on Subject: below --
2002-05-30 11:41 Adam J. Richter
2002-05-30 11:30 ` David S. Miller
2002-06-03 16:45 ` Pavel Machek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox