4

I've heard that FUSE-based filesystems are notoriously slow because they are implemented in a userspace program. What is it about userspace that is slower than the kernel?

2
  • 3
    It's not the userspace is slower than kernel space, it's that switching between the two is time-consuming, I'll let someone else write up a full answer though.
    – derobert
    Dec 20, 2014 at 16:42
  • And not just slow - unreliable. They are almost all ultimately just abstractions atop a real filesystem at some point, anyway. Only where the real filesystem's threads are shored up safely in VFS, FUSE processes are as vulnerable to failure and killing as any other userspace process - and all the while they're passing your valuable data around trying to get it where you should have put it in the first place - in a filesystem.
    – mikeserv
    Dec 20, 2014 at 17:38

2 Answers 2

5

Code executes at the same speed whether it's in the kernel or in user land, but there are things that the kernel code can do directly while user land code has to jump through hoops. In particular, kernel code can map application memory directly, so it can directly copy the file contents between the application memory and the internal buffers from or to which the hardware copies. User code has to either make an extra copy via a pipe or socket, or make a more complex memory sharing operation.

Furthermore each file operation has to go through the kernel — the only way for a process to interact with anything is via a system call. If the file operation is performed entirely inside the kernel, there's only one user/kernel transition and one kernel/user transition to perform, which is pretty fast. If the file operation is performed by another process, there has to be a context switch between processes, which requires a far more expensive operation in the MMU.

The speed performance is still negligible against most hardware access times, but it can be observed when the hardware isn't the bottleneck, especially as many hardware operations can be performed asynchronously while the main processor is doing something else, whereas context switches and data copies between processes keep the CPU busy.

1

Very simplified:

Your application wants to read a file

Application asks kernel, kernel access filesystem (in kernel space ) checks permissions, handles file descriptor to application.

With user space filesystems you have a lot more relatively slow kernel-to-userspace switches:

Application asks kernel to open file, kernel calls userspace filesystem, userspace fs calls kernel for disk access, userspace fs sends data to kernel, kernel hands data over to userspace application.

With userspace filesystems, you have a lot more context switches.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .