Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zero-Copy IPC #19

Open
nuta opened this issue Jul 31, 2020 · 5 comments
Open

Zero-Copy IPC #19

nuta opened this issue Jul 31, 2020 · 5 comments

Comments

@nuta
Copy link
Owner

nuta commented Jul 31, 2020

Currently, Resea requires at least two message copies even in the IPC fast path and what's worse, out-of-line payloads (analogous to the pair of buf and len in UNIX's read(2)) involves additional IPC with the pager task and the buffer copy. (Please note that this design decision is for making the microkernel simple as much as possible).

As the kernel allows the pager task to map memory pages, I'm wondering if we could implement a zero-copy IPC using the map system call and the notifications, a asynchronous IPC mechanism like UNIX's signals.

This issue tracks ideas and the progress of this feature.

@nuta
Copy link
Owner Author

nuta commented Jul 31, 2020

Requirements

  • No memory copies (obviously).

  • No additional kernel support: keep it simple!

  • Seamless integration with the current IPC: transparently switch to zero-copy IPC if possible.

  • No complicated algorithms: never bother with buggy IPC.

  • Protect mission-critical server from attacks from malicious clients.

Ideas

  • Survey zero-copy message passing implementations
  • Survey wait-free algorithms
  • FlatBuffers integration
  • Rewrite the existing async IPC library on top of zero-copy IPC
  • Implement an async runtime for Rust
  • Zero-copy message relaying (e.g. NIC driver -> TCP/IP Server -> Application) while it sounds impossible to me...

@arpitvaghela
Copy link
Contributor

Hey @nuta, I am classmate of @yashrajkakkad and have looked into the issue,

I believe this is the procedure for implementing Zero-Copy IPC

  1. handle flags
  2. prevent src from accessing *m (lock *m)
  3. check if dst is not blocked
  4. map *m to dst
  5. on done notification from dst
  6. unlock *m

However, I am unsure on how locking and unlocking can be performed. Also, How will Done notification be conveyed by dst?

@nuta
Copy link
Owner Author

nuta commented Oct 30, 2020

Hi @arpitvaghela. Here's my comments and suggestions:

First, you don't need to consider the compatibility with the existing IPC APIs. It is hard to use zero-copy IPC transparently from the current IPC APIs (e.g. ipc_call(server, &m)) because we need at least one message copy since the message buffer &m tends to be in the stack. Therefore, please try adding new APIs for zero-copy iPC along with the current IPC APIs.

The kernel cannot map a page by itself because it does not know which physical memory pages are available for a page table structures. In other words, the kernel does not have a memory allocator by design. Mapping a page every time a message is sent would degrade the performance.

I suggest mapping pages between tasks only once at the initialization (i.e. create a shared memory) and utilize lock-free algorithms and the notify system call (or another new system call if you need more features).

Because I'm not familiar with such algorithms, your suggestions are very welcome :)

JFYI, memory page mapping is done in vm server. It calls sys_map multiple times because the kernel needs multiple memory pages (kpage) for multi-level page table structures.

@arpitvaghela
Copy link
Contributor

arpitvaghela commented Nov 2, 2020

@nuta, can we implement POSIX shared memory ( similar to shm in linux ) ? However, it will require few more support from the kernel.

@nuta
Copy link
Owner Author

nuta commented Nov 4, 2020

Yes, we can implement such a feature in vm server.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants