Hello,

Elphel cameras have video buffer which is allocated in CMA system memory
using consistent DMA mapping. I want to implement streaming write from this
buffer to a block device. An application opens video buffer with mmap and I
would like to use O_DIRECT write to avoid page cache related overhead.
Basically, the pseudo-code of the application looks like this:

    f_in = open("/dev/videobuf", O_RDONLY);
    f_mmap = mmap(0, BUFFER_SIZE, PROT_READ, MAP_SHARED, f_in, 0);
    f_out = open("/dev/sda", O_WRONLY | O_DIRECT);
    write(f_out, f_mmap, BLOCK_SIZE);

where BLOCK_SIZE is sector aligned value. f_out is opened without any
errors, but write results in EFAULT. I tried to find out the reason for
this error and it turned out that mmap implementation in video buffer's
driver uses remap_pfn_range(), which sets VM_IO and VM_PFNMAP flags for
VMA. The O_DIRECT path in block device drivers checks these flags and
returns EFAULT. As far as I understand (from reading comments to VMA
flags), O_DIRECT writes need to pin the memory pages, but VMA flags set
prevent this which causes an error.

So the question is how to correctly map buffers in CMA area into user space
so that they can be used for O_DIRECT write to a disk?

Regards,
Mikhail
_______________________________________________
Support-list mailing list
Support-list@support.elphel.com
http://support.elphel.com/mailman/listinfo/support-list_support.elphel.com

Reply via email to