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
flockandfcntlbyte-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
go install github.com/scitrera/memorylayer-storage/mlfs/cmd/mlfs@v0.7.1go install github.com/scitrera/memorylayer-storage/mlfs/cmd/mlfs-admin@v0.7.1go install github.com/scitrera/memorylayer-storage/mlfs/cmd/mlfs-bench@v0.7.1The 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:
mkdir -p /mnt/mlfsmlfs -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 mydomainThe 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
blobgwcontrol 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.
blobgwresolves the tenant’s bucket. blobgwowns garbage collection.
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.credsRemote 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.
| Flag | Default | Purpose |
|---|---|---|
-mount | /mnt/mlfs | Mountpoint (must exist) |
-meta-dsn | $MLFS_META_DSN | PostgreSQL metadata DSN (required) |
-domain | mlfs | Dedup domain. In remote mode this is also the tenant token. |
-data-dir | /var/lib/mlfs/data | Local casstore directory (local mode) |
-cache-dir | /var/lib/mlfs/cache | Read cache and write-back staging |
-staging-dir, -wal-dir | under -cache-dir | Put these on persistent disk when -cache-dir is ephemeral NVMe |
-cache-max-bytes, -cache-min-free-fraction | 0 | Limits on the size of the clean cache |
-upload-concurrency | 0 (auto, up to 16) | Parallel write-back uploads |
-readahead-bytes, -readahead-concurrency | 16 MiB, 8 | Sequential-read prefetch for cold reads |
-max-background | 64 | Concurrent FUSE background requests |
-db-max-open-conns | 8 | PostgreSQL pool size per daemon |
-compression, -pack-framing, -default-store-class | backend default | Compression policy (see above) |
-node-id | empty | Coordination identity. Empty means single-node with no NATS and no fencing. |
-nats-url, -nats-creds | empty | External NATS and the per-domain account credentials |
-lease-ttl, -lease-refresh | 30s, 10s | Ownership lease timing |
-maintenance-interval | 0 | In-daemon GC and changelog trimming (0 = off) |
-metrics-addr, -otel-endpoint | empty | Prometheus 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, andReadWriteMany. 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-csiimage bundles bothmlfs-csiand themlfsdaemon. The same image serves as the mount-pod image.
Prerequisites
- PostgreSQL metadata database per domain
- A
blobgwcontrol 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
mlfsStorageClass - RBAC
- a controller
Deploymentwithcsi-provisioner - a node
DaemonSetwithnode-driver-registrar, a privileged container, andBidirectionalmount 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/v1kind: StorageClassmetadata: name: mlfsprovisioner: mlfs.csi.scitrera.comreclaimPolicy: DeletevolumeBindingMode: ImmediateallowVolumeExpansion: falseparameters: 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: v1kind: Secretmetadata: name: mlfs-domain-creds namespace: tenant-acmestringData: 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 databaseThen claim a volume:
apiVersion: v1kind: PersistentVolumeClaimmetadata: name: shared-data namespace: tenant-acmespec: accessModes: ["ReadWriteMany"] storageClassName: mlfs resources: requests: storage: 1GiNode 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(default180s) keeps a domain mount alive after its last PVC leaves, so a quick pod recreate re-adopts the mount.-mount-ready-timeout(default60s) must stay above the mlfs lease TTL.