Mapping Kernel memory to user space - Linux

This is a discussion on Mapping Kernel memory to user space - Linux ; Hi, Can anyone help me on mapping a page of kernel memory (allocated using get_free_page() ) to user space? Actually the scenario is that i'm copying data from the device and holding it in a kernel memory (ring buffer) temporarily ...

+ Reply to Thread
Results 1 to 4 of 4

Thread: Mapping Kernel memory to user space

  1. Mapping Kernel memory to user space

    Hi,
    Can anyone help me on mapping a page of kernel memory
    (allocated using get_free_page() ) to user space?

    Actually the scenario is that i'm copying data from the device and
    holding it in a kernel memory (ring buffer) temporarily before i copy
    it to the user space buffer. This approach has a lot of over-head.

    Was wondering it would be efficient to map this buffer to user space
    application so that the application can read from this buffer
    and write the data to the file system..

    Please guide me through this :-)

    Thanks in advance
    MAx


  2. Re: Mapping Kernel memory to user space

    On Jan 3, 2:19 pm, MAx wrote:
    > Hi,
    > Can anyone help me on mapping a page of kernel memory
    > (allocated using get_free_page() ) to user space?
    >
    > Actually the scenario is that i'm copying data from the device and
    > holding it in a kernel memory (ring buffer) temporarily before i copy
    > it to the user space buffer. This approach has a lot of over-head.
    >
    > Was wondering it would be efficient to map this buffer to user space
    > application so that the application can read from this buffer
    > and write the data to the file system..
    >
    > Please guide me through this :-)
    >
    > Thanks in advance
    > MAx


    Why you want a userspace application to write to file system why can't
    just kernel write it to filesystem. Why should data come to user space?

  3. Re: Mapping Kernel memory to user space

    On Jan 3, 8:19 pm, MAx wrote:
    > Hi,
    > Can anyone help me on mapping a page of kernel memory
    > (allocated using get_free_page() ) to user space?
    >
    > Actually the scenario is that i'm copying data from the device and
    > holding it in a kernel memory (ring buffer) temporarily before i copy
    > it to the user space buffer. This approach has a lot of over-head.
    >
    > Was wondering it would be efficient to map this buffer to user space
    > application so that the application can read from this buffer
    > and write the data to the file system..
    >
    > Please guide me through this :-)
    >
    > Thanks in advance
    > MAx


    One way to do this is to have an IOCTL type call to your kernel module
    to get the physical memory address of the kernel allocated memory and
    then using that with "mmap" in your userspace app to map that memory
    to a virtual address.

    An example of Mmap can be found at
    "http://groups.google.com.au/group/comp.os.linux.embedded/browse_frm/
    thread/90e28d1de306839f/c66a9ead21f7cd19?
    hl=en&lnk=st&q=#c66a9ead21f7cd19"
    or do a search of this mailing list for "Writing to a device at a
    known physical address"

  4. Re: Mapping Kernel memory to user space

    There is a kernel to user space relay mechanism in 2.6. I havent
    explored it yet, you might want to google for it and see if there is a
    good mechanism available. You can see this in the .config (it must be
    enabled for you to use this feature). Netlink sockets is another
    approach (but its obsolete i believe so dont use it if you want this
    code to live longer, but for test app, it can be good. Another way is
    to write the data to shared mem and notify the userspace app to read
    it from that address.
    Other approach is mmap that address to user space. But note, the mmap
    call isnt portable. So - please choose as per your requirements.

    Cheers
    /Ramesh

    On Jan 3, 1:19 am, MAx wrote:
    > Hi,
    > Can anyone help me on mapping a page of kernel memory
    > (allocated using get_free_page() ) to user space?
    >
    > Actually the scenario is that i'm copying data from the device and
    > holding it in a kernel memory (ring buffer) temporarily before i copy
    > it to the user space buffer. This approach has a lot of over-head.
    >
    > Was wondering it would be efficient to map this buffer to user space
    > application so that the application can read from this buffer
    > and write the data to the file system..
    >
    > Please guide me through this :-)
    >
    > Thanks in advance
    > MAx



+ Reply to Thread