一个高性能的异步只读缓存文件系统,专为加速NFS上大文件访问而设计。
- 🚀 重大性能修复 - 解决缓存未命中时NFS读取极慢的问题
- ⚡ 优化读取逻辑 - 缓存命中走异步,缓存未命中走同步
- 🔧 架构改进 - 移除异步队列瓶颈,保持NFS客户端优化
- 查看完整更新日志
- ⚡ 零延迟首次访问 - 异步缓存填充,不阻塞首次读取
- 🚀 io_uring 支持 - 利用 Linux 最新异步 I/O 框架,性能提升 20-30 倍
- 💾 智能缓存管理 - 自动LRU驱逐,高效利用NVMe空间
- 🔒 数据完整性 - 原子操作确保缓存文件始终完整
- 📊 实时监控 - 内置性能指标和健康检查
- 🔐 只读模式 - 专为只读工作负载优化,确保数据安全
- 🚢 静态编译 - 无依赖部署,兼容所有Linux发行版
- 🔄 零拷贝传输 - 使用 splice 实现高效文件传输
# 下载发布包
wget https://github.com/dionren/nfs-cachefs/releases/download/v0.6.0/nfs-cachefs-v0.6.0-linux-x86_64.tar.gz
# 解压并安装
tar -xzf nfs-cachefs-v0.6.0-linux-x86_64.tar.gz
cd nfs-cachefs-v0.6.0-linux-x86_64
sudo ./install.sh- Rust 1.75+
- musl工具链(用于静态编译)
# 克隆项目
git clone https://github.com/your-org/nfs-cachefs.git
cd nfs-cachefs
# 使用Makefile构建
make build
# 或直接运行构建脚本
./build/build-release.sh
# 安装到系统
sudo cp target/x86_64-unknown-linux-musl/release/nfs-cachefs /usr/local/bin/
sudo ln -sf /usr/local/bin/nfs-cachefs /sbin/mount.cachefs# 验证安装
nfs-cachefs --version
# 创建挂载点和缓存目录
sudo mkdir -p /mnt/cached /mnt/cache
# 先挂载NFS后端(必需)
sudo mount -t nfs 192.168.1.100:/share /mnt/nfs-share
# 手动挂载CacheFS (自动强制只读模式)
sudo mount -t cachefs cachefs /mnt/cached \
-o nfs_backend=/mnt/nfs-share,cache_dir=/mnt/cache,cache_size_gb=50,allow_other在 /etc/fstab 中添加:
# 1. 挂载NFS(必须在CacheFS之前)
10.20.66.201:/share /mnt/nfs nfs defaults,_netdev 0 0
# 2. 挂载本地缓存盘(如果需要)
/dev/nvme0n1 /mnt/nvme xfs defaults,noatime 0 0
# 3. 挂载CacheFS(自动只读模式)
cachefs /mnt/cached cachefs nfs_backend=/mnt/nfs,cache_dir=/mnt/nvme/cache,cache_size_gb=50,allow_other,_netdev 0 0
高级配置示例:
# 使用所有优化参数的配置(只读模式)
cachefs /mnt/cached cachefs nfs_backend=/mnt/nfs,cache_dir=/mnt/nvme/cache,cache_size_gb=100,block_size_mb=4,max_concurrent=8,direct_io=true,readahead_mb=16,eviction=lru,allow_other,_netdev 0 0
# 启用 io_uring 的高性能配置(Linux 5.10+)
cachefs /mnt/cached cachefs nfs_backend=/mnt/nfs,cache_dir=/mnt/nvme/cache,cache_size_gb=100,nvme_use_io_uring=true,nvme_queue_depth=256,nvme_polling_mode=true,allow_other,_netdev 0 0
nfs-cachefs/
├── src/ # 源代码
│ ├── main.rs # 程序入口
│ ├── lib.rs # 库入口
│ ├── mount_helper.rs # 挂载辅助工具
│ ├── core/ # 核心模块
│ ├── fs/ # 文件系统实现
│ ├── cache/ # 缓存管理
│ ├── io/ # io_uring 高性能 I/O
│ └── utils/ # 工具函数
├── build/ # 构建系统
│ ├── build-release.sh # 主构建脚本
│ ├── install.sh # 安装脚本
│ └── BUILD_GLIBC_COMPATIBILITY.md # 构建文档
├── tests/ # 测试套件
├── .github/ # GitHub Actions 工作流
├── Makefile # 构建快捷方式
├── Cargo.toml # Rust 项目配置
├── Cargo.lock # 依赖锁定文件
├── CHANGELOG.md # 更新日志
└── README.md # 项目说明
# 静态编译构建(生产环境)
make build
# 构建带 io_uring 支持的版本(Linux 5.10+)
make build-io-uring
# 本地开发构建
make local-build
# 清理构建产物
make clean
# 查看帮助
make help# 静态编译(推荐)
./build/build-release.sh
# 查看构建文档
cat ./build/BUILD_GLIBC_COMPATIBILITY.md# 运行所有测试
cargo test
# 运行集成测试 (需要先设置测试环境)
cargo test --test integration# 启用调试日志
RUST_LOG=debug nfs-cachefs --nfs-backend /mnt/nfs ...
# 使用前台模式进行调试
sudo mount -t cachefs cachefs /mnt/cached \
-o nfs_backend=/mnt/nfs,cache_dir=/mnt/cache,foreground,debug# 安装开发依赖
cargo install cargo-watch
cargo install cargo-expand
# 实时编译和测试
cargo watch -x check -x test| 场景 | 直接NFS | NFS-CacheFS (首次) | NFS-CacheFS (缓存后) | NFS-CacheFS + io_uring |
|---|---|---|---|---|
| 10GB文件顺序读 | 100s | 100s | 10s | 3s |
| 随机访问延迟 | 10ms | 10ms | 0.1ms | 0.05ms |
| 并发读取吞吐量 | 1GB/s | 1GB/s | 10GB/s | 20-30GB/s |
| CPU使用率 | 100% | 100% | 50% | 15% |
- ✅ 无依赖部署:单一二进制文件,无需安装额外库
- ✅ 广泛兼容性:支持任何Linux发行版,无论glibc版本
- ✅ 容器友好:适合Docker和Kubernetes部署
- ✅ 简化运维:减少部署复杂性和依赖管理
graph TD
A[应用程序] --> B[CacheFS FUSE层]
B --> C{缓存状态?}
C -->|已缓存| D[NVMe缓存]
C -->|未缓存| E[NFS后端]
C -->|缓存中| E
B --> F[异步缓存管理器]
F --> G[后台复制任务]
G --> D
欢迎提交Issue和Pull Request!在贡献之前,请注意:
- Bug报告: 使用GitHub Issues提交bug报告,请包含详细的重现步骤
- 功能请求: 描述您希望的功能和使用场景
- 代码贡献:
- Fork项目并创建功能分支
- 确保代码通过所有测试:
cargo test - 遵循Rust代码风格:
cargo fmt - 运行代码检查:
cargo clippy - 提交前请更新相关文档
- 当前版本: v0.6.0 (2025-01-10)
- 发布节奏: 根据功能和bug修复情况不定期发布
- 查看CHANGELOG.md了解详细更新历史
本项目采用 MIT 许可证。详见 LICENSE 文件。