Google Summer of Code 2026
Final report · EROFS Filesystem
Multi-threaded Extraction for fsck.erofs
I made fsck.erofs check and extract EROFS images on all CPU cores instead of one. Directories are walked by a pool of worker threads, and large LZMA and DEFLATE files are decompressed in parallel batches.
- Contributor
- K S Nithurshen · @Nithurshen
- Mentors
- Xiang Gao, Yifan Zhao, Chunhai Guo
- Project
- GSoC project page · Large, 350 h
- Repository
- erofs-utils · EROFS docs
- Applied to
experimental-mt-extraction- Period
- May 2026 – November 2026
Summary
fsck.erofs is the checking tool for EROFS, the compressed read-only Linux filesystem. It checks EROFS images and can unpack them to a directory with --extract. Before this project it ran on one thread: it walked the directory tree, read each inode, decompressed each physical cluster (pcluster) and wrote the output, one item at a time. On images compressed with LZMA, decompression took most of the run time and the directory walk waited behind it.
The work is two patches that build on each other. Patch 1 runs the directory walk on a pool of traversal workers. Patch 2 adds a per-CPU decompression pool for large LZMA and DEFLATE files, where each worker writes its output straight to the right file offset.
“Thanks for your efforts on finishing our GSoC project. I've applied your patches to experimental-mt-extraction, it works, but I will finalize myself so that it could merge upstream.”
The Patches
fsck.erofs: implement concurrent directory traversal
fsck.erofs: add multi-threaded decompression
To try them, apply the series to the erofs-utils 1.9.4 release (f36cadb), which it applies to cleanly:
git clone https://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs-utils.git
cd erofs-utils
git checkout -b mt-extraction v1.9.4
git am /path/to/fsck-erofs-mt-extraction.mbox
./autogen.sh && ./configure && make
fsck/fsck.erofs --extract=/tmp/out image.erofs
How It Works
Patch 1: concurrent directory traversal
The old walk was recursive and kept its state in globals: one shared extract_path buffer that grew and shrank with the recursion, and one shared dirstack for loop detection. Threads can't share that, so each unit of work now carries its own.
- Each inode is a
struct erofsfsck_inode_taskholding its parent NID, its NID, its own output path and its own copy of the directory stack, so-ELOOPdetection still works per path. - Directory entries are queued as new tasks instead of recursive calls. One traversal worker per CPU takes tasks from the queue.
- The main thread waits on a pending-task counter until the whole tree is done, then returns the first error any worker hit.
- The hardlink table, the compression-ratio counters and the
corruptedflag are protected witherofs_mutex_t. - A new
erofs_cond_twrapper (include/erofs/cond.h) anderofs_mutex_destroy()keep the code on erofs-utils' own primitives. Built withoutEROFS_MT_ENABLED, they become no-ops and fsck runs single-threaded as before.
Patch 2: multi-threaded decompression
Parallel traversal alone doesn't help when one large LZMA file takes seconds to decompress, because one worker is stuck on it. Patch 2 spreads a single large file across all cores.
- A per-CPU pool of decompression workers starts the first time it's needed (
pthread_once) and stops inliberofs_global_exit(). Each worker has its own cache-line-aligned queue. - A per-file
struct z_erofs_mt_read_ctxgroups pclusters into batches of 8 and hands each batch to the next worker, round-robin. Batching keeps locking and thread wake-ups off the hot path. - Workers write each result to its logical offset with
pwrite(), so out-of-order completion still gives correct output. The file is thenftruncate()d toi_sizeso trailing holes are right. - Only compressed files over 128 KiB that use LZMA or DEFLATE take this path, and only when no SHA-256 digest is being computed, since a digest needs the data in order. lz4 and zstd decompress fast enough that handing them off would cost more than it saves.
Results
Extraction time with each patch, as a share of the time on current master. Best of 10 runs per configuration; three algorithms at five cluster sizes. Hosts: Acer Nitro 5 (WSL), Raspberry Pi 4 and MacBook Pro M4 Pro. Hover or focus a row for exact times.
- Patch 1 speeds up every algorithm by 23–35%, because the directory walk and per-file work now overlap across cores.
- Patch 2 is where LZMA gains most: a further 57–70% on top of patch 1. At 64 KiB clusters, extraction drops from 76.19 s to 17.83 s.
- lz4hc and zstd barely change with patch 2, as intended. They don't use the decompression pool, so patch 2 adds no overhead for them.
- Run times become more predictable. lz4hc at 8 KiB measured 7.42 ± 13.7 s on master and 3.14 ± 0.77 s with both patches.
- Output integrity. During review, the extracted tree was compared bit for bit against the original directory for every algorithm and cluster size, and all checks passed. Later benchmark rounds of the traversal and combined patches also passed all integrity checks. The cover letter for the final series reports timings only.
Minimum extraction time (best of 10 runs)
| Algorithm | Cluster | master | Patch 1 | Patches 1+2 | Patch 1 gain | Patch 2 gain | Total |
|---|
Mean ± standard deviation (10 runs)
| Algorithm | Cluster | master | Patch 1 | Patches 1+2 | Patch 1 gain | Patch 2 gain | Total |
|---|
Timeline
- [PATCH 0/2] fsck.erofs: implement concurrent extraction and decompression
- [PATCH 1/2] fsck.erofs: implement concurrent directory traversal
- [PATCH 2/2] fsck.erofs: add multi-threaded decompression
- Maintainer applies the series to experimental-mt-extraction
- Gao Xiang finalizes the series for the upstream merge into erofs-utils
master