LLFIO is a high-performance, low-latency C++17/20 library designed for modern file I/O and filesystem operations, specifically targeting fast storage devices like Storage Class Memory (SCM), Direct Access Storage (DAX), and NVMe drives. The library is architected around "zero-copy," "zero-malloc," and race-free (TOCTOU-free) design principles, achieving a benchmarked I/O overhead of just 100 nanoseconds. It provides a portable API across Windows, Linux, Mac OS, and other POSIX-compliant systems, and is compatible with toolchains that have C++ exceptions and RTTI globally disabled. Key features include a hierarchical handle system for different filesystem objects (files, directories, memory maps), comprehensive support for memory-mapped files, and advanced filesystem algorithms. The library is built using CMake, offers header-only, static, and shared library build modes, and is mature enough for production use, notably powering a component of the US SEC's MIDAS data ingress system.
LLFIO: A High-Performance C++ File I/O Library
Core Purpose & Performance: LLFIO is a C++ library for file I/O designed to minimize overhead for high-throughput storage. It aims to achieve latencies suitable for devices like Intel Optane, with a benchmarked syscall overhead of 100 nanoseconds, corresponding to a theoretical maximum of 10 million IOPS at a queue depth of one.
Key Design Principles:
Zero-Copy & Zero-Malloc: The library is designed to eliminate system memory copies and dynamic memory allocations during I/O operations, reducing CPU cache pressure and latency.
Race-Free Filesystem Operations: It is built to avoid Time-of-check-to-time-of-use (TOCTOU) race conditions, making filesystem algorithms more reliable.
Platform & Compiler Support:
It is portable to any conforming C++17 compiler with a working <filesystem> implementation. It also leverages C++20 features like Coroutines and Concepts if available.
Supported operating systems include Windows, Linux, Android, iOS, Mac OS, and FreeBSD.
The library can be used in environments where C++ exceptions and RTTI are globally disabled.
Hierarchical Handle System: LLFIO provides a structured hierarchy of handle types for different I/O and filesystem tasks, each adding specific functionality:
handle: Base type for opening, closing, and cloning.
path_handle: A race-free anchor to a location in the filesystem.
io_handle: Adds synchronous scatter-gather I/O and byte-range locking.
file_handle: Adds file-specific operations like creation and extent management.
The library uses CMake and can be built in three modes: header-only, static library, or shared library. Prebuilt binaries are also available.
It can be easily installed via the vcpkg package manager.
Key Takeaway: Using the header-only mode on Windows is discouraged for production use due to a design flaw in <system_error> that can cause unreliable error code comparisons across shared library boundaries.
Future Development & Project Status:
The project is mature and has been used in production by multiple vendors for several years.
Future plans include implementing a B+ tree index based on a page allocator, creating a key-value store, and adding support for Linux's io_uring for high-performance non-blocking I/O.
Licensing: The library is available under a dual license: either the Apache License, Version 2.0 or the Boost Software License, Version 1.0.