9P File Access

The 9P protocol provides an alternative way to mount ZeroFS on Linux systems. Originally from Plan 9, the 9P2000.L variant is optimized specifically for Linux and can offer better performance than NFS for certain workloads.

Installation

9P support is included in the Linux kernel. You may need to load the module:

# Load 9P modules
sudo modprobe 9p
sudo modprobe 9pnet_tcp

# Verify modules are loaded
lsmod | grep 9p

Basic Usage

Mounting ZeroFS

# Create mount point
sudo mkdir -p /mnt/zerofs-9p

# Mount via 9P
sudo mount -t 9p -o trans=tcp,port=5564,version=9p2000.L 127.0.0.1 /mnt/zerofs-9p

Unmounting

sudo umount /mnt/zerofs-9p

Mount Options

Required Options

OptionDescription
trans=tcpUse TCP transport
port=5564ZeroFS 9P port
version=9p2000.LUse Linux-specific 9P version

Performance Options

OptionDescriptionDefault
msize=NMaximum message size in bytes8192
cache=modeCaching mode (see below)none
access=modeAccess check modeuser

Cache Modes

ModeDescriptionUse Case
noneNo caching, direct I/OMaximum consistency
looseRelaxed consistencyBest performance
fscachePersistent cacheCache survives unmount
mmapEnable mmap supportRequired for memory-mapped file access

Configuration

Persistent Mount

Add to /etc/fstab:

# Basic persistent mount
127.0.0.1 /mnt/zerofs-9p 9p trans=tcp,port=5564,version=9p2000.L,_netdev 0 0

# With performance options
127.0.0.1 /mnt/zerofs-9p 9p trans=tcp,port=5564,version=9p2000.L,msize=1048576,cache=loose,_netdev 0 0

Systemd Mount Unit

Create /etc/systemd/system/mnt-zerofs-9p.mount:

[Unit]
Description=ZeroFS 9P Mount
After=network.target

[Mount]
What=127.0.0.1
Where=/mnt/zerofs-9p
Type=9p
Options=trans=tcp,port=5564,version=9p2000.L,msize=1048576,cache=loose,_netdev

[Install]
WantedBy=multi-user.target

Enable and start:

sudo systemctl enable mnt-zerofs-9p.mount
sudo systemctl start mnt-zerofs-9p.mount

Performance Tuning

Message Size

Larger message sizes improve throughput for sequential I/O:

# Low (8KB)
-o msize=8192

# Recommended (1MB)
-o msize=1048576

Cache Mode Selection

Choose based on your workload:

# Development - frequent file changes
sudo mount -t 9p -o cache=none ...

# Applications using mmap (databases, etc.)
sudo mount -t 9p -o cache=mmap ...

# Best performance, accept some inconsistency
sudo mount -t 9p -o cache=loose ...

Troubleshooting

Mount Fails

# Check if ZeroFS is running
ps aux | grep zerofs

# Verify 9P port is open
nc -zv 127.0.0.1 5564

# Check kernel modules
lsmod | grep 9p

# Enable debug messages
sudo mount -t 9p -o trans=tcp,port=5564,debug=0x1ff 127.0.0.1 /mnt/test

Performance Issues

# Check current mount options
mount | grep 9p

# Test with different cache modes
for mode in none mmap loose; do
    echo "Testing cache=$mode"
    sudo umount /mnt/zerofs-9p
    sudo mount -t 9p -o cache=$mode,msize=1048576,trans=tcp,port=5564 127.0.0.1 /mnt/zerofs-9p
    # Run your benchmark
done

9P vs NFS Comparison

When to Use 9P

  • Linux-only environments
  • Need maximum performance on Linux
  • Simpler protocol overhead is beneficial
  • Applications requiring correct fsync behavior (databases, transactional systems)

When to Use NFS

  • Cross-platform compatibility needed
  • macOS or Windows clients
  • Need automatic reconnection on network issues
  • Existing NFS infrastructure and tooling

Performance Characteristics

Aspect9PNFS
Protocol OverheadLowerHigher
Linux PerformanceBetterGood
Cross-PlatformLinux onlyUniversal
fsync BehaviorCorrectLimited*

*NFS COMMIT semantics may not provide expected durability guarantees for fsync operations

Security Considerations

Advanced Usage

Multiple Cache Modes

Mount the same filesystem with different cache modes:

# Consistent mount for important operations
sudo mount -t 9p -o cache=none,trans=tcp,port=5564 127.0.0.1 /mnt/zerofs-consistent

# Performance mount for read-heavy operations  
sudo mount -t 9p -o cache=loose,trans=tcp,port=5564 127.0.0.1 /mnt/zerofs-fast

Next Steps

Was this page helpful?