Skip to content

POSIX Filesystem and CSI Driver

mlfs is a FUSE filesystem. Metadata lives in PostgreSQL. File data is stored as content-addressed slices through casstore, so it gets the same deduplication and compression as objects. mlfs-csi exposes mlfs to Kubernetes pods as persistent volumes.

mlfs features

  • POSIX metadata in PostgreSQL: files, directories, symlinks, hard links, FIFOs, device nodes and sockets, extended attributes, and BSD flock and fcntl byte-range locks.
  • POSIX ACLs: ACLs are stored as system.posix_acl_* xattrs. mlfs advertises ACL support to the kernel, and the kernel enforces them.
  • Durable write-back cache: writes are staged on local disk before they’re acknowledged, then uploaded asynchronously. A local write-ahead log (-wal, on by default) recovers metadata writes that hadn’t been committed when a crash occurred.
  • Copy-on-write: copy_file_range(2) shares the underlying slices for chunk-aligned ranges, so no data is moved, and falls back to copying for the rest.
  • Open-unlinked files: a file stays readable while it’s still open after unlink.
  • Multi-node coordination: ownership leases, fencing, and change notifications over NATS JetStream coordinate nodes that mount the same domain.
  • Content-aware compression: files with model or tensor extensions stay uncompressed so they remain range-readable and mmap-safe. The extensions are .safetensors, .pt, .pth, .bin, .npy, .npz, .gguf, .ggml, .onnx, and .ckpt.

Linux and FUSE (/dev/fuse, fusermount3) are required. The repository includes a pjdfstest POSIX-conformance harness (mlfs/test/fstest/run-pjdfstest.sh) and fio workloads (mlfs/test/fio/) so you can run acceptance tests on your own hosts.

Installing the commands

Terminal window
go install github.com/scitrera/memorylayer-storage/mlfs/cmd/mlfs@v0.7.1
go install github.com/scitrera/memorylayer-storage/mlfs/cmd/mlfs-admin@v0.7.1
go install github.com/scitrera/memorylayer-storage/mlfs/cmd/mlfs-bench@v0.7.1

The ghcr.io/scitrera/mlfs image contains mlfs, mlfs-admin, and mlfs-bench, with fuse3 installed.

Mounting locally (single node)

In local mode, file data goes to a casstore directory on the same host:

Terminal window
mkdir -p /mnt/mlfs
mlfs -mount /mnt/mlfs \
-meta-dsn 'postgres://user:pass@localhost:5432/mlfs?sslmode=disable' \
-data-dir /var/lib/mlfs/data \
-cache-dir /var/lib/mlfs/cache \
-domain mydomain

The metadata schema is created automatically. -meta-dsn falls back to $MLFS_META_DSN. Local mode compresses with zstd by default. Add -allow-other if processes running as other users must reach the mount.

Remote mode

-remote switches to the converged direct-S3 backend:

  • Bytes move between the node and the tenant’s S3-compatible bucket through presigned URLs issued by the blobgw control plane.
  • Dedup-index lookups go over NATS.
  • Slice manifests are stored in the same PostgreSQL database as the metadata.
  • The node holds no S3 credentials. blobgw resolves the tenant’s bucket.
  • blobgw owns garbage collection.
Terminal window
mlfs -remote -allow-other \
-domain tenant-acme \
-meta-dsn 'postgres://…/mlfs_tenant_acme' \
-mount /mnt/mlfs -cache-dir /var/lib/mlfs/cache \
-node-id "$HOSTNAME" \
-nats-url nats://nats.dc1:4222 \
-nats-creds /etc/mlfs/tenant-acme.creds

Remote mode stores everything uncompressed by default, which suits model stores. Set -compression zstd to switch to mixed mode: model and tensor files stay uncompressed and generic data is compressed. -default-store-class uncompressed also keeps unrecognized files uncompressed.

See Operations for the full remote topology and per-tenant NATS account isolation.

Key mlfs flags

Run mlfs -help to see every flag.

FlagDefaultPurpose
-mount/mnt/mlfsMountpoint (must exist)
-meta-dsn$MLFS_META_DSNPostgreSQL metadata DSN (required)
-domainmlfsDedup domain. In remote mode this is also the tenant token.
-data-dir/var/lib/mlfs/dataLocal casstore directory (local mode)
-cache-dir/var/lib/mlfs/cacheRead cache and write-back staging
-staging-dir, -wal-dirunder -cache-dirPut these on persistent disk when -cache-dir is ephemeral NVMe
-cache-max-bytes, -cache-min-free-fraction0Limits on the size of the clean cache
-upload-concurrency0 (auto, up to 16)Parallel write-back uploads
-readahead-bytes, -readahead-concurrency16 MiB, 8Sequential-read prefetch for cold reads
-max-background64Concurrent FUSE background requests
-db-max-open-conns8PostgreSQL pool size per daemon
-compression, -pack-framing, -default-store-classbackend defaultCompression policy (see above)
-node-idemptyCoordination identity. Empty means single-node with no NATS and no fencing.
-nats-url, -nats-credsemptyExternal NATS and the per-domain account credentials
-lease-ttl, -lease-refresh30s, 10sOwnership lease timing
-maintenance-interval0In-daemon GC and changelog trimming (0 = off)
-metrics-addr, -otel-endpointemptyPrometheus scrape endpoint and OTLP push

With -metrics on (the default), live counters are also available at <mount>/.mlfs/metrics.

Administration

mlfs-admin subcommands:

  • gc: garbage-collect orphaned slice data.
  • fsck: reap inodes orphaned by a crash and stale locks, then run GC.
  • stats: read-only inspection of metadata and on-disk usage.
  • bench: POSIX throughput and small-file latency on a mounted path.
  • compact, bridge: further maintenance commands. Run each with -h.

gc and fsck assume a quiesced filesystem. They refuse to run while a live daemon holds the data-dir lock. -force-online overrides that check and can cause data loss if a mount is actually active.

Kubernetes: mlfs-csi

The CSI driver mlfs.csi.scitrera.com provisions volumes scoped to a domain. A volume is a subdirectory of the domain’s mlfs mount, bind-mounted into the pod. One node plugin per node serves PVCs for many domains at once.

  • Access modes: ReadWriteOnce, ReadOnlyMany, and ReadWriteMany. At the CSI level this covers single-node writer and reader, multi-node reader, and multi-node single and multi writer. Block volumes are not supported.
  • Pod launch mode: with -launch-mode=pod, the node plugin runs a separate mlfs mount pod for each domain. A restart or upgrade of the CSI container therefore doesn’t kill the mount daemons, and the plugin re-adopts live mount pods when it starts.
  • Capacity is recorded but only advisory. mlfs has no per-volume quota yet.
  • The ghcr.io/scitrera/mlfs-csi image bundles both mlfs-csi and the mlfs daemon. The same image serves as the mount-pod image.

Prerequisites

  • PostgreSQL metadata database per domain
  • A blobgw control plane with tenant bindings (see Operations)
  • NATS in operator/JWT mode with a system account. The system account must not have JetStream enabled. Each tenant account needs JetStream, because mlfs coordination uses JetStream KV. No-auth and user/password NATS servers are not supported by the driver.

Install

Start from the reference manifest mlfs-csi/deploy/mlfs-csi.yaml in the repository. It defines:

  • the CSIDriver
  • a single mlfs StorageClass
  • RBAC
  • a controller Deployment with csi-provisioner
  • a node DaemonSet with node-driver-registrar, a privileged container, and Bidirectional mount propagation for /var/lib/mlfs/domains

Set the image tags (for example ghcr.io/scitrera/mlfs-csi:0.7.1) and the NATS URL, then apply it. Treat it as an example to adapt. Provisioning databases and credentials is the operator’s job.

The StorageClass from the reference manifest:

apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: mlfs
provisioner: mlfs.csi.scitrera.com
reclaimPolicy: Delete
volumeBindingMode: Immediate
allowVolumeExpansion: false
parameters:
natsUrl: "nats://nats.mlfs-control.svc:4222"
dirMode: "0777"
csi.storage.k8s.io/node-publish-secret-name: "mlfs-domain-creds"
csi.storage.k8s.io/node-publish-secret-namespace: ${pvc.namespace}

Each tenant namespace provides its own node-publish secret:

apiVersion: v1
kind: Secret
metadata:
name: mlfs-domain-creds
namespace: tenant-acme
stringData:
domain: tenant-acme # mlfs dedup domain / NATS account token
nats-creds: | # this tenant's NATS account credentials
-----BEGIN NATS USER JWT----- ...
meta-dsn: postgres://…/tenant_acme # this tenant's mlfs metadata database

Then claim a volume:

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: shared-data
namespace: tenant-acme
spec:
accessModes: ["ReadWriteMany"]
storageClassName: mlfs
resources:
requests:
storage: 1Gi

Node plugin tuning

Node plugin flags pass through to each per-domain mlfs daemon. The main ones are -cache-base, -cache-max-bytes, -cache-min-free-fraction, -upload-concurrency, -pack-target-bytes, -readahead-bytes, -readahead-concurrency, -max-background, -db-max-open-conns, -compression, -default-store-class, and -mount-otel-endpoint. Several also accept environment variables (MLFS_NATS_URL, MLFS_LAUNCH_MODE, MLFS_MOUNT_POD_IMAGE, MLFS_CACHE_BASE, MLFS_COMPRESSION, and others).

  • -mount-linger-grace (default 180s) keeps a domain mount alive after its last PVC leaves, so a quick pod recreate re-adopts the mount.
  • -mount-ready-timeout (default 60s) must stay above the mlfs lease TTL.