This is all in Linux and C.
I have a user space library function that will need to call a device driver's read/write function up to 8 times. (I am writing the library and device driver.) I see two ways of achieving this:
- Have the library call read/write the needed number of times.
- Have the driver handle reading/writing to the device the needed number of times.
The driver would already know the needed number of times based on a previous ioctl call that will happen regardless. Option 1 requires more switching between user space and kernel space which I know reduces performance. On the other hand, option 2 creates issues. For a read call, the buffer passed back to user space would be up to 8 times larger unless it's possible to pass 1 read at a time back to user space without switching between the two modes. A write call would also have the same issue unless the same data is to be written each time. So worst case for option 2 requires a buffer 8 times larger being passed back and forth as opposed to option 1.
Ultimately, which one is more efficient?
readv(2)/writev(2)
system calls. It doesn't help reduce the total memory usage, but in some situations it can help reduce the number of times the data is copied in memory, which helps improve cache performance. – Adam Rosenfield