mateusz@systems ~/book/filesystem-fundamentals $ cat chapter.md

Chapter 1

Filesystem Fundamentals

Filesystems are the primary interface for storing and accessing data, and their behavior shapes the performance and reliability of everything built on them. This chapter covers the semantics every Linux filesystem shares and one local implementation, ZFS; Network & Distributed Filesystems takes the remote case.

# Chapter Sections

Filesystem Primitives for Systems Software

Atomic rename, unlink with open file descriptors, O_TMPFILE, file locking (flock vs fcntl), and sparse files. POSIX operations that reliable software depends on.

IO Modes: Buffered vs Direct IO

Understanding buffered IO, direct IO (O_DIRECT), synchronous IO flags (O_SYNC, fsync), and how different filesystems handle these modes.

The Linux Page Cache

How the page cache works, read-ahead mechanisms, dirty page writeback, and memory reclaim. Essential for understanding Linux filesystem performance.

Memory-Mapped Files

How mmap() works, its relationship to the page cache, when writes actually reach disk, and mmap coherence across local and network filesystems.

ZFS: A Modern Local Filesystem

End-to-end checksumming, copy-on-write architecture, integrated RAID, and snapshots. Understand ZFS's unique features, RAM requirements, and when to choose it over traditional filesystems.

Deep Dive: ZFS recordsize

What recordsize controls, compression interaction, workload matching, performance measurement, and code walkthrough.

Synchronization Guarantees

Coordinating concurrent access across processes on one host. POSIX semantics, advisory and mandatory locking, and what the kernel does and does not serialize for you.

Resiliency Guarantees

Surviving crashes, power loss, and corruption. Journaling, copy-on-write, fsync semantics, and checksumming.

Performance Characteristics

Block allocation, metadata overhead, caching strategies, and IO patterns on local storage.

Filesystem Hacks

Battle-tested techniques: squashfs on NFS, tmpfs for performance testing, loop devices, bind mounts, sparse files, and FUSE. Unconventional approaches that solve real problems.

Observability and Debugging

Device and pool statistics with iostat, blktrace, and zpool iostat, plus eBPF/bpftrace scenarios. Telling a slow device from a stalled writeback from an application waiting on its own fsync.