Large shared memory between kernel space and user space

I am working on a research project and I have to share a large data structure between the kernel module and user space program. The data structure can be very large, and since the application is critical, I tried using shared memory to reduce the overhead of serializing the structure (using other interfaces, such as NetLink). Currently, I have made test code based on this link:

[ http://people.ee.ethz.ch/~arkeller/linux/kernel_user_space_howto.html#s8†[1]

They use debugfs. I added the code to the link in my kernel module, and I wrote a custom space program similar to them. I tried this with the small size of my file structure, which worked fine. You may notice in the code that they use only one page of memory. I wanted to know if there is an easy way to share much more memory than one page.

+8
c linux shared-memory linux-kernel kernel
source share
1 answer

Actually there are not many different pages.

Select more pages in the open (alloc_pages or option), save them in an array, then your error handler should (based on the error address):

  • calculate the offset to a region with something like "((((Unsigned long) vmf-> virtual_address - vma-> vm_start) + (vma-> vm_pgoff <PAGE_SHIFT))"
  • divided by PAGE_SIZE to calculate the page index in the array
  • check the range to make sure it is valid.
  • pull struct page * from array
  • call get_page to perform the mapping

You can continue to use debugfs or, with a little extra work in the module initialization, put more of the standard personal device interface on it. (For this, nothing needs to be changed outside the module_init / module_exit parts.)

+6
source share

All Articles