AnsweredAssumed Answered

OpenCL mmap vs malloc, different data transfer speed using clEnqueueWriteBuffer on LINUX platform.

Question asked by zhangjingtian on Aug 7, 2013


     Here is the situation:

     kernel  side:

     1.we alloc a big area of physical memory when linux start up using alloc_boot_mem

     2.we write a simple char device driver implementing the mmap function in the file_operations struct to map the physical memory to user space.

     user space side:

     1.we open the char device and then using the mmap api to get the virtual address of the physical memory we alloced in kernel space.

     2.we alloc a same size of virtual memory using malloc.

     the test:

     we used the opencl api clEnqueueWriteBuffer to transfer these two memory area to the device, but it showed a different transfer speed, if we transfer the malloc memory firstly and  then transfer

     the mmap memory area secondly, the transfer speeds were 1.5GB/S vs 500MB/s. if we transfer the mmap memory firstly and then transfer the malloc memory area secondly, the transfer speeds

     were 700MB/s vs 900MB/s.

     Any one can tell me why? And how can i to make the mmap memory transfer speed the same as the malloc memory.


    Here is the mmap function we implemented in the char device driver:


    int my_mmap(struct file *filp, struct vm_area_struct *vma)


    vma->vm_flags |= VM_RESERVED | VM_IO;

    if(remap_pfn_range(vma, vma->vm_start, virt_to_phys((void *)my_boot_mem)>>PAGE_SHIFT,

       boot_mem_size, vma->vm_page_prot))


        return -EAGAIN;



    return 0;