Skip to content
systemcoding.dev
Kernels

FUSE vs Kernel Filesystem: When to Write Each

Choose between a FUSE daemon and an in-kernel filesystem by weighing crash safety, speed, tooling and boot needs, with a decision table and a libfuse sketch.

6 min read
Summarize in AI
Flat illustration of user space above the system call boundary, the kernel and the hardware, with the Linux, C and GNU logos.

Most filesystem ideas should never touch kernel code. A bug in a FUSE daemon kills that daemon and leaves the machine running, while the same bug in a kernel module can corrupt memory and panic the box. Yet there are cases where only an in-kernel filesystem will do, and picking wrong costs months. This post compares the two approaches on the questions that decide it, gives a decision table, and shows how small a FUSE filesystem can be. It targets Linux 6.12 and libfuse 3.16, and it stays on mechanisms rather than benchmark numbers, since no honest figure transfers between workloads.

What each approach is

FUSE (Filesystem in Userspace) is a kernel module plus a protocol. The kernel's fuse driver registers a filesystem type, and when a program touches a file under a FUSE mount, the driver packages the request and sends it over /dev/fuse to a user-space daemon. The daemon, written with libfuse, answers it and the kernel returns the result to the caller. The kernel's FUSE documentation describes the protocol and the mount options.

An in-kernel filesystem is a module (or built-in code) that registers a struct file_system_type and implements the VFS operation tables directly. It runs in kernel context, shares kernel memory and talks to the page cache and block layer without a process boundary.

The costs that differ

Every FUSE request crosses the user and kernel boundary twice, and the daemon is an ordinary process scheduled like any other. That adds context switches and copies on paths that an in-kernel filesystem handles inside one system call. The cost is structural, which is why newer FUSE features such as FUSE_PASSTHROUGH for backing files and io_uring-based transport exist to shave it. How much it matters depends on your workload: a filesystem that proxies slow network storage barely notices the overhead, while one serving cached small reads on NVMe can.

The failure model differs more than the speed. A FUSE daemon that crashes leaves its mount returning ENOTCONN ("Transport endpoint is not connected") until you unmount and restart it, but the rest of the system is fine. A kernel filesystem bug can oops or corrupt unrelated data. Debugging also differs: a daemon runs under gdb or valgrind, while a module needs printk, ftrace and a crash dump.

Decision table

QuestionPick FUSEPick a kernel filesystem
Is the root filesystem or early boot involved?No, FUSE needs user space runningYes, the kernel mounts it before init
Does a crash have to be survivable?Yes, a daemon crash is isolatedOnly with great care
Is the data backed by an API, archive or network service?Yes, use any language and libraryRarely worth it
Do you need the lowest latency per small operation?Not the best fitYes, no user-space round trip
Do you want to ship across distributions and kernels?Yes, the protocol is stableNo, you track kernel internals
Must it be the backing store for a block device or swap?Not supported wellYes
Is it a prototype or research design?Yes, iterate in minutesNo

Two rows deserve emphasis. In-kernel interfaces change between releases. register_filesystem, fs_context and iterate_shared all arrived by replacing something older, so an out-of-tree module needs porting for each kernel series. The FUSE protocol is versioned and negotiated at mount time, so a daemon built against libfuse 3 keeps working on newer kernels.

What a FUSE filesystem looks like

To show the scale, here is a read-only filesystem with one file, /hello, written against the libfuse 3 high-level API. Compile it with gcc -Wall hello_fuse.c $(pkg-config fuse3 --cflags --libs) -o hello_fuse:

hello_fuse.cc
#define FUSE_USE_VERSION 31
#include <fuse.h>
#include <string.h>
#include <errno.h>
#include <sys/stat.h>

static const char *content = "hello from userspace\n";

static int hello_getattr(const char *path, struct stat *st,
                         struct fuse_file_info *fi)
{
    (void)fi;
    memset(st, 0, sizeof(*st));
    if (strcmp(path, "/") == 0) {
        st->st_mode = S_IFDIR | 0555;
        st->st_nlink = 2;
    } else if (strcmp(path, "/hello") == 0) {
        st->st_mode = S_IFREG | 0444;
        st->st_nlink = 1;
        st->st_size = strlen(content);
    } else {
        return -ENOENT;
    }
    return 0;
}

static int hello_readdir(const char *path, void *buf, fuse_fill_dir_t fill,
                         off_t off, struct fuse_file_info *fi,
                         enum fuse_readdir_flags flags)
{
    (void)off; (void)fi; (void)flags;
    if (strcmp(path, "/") != 0)
        return -ENOENT;
    fill(buf, ".", NULL, 0, 0);
    fill(buf, "..", NULL, 0, 0);
    fill(buf, "hello", NULL, 0, 0);
    return 0;
}

static int hello_read(const char *path, char *buf, size_t size, off_t off,
                      struct fuse_file_info *fi)
{
    size_t len = strlen(content);

    (void)fi;
    if (strcmp(path, "/hello") != 0)
        return -ENOENT;
    if ((size_t)off >= len)
        return 0;
    if (off + size > len)
        size = len - off;
    memcpy(buf, content + off, size);
    return size;
}

static const struct fuse_operations ops = {
    .getattr = hello_getattr,
    .readdir = hello_readdir,
    .read    = hello_read,
};

int main(int argc, char **argv)
{
    return fuse_main(argc, argv, &ops, NULL);
}

Run it against an empty directory and read the file:

Shell
mkdir -p /tmp/hello_mnt
./hello_fuse /tmp/hello_mnt
ls /tmp/hello_mnt
cat /tmp/hello_mnt/hello
fusermount3 -u /tmp/hello_mnt
Text
hello
hello from userspace

That is the whole filesystem: three callbacks and about sixty lines. The equivalent kernel module needs a file_system_type, a superblock setup, inode and directory operations, and careful locking, and the next posts in this cluster cover those pieces. A newcomer can have the FUSE version working in an afternoon.

What a kernel filesystem buys you

Choose the kernel route when one of these holds:

  • The filesystem must be mounted as / or before user space starts, as with an initramfs-free embedded image.

  • Your design needs direct access to the page cache, block layer or journaling, as ext4 and XFS do with jbd2 and the block device.

  • You are upstreaming a general-purpose filesystem that distributions will ship.

  • Per-operation latency is the product, and a measured profile shows the daemon round trip dominating.

Even then, prototype in FUSE first. The semantics, the on-disk format and the tests transfer, and only the glue needs rewriting. Several well-known filesystems started that way.

A practical middle path

You do not have to choose once and forever. A common route is to start with the high-level libfuse API, where callbacks take paths and the library handles inode bookkeeping, and to move to the low-level API when you need control of inode numbers, lookup counts and cache timeouts. The low-level API is closer to how a kernel filesystem thinks, so it is also the better rehearsal if you later port the design into the kernel. Keep the on-disk or on-wire format in a library that both front ends can call, and the port becomes a matter of replacing glue.

Mount options give you a few more dials before you give up on FUSE. The kernel documentation lists max_read, allow_other, default_permissions and blksize, and the daemon can ask for kernel-side caching through attribute and entry timeouts. With default_permissions, the kernel enforces the mode bits itself, so your daemon does not have to re-implement access checks, which removes one class of security bugs. Read the mount.fuse3 manual page for the full list on your system.

Finally, think about who will operate this. A FUSE filesystem is a service: it needs a supervisor such as systemd to restart it, a plan for stale mounts after a crash, and a clean unmount path with fusermount3 -u. A kernel module is a different kind of burden, since a mismatch between the module and the running kernel stops it from loading at all after an update. Neither is free, but the operational failure of FUSE is a restart, while the failure of a module is a boot problem.

Boundaries

FUSE is not a free lunch for security. A daemon running as root that follows paths from untrusted users inherits all the usual risks, and allow_other widens who can reach the mount. FUSE also changes some semantics: mmap coherence, O_DIRECT and inode lifetime rules need attention, and fsync is only as durable as the daemon makes it.

Share

Keep reading

Get new posts by email

We send one email when a new post is published. No spam.

Unsubscribe in one click. No spam, ever.