89 points · by riyakhanna1983 · 7y ago · 32 comments
I wish such a fully-user-space option existed for Linux. This work is philosophically in the opposite direction, moving more functionality into kernel space for perf benefits.
[1]: https://fuchsia.dev/fuchsia-src/the-book/filesystems.md
Quoting: > Unlike more common monolithic kernels, Fuchsia’s filesystems live entirely within userspace. They are not linked nor loaded with the kernel; they are simply userspace processes which implement servers that can appear as filesystems
[1]: https://fuchsia.googlesource.com/fuchsia/+/master/zircon/sys...
A "server" is an IPC mechanism; this is describing a way for one userspace process to serve filesystems to other userspace processes.
It sounds like the kernel has no built-in notion of a "filesystem", and filesystems just take advantage of the kernel's generic IPC mechanism, which is also used by a lot of other things. That's great – but it's still true that IPC must go through the kernel, and switching from one user process (the client) to another (the server) is a context switch.
It may be that the code also supports locating the client and server within the same process – I have not looked at it. But that's not what the documentation describes, so it's at least not the main intended operating mode.
Note that there are ways to minimize the amount of time spent in privileged contexts. Shared memory can be used to pass data directly, but unless you want all your CPUs pegged at 100% utilization the kernel must be involved somehow to optimize IPC polling. In any event, the same strategies can be used for in-kernel VFS services, so it's not a useful distinction.
Also, if the point is that you want to expose the filesystem to other applications, but have it local to your own, then why not expose it through FUSE, even if it's in your own process?
And replacing it with expensive userspace<--->userspace switching.
But because the kernel is still doing the context switch between the processes, now you're doing userspace<-->kernel<--->userspace switching.
IMO, the ideal combo looks something like this FUSE/BPF work combined with XOK's capability based buffer cache rather than trying to split everything out into user mode.
So-called safe languages don't help, either, because the whole purpose of doing this in a monolithic, shared memory context is precisely because it's easier to move fast and break things in terms of unsafe optimizations (e.g. circular, direct pointer references) unburdened by careful, formal constraints. If written in Rust every other line of Linux code would be wrapped in unsafe{}. Most of the parts that needn't be would be better moved into user space, anyhow.
tl;dr: perform metadata caching in the kernel using eBPF, avoiding context switches for common operations like listdir() and getattr(), and reduce FUSE overhead from ~18% to ~6%.
In principle, any resource available to a FUSE implementation can be exported as a file system.