0

Say, I have a huge file which I want to load into memory. Is it possible to use the DMA to quickly load the data from the file into the memory in Linux? If so, how?

MetallicPriest
  • 29,191
  • 52
  • 200
  • 356
  • What makes you think that *all* file reads aren't done via DMA? Do you mean you want to access HW directly rather than calling `mmap` or something along those lines? – Carl Norum Nov 26 '14 at 17:46
  • Does fread also uses DMA for copying large data? – MetallicPriest Nov 26 '14 at 17:50
  • 1
    Hard drive controllers, such as the built in SATA interface on a motherboard use a bus mastering controller which supports scatter / gather in order to work with virtual paged memory. The virtual memory is "locked", and the physical pages and lengths are programmed into an array of "descriptors". For large I/O with a single command, the "descriptors" may get reprogrammed during the I/O. – rcgldr Nov 26 '14 at 17:59
  • Your code interacts with the kernel using [syscalls(2)](http://man7.org/linux/man-pages/man2/syscalls.2.html). Use `strace` to find out which. So your question about `fread` using `DMA` does not have much sense: `fread` uses `read(2)` which is done by the kernel which might do DMA (*inside* the kernel). – Basile Starynkevitch Nov 26 '14 at 18:08
  • See [this](http://stackoverflow.com/q/8174338/841108) question, which is *almost* a duplicate (but phrased differently) – Basile Starynkevitch Nov 26 '14 at 18:10

1 Answers1

4

If DMA is available then the driver is probably already using it. If you want high-speed direct access to a file then use mmap(2) instead of second-guessing the OS.

Ignacio Vazquez-Abrams
  • 776,304
  • 153
  • 1,341
  • 1,358