Fire-Flyer File System (3FS)
repository·main·Indexed 27 days ago
https://github.com/deepseek-ai/3fsA high-performance distributed file system optimized for AI training and inference workloads. 3FS leverages modern SSDs and RDMA networks to provide strong consistency and high throughput for data loading, checkpointing, and KVCache management. The system includes components such as mgmtd, meta, and storage services, an admin CLI for cluster management, a FUSE client, and a USRBIO FIO engine plugin for benchmarking.
What's inside 3FS
- User Space Ring Based IO (USRBIO) is a high-speed I/O interface for 3FS. It allows user applications to submit I/O requests directly to the 3FS I/O queue in the FUSE process, bypassing FUSE limitations such as maximum single I/O size restrictions. This enables zero-copy data exchange between the user and FUSE processes.
Understand the 3FS Chunk Storage and Data Placement
main3FS uses a chunk storage system designed for high bandwidth and linear scalability with SSD count. Data is replicated using Chain Replication with Apportioned Queries (CRAQ).
Key Concepts:
- Chain Replication: Each chunk is replicated across a chain of storage targets. Write requests are sent to the head and propagated to the tail. Read requests can be sent to any target in the chain to balance load.
- Storage Targets: Multiple targets are created on each SSD, and targets join different chains to ensure load balancing.
- Chain Tables: The metadata service selects a chain table for each file. Multiple tables can exist to support different requirements (e.g., one for batch/offline jobs and one for online services) using mutually exclusive nodes/SSDs.
Understand the role of the core component in 3fs
mainThecorecomponent serves as the foundational base component for various concrete server components within the 3fs ecosystem, includingmgmtd,meta, andstorage.Understand 3FS file chunking and data layout
main3FS divides file data into equally sized chunks and stripes them across multiple replication chains.
Key Concepts:
- Chunk ID Generation: Computed by concatenating the file's
inode idand thechunk index. - Per-directory Configuration: Users can specify the
chain table,chunk size, andstripe sizefor files on a per-directory basis. - Allocation Strategy: When creating a file, the metadata service uses a round-robin strategy to select consecutive replication chains from the designated
chain tablebased on thestripe size. A random seed is then used to shuffle these chains to ensure balanced distribution across SSDs. - Client-side Computation: Once a client obtains the data layout from the meta service, it can independently compute chunk IDs and chains for data operations, reducing meta service overhead.
- Chunk ID Generation: Computed by concatenating the file's
Understand the Chunk Engine architecture
mainThe Chunk Engine is composed of two primary components designed for high-performance chunk management and atomic metadata persistence:
- Allocator: Manages the in-memory state of chunk allocation and reclamation. It assigns chunk positions to disk space.
- MetaStore: Responsible for the durable persistence of allocation/reclamation events using RocksDB. It ensures atomicity via
WriteBatch.
Write Workflow:
- The Allocator assigns a new chunk position (in-memory).
- Data is written to the assigned disk position.
- Metadata is generated and persisted to the MetaStore using a
WriteBatchto ensure the update is atomic.
Read Safety: Read operations return an
Arc<ChunkPos>, which manages ownership of the chunk position. This ensures that even if a chunk is reclaimed or deleted, the data remains valid and accessible until theArcis dropped.Understand the 3FS Architecture
main3FS is a distributed file system composed of four main components, all connected via an RDMA network (InfiniBand or RoCE):
- Cluster Manager: Handles membership changes and distributes cluster configuration. It uses a primary/secondary election model. Configuration is typically stored in a distributed coordination service like ZooKeeper or etcd (or the same key-value store used for file metadata).
- Metadata Service: Implements file system semantics (e.g.,
open,create). These services are stateless because metadata is stored in a transactional key-value store (e.g., FoundationDB). - Storage Service: Manages local SSDs and provides a chunk store interface. It uses Chain Replication with Apportioned Queries (CRAQ) to ensure strong consistency and high throughput.
- Client: Provides two interfaces for applications: the FUSE client (low adoption barrier, standard POSIX) and the Native client (high performance, asynchronous zero-copy).
USRBIO Core Concepts: Iov and Ior
mainUSRBIO relies on two primary shared memory structures:
- Iov: A large shared memory region used for zero-copy read/write operations. All read data is read into the Iov, and all write data must be written to the Iov by the user first. The FUSE process manages InfiniBand (IB) memory registration for this region.
- Ior: A small shared memory ring used for communication between the user and FUSE processes, similar to Linux
io-uring. The user enqueues requests and the FUSE process dequeues them. I/Os are executed in batches controlled byio_depth. For multi-threaded applications, it is recommended to use multiple rings to avoid synchronization overhead.
Access 3fs documentation and guides
mainThe 3fs documentation is organized into several key areas:
- Design Notes: Detailed architectural and design documentation.
- Setup Guide: Instructions for deploying the system.
- USRBIO API Reference: Technical reference for the USRBIO API.
- P Specifications: Detailed specifications for the P component.
Understand 3FS metric types and storage
main3FS calculates metrics within each service and stores them in ClickHouse via a monitor service. Metrics are categorized into four types, which determine how they are recorded and whether they reset after each report:
- value (
ValueRecorder): Stored in3fs.counters. These are set directly by code (e.g., capacity) and do not necessarily reset. - count (
CountRecorder): Stored in3fs.counters. These typically increase and reset to zero after each report (e.g., IOPS). However, they can also be used to track 'on-flight' operations, where the value is increased at the start and decreased upon completion rather than resetting automatically. - distribution (
DistributionRecorder): Stored in3fs.distributions. Used to calculate percentiles like P90 and P99 for the period between reports. - latency (
LatencyRecorder): Stored in3fs.distributions. A specialized distribution implementation that records latency in nanoseconds (ns).
- value (
Build 3FS
mainBuild 3FS into the
builddirectory using CMake.Important: Shuffle Method Compatibility Due to
std::shuffleimplementation differences, binaries compiled with different compiler versions (e.g.,g++10vsg++11) may be incompatible. You must specify-DSHUFFLE_METHODto lock the algorithm:- Existing Clusters: Use the method corresponding to the compiler version used for the current deployment (
g++10org++11). - New Clusters: Choose either
g++10org++11, but you must remain consistent for all future builds to maintain compatibility.
# Replace <method> with 'g++10' or 'g++11' based on your environment cmake -S . -B build \ -DCMAKE_CXX_COMPILER=clang++-14 -DCMAKE_C_COMPILER=clang-14 \ -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \ -DSHUFFLE_METHOD=<method> cmake --build build -j 32- Existing Clusters: Use the method corresponding to the compiler version used for the current deployment (
Install dependencies for OpenCloudOS 9 and TencentOS 4
mainUse the following command to install the necessary system dependencies on OpenCloudOS 9 and TencentOS 4.
dnf install epol-release wget git meson cmake perl lld gcc gcc-c++ autoconf lz4 lz4-devel xz xz-devel \ double-conversion-devel libdwarf-devel libunwind-devel libaio-devel gflags-devel glog-devel \ libuv-devel gmock-devel gperftools gperftools-devel openssl-devel boost-static boost-devel mono-devel \ libevent-devel libibverbs-devel numactl-devel python3-develBuild 3FS using Docker
mainIf you prefer using Docker for the build environment, pull the appropriate image for your OS:
- TencentOS-4:
docker.io/tencentos/tencentos4-deepseek3fs-build:latest - OpenCloudOS-9:
docker.io/opencloudos/opencloudos9-deepseek3fs-build:latest
docker pull docker.io/tencentos/tencentos4-deepseek3fs-build:latest # OR docker pull docker.io/opencloudos/opencloudos9-deepseek3fs-build:latest- TencentOS-4: