Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the ideal & fastest way to communicate between kernel and user space?

I know that information exchange can happen via following interfaces between kernel and user space programs

  • system calls

  • ioctls

  • /proc & /sys

  • netlink

I want to find out

  • If I have missed any other interface?

  • Which one of them is the fastest way to exchange large amounts of data? (and if there is any document/mail/explanation supporting such a claim that I can refer to)

  • Which one is the recommended way to communicate? (I think its netlink, but still would love to hear opinions)

like image 480
Methos Avatar asked Jun 02 '09 22:06

Methos


1 Answers

The fastest way to exchange vast amount of data is memory mapping. The mmap call can be used on a device file, and the corresponding kernel driver can then decide to map kernel memory to user address space. A good example of this is the Video For Linux drivers, and I suppose the frame buffer driver works the same way. For an good explanation of how the V4L2 driver works, you have :

  • The lwn.net article about streaming I/O
  • The V4L2 spec itself

You can't beat memory mapping for large amount of data, because there is no memcopy like operation involved, the physical underlying memory is effectively shared between kernel and userspace. Of course, like in all shared memory mechanism, you have to provide some synchronisation so that kernel and userspace don't think they have ownership at the same time.

like image 95
shodanex Avatar answered Sep 28 '22 01:09

shodanex