2

Right, so I'm trying to optimize a software that needs to read a huge image file (1.3 GB) in C/OpenCL in order to transfer it to the device by 40 MB blocks.

I created a RAMDISK with tmpfs to store the file but when I analyze bitrates I find that using a RAMDISK is actually a bit slower than using my SSD to read the image file.

So I'm wondering, does the open operation (using fopen) do a RAM-to-RAM transfer to store data in the buffer ? Or is it the filesystem's overhead that causes this performance issue ?

Marc
  • 61
  • 1
  • 7
  • If I understand correctly tmpfs may use swap space. This may be slowing something down. – Philip Couling May 21 '15 at 12:46
  • I have the same bitrates using a ramfs file system that can't use swap. – Marc May 21 '15 at 12:56
  • 1
    Use of `fopen()/fread()` results in the data being copied three times on its way to your code's buffers: disk->page cache->FILE buffer->code buffer. If you're doing a pure streaming read, that's useless. Just use `open()/read()` and use direct IO. (O_DIRECT `open()` flag on Linux.) Also be sure to `memset()` your buffer before you read into it as it may not have a physical page yet. – Andrew Henle May 21 '15 at 13:16
  • So I tried what you proposed : `int input = open(argv[1], O_RDONLY|O_DIRECT);` But `open()` keeps returning -1, even if I specify a mode like 0777. – Marc May 21 '15 at 14:14
  • 1
    Check `errno` for the real error. `O_DIRECT` is not guaranteed to be supported. – Colonel Thirty Two May 21 '15 at 14:27
  • Actually, `O_DIRECT` with a file on my ext4 partition works but it's not available on a tmpfs/ramfs file system. Or at least by default ? Is there a way to make that work ? – Marc May 21 '15 at 14:55

0 Answers0