I faced the first problem when I tried to implement the communication between an usual userspace process and the VFS server because I need to pass a lot of data between them when the process wants to read or write some kind of file, etc. At first I implemented my IPC messages with fixed size (6 * 8 bytes) to avoid queueing big message data inside the kernel. I thought that this problem can be solved with the help of creating a shared memory region per (to stick with the previous example) file descriptor. This region could be used to put the data there that should be written and vice versa. I started to worry about my design when I thought about what happens when multiple threads are trying to access the same file at the same time, the simple shared memory region will not be enough.

I have some ideas how to solve the issue but before trying to implement another method I would ask you for your opinions.
Idea #1: One shared memory region could be used per thread in the user application. This way it would not be a problem if multiple threads would like to write the same file at the same time. However this method requires a lot of support in the C (or whatever) library to maintain these informations. One more bottleneck that it still requires a copying when the data is put from the given user buffer into the shared region.
Idea #2: Extend the IPC messages to be able to contain any kind of data that will be cached by the kernel until the other end of the IPC link reads it. This seems to be the worst solution for me. It requires allocation of dynamic memory regions inside the kernel while I tried to avoid that.
Idea #3: Pass a pointer with a size to the ipc_send() function containing the memory location associated to the message from the sender process (e.g. the buffer to write into a file). Before receiving the message at the other end of the link the kernel maps the selected memory region to the address space of the other process. For now this seems to be the best solution I could think of however it still has some problem. I am worrying because the buffers passed to read() and write() are not page aligned in 99% of the cases. This means that the receiver process could access some of the sender's memory that is not even involved in the current operation.
What other options do I have to solve this problem?
