• Stars
    star
    753
  • Rank 58,049 (Top 2 %)
  • Language
    C++
  • License
    Other
  • Created over 10 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

P1031 low level file i/o and filesystem library for the C++ standard
LLFIO
on GitHub
API
Documentation
CTest summary
dashboard
Prebuilt
binaries

Herein lies my proposed zero whole machine memory copy file i/o and filesystem library for the C++ standard, intended for storage devices with ~1 microsecond 4Kb transfer latencies and those supporting Storage Class Memory (SCM)/Direct Access Storage (DAX). Its i/o overhead, including syscall overhead, has been benchmarked to 100 nanoseconds on Linux which corresponds to a theoretical maximum of 10M IOPS @ QD1, approx 40Gb/sec per thread. It has particularly strong support for writing portable filesystem algorithms which work well with directly mapped non-volatile storage such as Intel Optane.

It is a complete rewrite after a Boost peer review in August 2015. LLFIO is the reference implementation for these C++ standardisations:

  • llfio::path_view is expected to enter the C++ 26 standard (P1030).
  • llfio::file_handle and llfio::mapped_file_handle are on track for entering the C++ 26 standard (P1883).

Other characteristics:

  • Portable to any conforming C++ 14 compiler with a working Filesystem TS in its STL.
    • Note that VS2019 16.3 and libc++ 11 dropped support for Filesystem in C++ 14, so for those LLFIO's cmake forces on C++ 17.
  • Fully clean with C++ 20.
    • Will make use of any Coroutines, Concepts, Span, Byte etc if you have them, otherwise swaps in C++ 14 compatible alternatives.
    • NOTE that Ubuntu 18.04's libstdc++ 9 does not currently provide symbols for <codecvt> if you are building in C++ 20, so linking LLFIO programs on libstdc++ on that Linux if in C++ 20 will fail. Either use a different STL, manually rebuild libstdc++, or use C++ 17.
  • Aims to support Microsoft Windows, Linux, Android, iOS, Mac OS and FreeBSD.
    • Best effort to support older kernels up to their EOL (as of July 2020: >= Windows 8.1, >= Linux 2.6.32 (RHEL EOL), >= Mac OS 10.13, >= FreeBSD 11).
  • Original error code is always preserved, even down to the original NT kernel error code if a NT kernel API was used.
    • Optional configuration based on P1028 SG14 status_code and standard error object for P0709 Zero-overhead deterministic exceptions.
  • Race free filesystem design used throughout (i.e. no TOCTOU).
  • Zero malloc, zero exception throw and zero whole system memory copy design used throughout, even down to paths (which can hit 64Kb!).
  • Comprehensive support for virtual and mapped memory of both SCM/DAX and page cached storage, including large, huge and super pages.
  • Happy on the cloud, well tested with AWS Lustre distributed network filing system.

\note Most of this code is mature quality. It has been shipping in production with multiple vendors for some years now, indeed amongst many big data solutions it powers the low level custom database component of the US Security and Exchange Commission's MIDAS solution which ingresses Terabytes of trade data per day. It is considered quite reliable on Windows and Linux (less well tested on Mac OS).

Examples of use (more examples: https://github.com/ned14/llfio/tree/develop/example):

Memory map in a file for read: \snippet example/mapped_file.cpp mapped_file

Sparsely stored temporary disposable array: \snippet example/sparse_array.cpp sparse_array

Read metadata about a file and its storage: \snippet example/read_stats.cpp file_read_stats

See https://github.com/ned14/llfio/blob/master/programs/fs-probe/fs_probe_results.yaml for a database of latencies for various previously tested OS, filing systems and storage devices.

Todo list for already implemented parts: https://ned14.github.io/llfio/todo.html

Β 

[Build instructions can found here](Build.md)

Β 

v2 architecture and design implemented:

NEW in v2 Boost peer review feedback
βœ” βœ” Universal native handle/fd abstraction instead of void *.
βœ” βœ” Perfectly/Ideally low memory (de)allocation per op (usually none).
βœ” βœ” noexcept API throughout returning error_code for failure instead of throwing exceptions.
βœ” βœ” LLFIO v1 handle type split into hierarchy of types:
  1. handle - provides open, close, get path, clone, set/unset append only, change caching, characteristics
  2. fs_handle - handles with an inode number
  3. path_handle - a race free anchor to a subset of the filesystem
  4. directory_handle - enumerates the filesystem
  5. io_handle - adds synchronous scatter-gather i/o, byte range locking
  6. file_handle - adds open/create file, get and set maximum extent
  7. mapped_file_handle - adds low latency memory mapped scatter-gather i/o
βœ” βœ” Cancelable i/o (made possible thanks to dropping XP support).
βœ” βœ” All shared_ptr usage removed as all use of multiple threads removed.
βœ” βœ” Use of std::vector to transport scatter-gather sequences replaced with C++ 20 span<> borrowed views.
βœ” βœ” Completion callbacks are now some arbitrary type U&& instead of a future continuation. Type erasure for its storage is bound into the one single memory allocation for everything needed to execute the op, and so therefore overhead is optimal.
βœ” βœ” Filing system algorithms made generic and broken out into public llfio::algorithms template library (the LLFIO FTL).
βœ” βœ” Abstraction of native handle management via bitfield specified "characteristics".
βœ” Storage profiles, a YAML database of behaviours of hardware, OS and filing system combinations.
βœ” Absolute and interval deadline timed i/o throughout (made possible thanks to dropping XP support).
βœ” Dependency on ASIO/Networking TS removed completely.
βœ” Four choices of algorithm implementing a shared filing system mutex.
βœ” Uses CMake, CTest, CDash and CPack with automatic usage of C++ Modules or precompiled headers where available.
βœ” Far more comprehensive memory map and virtual memory facilities.
βœ” Much more granular, micro level unit testing of individual functions.
βœ” Much more granular, micro level internal logging of every code path taken.
βœ” Path views used throughout, thus avoiding string copying and allocation in std::filesystem::path.
βœ” Paths are equally interpreted as UTF-8 on all platforms.
βœ” We never store nor retain a path, as they are inherently racy and are best avoided.
βœ” βœ” Parent handle caching is hard coded in, it is now an optional user applied templated adapter class.

Todo:

NEW in v2 Boost peer review feedback
βœ” clang AST assisted SWIG bindings for other languages.
βœ” Statistical tracking of operation latencies so realtime IOPS can be measured.

Planned features implemented:

NEW in v2 Windows POSIX
βœ” βœ” βœ” Native handle cloning.
βœ” (up from four) βœ” βœ” Maximum possible (seven) forms of kernel caching.
βœ” βœ” Absolute path open.
βœ” βœ” Relative "anchored" path open enabling race free file system.
βœ” βœ” Win32 path support (260 path limit).
βœ” NT kernel path support (32,768 path limit).
βœ” βœ” βœ” Synchronous universal scatter-gather i/o.
βœ” (POSIX AIO support) βœ” βœ” Asynchronous universal scatter-gather i/o.
βœ” βœ” βœ” i/o deadlines and cancellation.
βœ” βœ” Retrieving and setting the current maximum extent (size) of an open file.
βœ” βœ” Retrieving the current path of an open file irrespective of where it has been renamed to by third parties.
βœ” βœ” statfs_t ported over from LLFIO v1.
βœ” βœ” utils namespace ported over from LLFIO v1.
βœ” βœ” βœ” shared_fs_mutex shared/exclusive entities locking based on lock files
βœ” βœ” βœ” Byte range shared/exclusive locking.
βœ” βœ” βœ” shared_fs_mutex shared/exclusive entities locking based on byte ranges
βœ” βœ” βœ” shared_fs_mutex shared/exclusive entities locking based on atomic append
βœ” βœ” Memory mapped files and virtual memory management (section_handle, map_handle and mapped_file_handle)
βœ” βœ” βœ” shared_fs_mutex shared/exclusive entities locking based on memory maps
βœ” βœ” βœ” Universal portable UTF-8 path views.
βœ” βœ” "Hole punching" and hole enumeration ported over from LLFIO v1.
βœ” βœ” Directory handles and very fast directory enumeration ported over from LLFIO v1.
βœ” βœ” βœ” shared_fs_mutex shared/exclusive entities locking based on safe byte ranges
βœ” βœ” Set random or sequential i/o (prefetch).
βœ” βœ” βœ” llfio::algorithm::trivial_vector<T> with constant time reallocation if T is trivially copyable.
βœ” βœ” symlink_handle.
βœ” βœ” βœ” Large, huge and massive page size support for memory allocation and (POSIX only) file maps.
βœ” βœ” βœ” A mechanism for writing a stat_t onto an inode.
βœ” βœ” βœ” Graph based directory hierarchy traveral algorithm.
βœ” βœ” βœ” Graph based directory hierarchy summary algorithm.
βœ” βœ” βœ” Graph based reliable directory hierarchy deletion algorithm.
βœ” βœ” βœ” Intelligent file contents cloning between file handles.

Todo thereafter in order of priority:

NEW in v2 Windows POSIX
βœ” Page allocator based on an index of linked list of free pages. See notes.
βœ” Optionally concurrent B+ tree index based on page allocator for key-value store.
βœ” Attributes extending span<buffers_type> with DMA colouring.
βœ” Coroutine generator for iterating a file's contents in DMA friendly way.
βœ” Ranges & Concurrency based reliable directory hierarchy copy algorithm.
βœ” Ranges & Concurrency based reliable directory hierarchy update (two and three way) algorithm.
βœ” Linux io_uring support for native non-blocking O_DIRECT i/o
βœ” std::pmr::memory_resource adapting a file backing if on C++ 17.
βœ” Extended attributes support.
βœ” Algorithm to replace all duplicate content with hard links.
βœ” Algorithm to figure out all paths for a hard linked inode.
βœ” Algorithm to compare two or three directory enumerations and give differences.

Features possibly to be added after a Boost peer review:

  • Directory change monitoring.
  • Permissions support (ACLs).
Why you might need LLFIO
Manufacturer claimed 4Kb transfer latencies for the physical hardware: - Spinning rust hard drive latency @ QD1: **9000us** - SATA flash drive latency @ QD1: **800us** - NVMe flash drive latency @ QD1: **300us** - RTT UDP packet latency over a LAN: **60us** - NVMe Optane drive latency @ QD1: **60us** - `memcpy(4Kb)` latency: **5us** (main memory) to **1.3us** (L3 cache) - RTT PCIe latency: **0.5us** 100% read QD1 4Kb direct transfer latencies for the software with LLFIO: - < 99% spinning rust hard drive latency: Windows **187,231us** FreeBSD **9,836us** Linux **26,468us** - < 99% SATA flash drive latency: Windows **290us** Linux **158us** - < 99% NVMe drive latency: Windows **37us** FreeBSD **70us** Linux **30us** 75% read 25% write QD4 4Kb direct transfer latencies for the software with LLFIO: - < 99% spinning rust hard drive latency: Windows **48,185us** FreeBSD **61,834us** Linux **104,507us** - < 99% SATA flash drive latency: Windows **1,812us** Linux **1,416us** - < 99% NVMe drive latency: Windows **50us** FreeBSD **143us** Linux **40us**

Max bandwidth for the physical hardware:

  • DDR4 2133: 30Gb/sec (main memory)
  • x4 PCIe 4.0: 7.5Gb/sec (arrives end of 2017, the 2018 NVMe drives will use PCIe 4.0)
  • x4 PCIe 3.0: 3.75Gb/sec (985Mb/sec per PCIe lane)
  • 2017 XPoint drive (x4 PCIe 3.0): 2.5Gb/sec
  • 2017 NVMe flash drive (x4 PCIe 3.0): 2Gb/sec
  • 10Gbit LAN: 1.2Gb/sec

More Repositories

1

outcome

Provides very lightweight outcome<T> and result<T> (non-Boost edition)
C++
658
star
2

nedmalloc

An EXTREMELY FAST portable thread caching malloc implementation written in C for multiple threads without lock contention based on dlmalloc. Optimised for x86 and x64. Compatible with C++. Can patch itself into existing binaries on Windows.
C
392
star
3

nedtries

A portable in-place bitwise binary Fredkin trie algorithm which allows for near constant time insertions, deletions, finds, closest fit finds and iteration. Is approx. 50-100% faster than red-black trees and up to 20% faster than O(1) hash tables.
C++
270
star
4

pcpp

A C99 preprocessor written in pure Python
Python
203
star
5

quickcpplib

Eliminate all the tedious hassle when making state-of-the-art C++ 14 - 23 libraries!
C
118
star
6

status-code

Proposed SG14 status_code for the C++ standard
C++
62
star
7

stl-header-heft

Measures how parsing overweight the major STLs have become
Python
52
star
8

uthash

A GIT clone of uthash.sourceforge.net, a hash table, implemented in C, supporting constant-time add/find/remove of C structures. Any structure having a unique, arbitrarily-typed key member can be hashed by adding a UT_hash_handle member to the structure and calling these macros.
C
35
star
9

ntkernel-error-category

A C++ 11 std::error_category for the NT kernel's NTSTATUS error codes
C++
33
star
10

Easyshop

An E-Commerce solution for Plone supporting a shopping basket, stock quantities, differing delivery and taxation rules based on criteria, product variants and Paypal payment processing
Python
26
star
11

static-website-activitypub

Wraps a static website generator with an ActivityPub client-to-server implementation
Python
22
star
12

mcpp

A C99 conforming preprocessor
C
20
star
13

zero-copy-socket-test

C++
13
star
14

FastDirectoryEnumerator

Enumerates very, very large directories quickly by directly using kernel syscalls. For POSIX and Windows. WARNING THIS IS OBSOLETE. USE BOOST.AFIO INSTEAD.
C++
13
star
15

kerneltest

C++14 automated code test infrastructure with permutation, fuzzing, sanitising and edge coverage
C++
11
star
16

BEurtle

TortoiseXXX plugin for the Bugs Everywhere distributed issue tracker
Python
11
star
17

automodinit

Solves the problem of forgetting to keep __init__.py files up to date
Python
10
star
18

tnfox

FOX for Tn
C++
10
star
19

boost-trunk

NO LONGER UPDATED NOW BOOST HAS MOVED TO MODULARISED GIT
C++
7
star
20

NiallsCPP11Utilities

Some C++ 11 rewrites of useful stuff from TnFOX (http://www.nedprod.com/TnFOX/)
C
7
star
21

Bugs-Everywhere-for-BEurtle

Bugs Everywhere is a β€œdistributed bugtracker” designed to complement distributed revision control systems
Python
5
star
22

VL53L3CX_rasppi

Port of the 2020 support library to Raspberry Pi for the VL53L3CX Time-of-Flight ranging sensor with advanced multi-object detection
C
5
star
23

boost-bmv-cmake

Mock up of what a bare minimum viable cmakeification of Boost would look like
C++
5
star
24

libcurl-cxx-std-networking-integration

Demonstration of libcurl integration into C++ 23 standard networking
C++
4
star
25

BEXML

Provides fast, lazy, RESTful fastcgi access to various issue (bug) trackers. Compilable into a fast binary with IronPython and PyPy for even faster access.
Python
3
star
26

ISO_POSIX_standards_stuff

Reference Implementations for my ISO and POSIX standards change proposals
C
3
star
27

HouseBuild

Tracking progress, open issues, and project milestones of my house build
3
star
28

TripleGit

The world's stupidest triplestore database
C++
2
star
29

ClamAV-Plugin-for-PKP-Open-Journal-Systems

Implements a plugin which scans uploaded documents for viruses
PHP
2
star
30

boostdoc

A Hugo theme generating a Boost C++ Libraries documentation
CSS
1
star
31

c11-permit-object

A C11 and C++11 pthreads permit object. With adaptors for Boost.Thread and Boost.Expected
C++
1
star
32

boost-release

NO LONGER BEING UPDATED
C++
1
star
33

Oxyderkeia

Super secret R&D project
1
star
34

LiveXMLCV

An Interactive Live XML based Curriculum Vitae with XHTML output
JavaScript
1
star
35

dvb_ttusb_ned

Just enough of the TechnoTrend S-2400 Linux kernel driver to cold start a faulty tuner
C
1
star