I was reading a blog post and noticed the following sentence:
Then he said something really surprising: that in the Seastar HTTP framework, they wrote their own TCP stack, and it made everything several times times faster. What?!
I'm trying to understand why kernel functionalities would be re-implemented in user-space for performance reasons. I would assume that features present in a kernel are in the kernel exactly because they execute (many) privileged instructions, because otherwise the feature could simply be implemented as a user-space program. So, if one were to re-implement kernel features or functionality in user-space, such as a network stack (this is what gVisor does with its netstack for example), would you not end up having to execute many system calls back into the kernel anyway, causing a lot of overhead?
Are such user-space re-implementations of features that are traditionally part of the kernel somehow able to avoid making many system calls? If so, how does that work for e.g. a network stack, since you would probably have to e.g.
recv() often, I can imagine.
I do understand that two potential advantages of re-implementing features in user-space are that:
- you are not dependent on what is added to the kernel (which seems to be an arduous process)
- if an exploit is found within a traditionally kernel feature re-implemented in user-space, it is 'only' an unprivileged user-space process anyway
But I am more interested in the performance aspect in this question.