Using DMA Memory Transfer in User-Space

Yeraze picture Yeraze · May 10, 2014 · Viewed 7.3k times · Source

Is there a linux DMA mem-to-mem copy mechanism available to userspace?

I have a linux application that routinely (50-100 times a second) has to memcpy several megs (10+) of data around. Often it's not an issue, but we've begun to see evidence that it may be consuming too much of our CPU bandwidth. Current measurements put it at something like 1Gbytes/s we're moving around.

I'm aware of the dma capability in the kernel, and I see a bit of documentation talking about building custom drivers for large memory copies, for this very reason.. But it seems someone would have build a generic API for this by now. Am I wrong? Is DMA a kernel-only feature?

I should clarify, this is for Intel X86 architecture, not embedded.

Answer

Grapsus picture Grapsus · May 10, 2014
  • Linux's API for DMA doesn't permit memory to memory transfers. It's only for communication between devices and memory. Look in Documentation/DMA-API.txt for more details.

  • At hardware level, the x86 DMA controller doesn't allow memory to memory transfers. It's been discussed here: DMA transfer RAM-to-RAM

  • Given that the memory bus is usually slower than the CPU, what benefit would it have to launch a kernel driven memory copy ? You'd still have to wait for the transfer to finish and its duration would still be the determined by the memory bandwidth, exactly as with a CPU driven copy.

  • If your program's performance solely depends on memory to memory copy performance, it means that it can be probably be strongly improved by avoiding copy as much as possible, or by implementing a smarter procedure such as copy on write.