suhas hv
suhas hv

Reputation: 21

Is it necessary to copy data from user space to the kernel before transfering it to an external device?

I have a device driver which provides the implementation for read, write and and some other file operations. For transfers, say, from the host to the external device, it is recommended to copy the user space data to kernel space before transferring it out to the device because the page containing the user space data maybe swapped out during the transfer. However this seems to be a major overhead. Is there a possibility to directly transfer user space data to the device using the driver without the intermediate copy to a kernel pointer? Of course this would need the prevention of a possible swap out of the corresponding page(s). A similar question also holds for transfers from the device to user space.

Upvotes: 1

Views: 490

Answers (1)

Rachid K.
Rachid K.

Reputation: 5211

You need to send data to the device driver. Where the source data comes from? If it comes from a file, you can use sendfile from a user application program: it opens the file of source data (file descriptor fd1), it opens the destination driver (file descriptor fd2) and it sends the data from fd1 to fd2 calling sendfile(). Here is a small article presenting this system call with a tool called odd, an enhanced version of dd tool.

Upvotes: 2

Related Questions