Google Summer of Code 2026

Final report · EROFS Filesystem

EROFS

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.

lz4hc25–31%less extraction time
zstd32–35%less extraction time
lzma72–77%less extraction time; 76 s down to 18 s at 64 KiB clusters

“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.”

Gao Xiang, EROFS maintainer · 19 Oct 2026

The Patches

PATCH 0/22026-09-19cover letter

fsck.erofs: implement concurrent extraction and decompression

6 files changed, +848 −170 · includes the full benchmark results
a54dbf5PATCH 1/22026-09-19

fsck.erofs: implement concurrent directory traversal

3 files changed, +382 −116 · fsck/main.c, include/erofs/cond.h (new), include/erofs/lock.h
35330f7PATCH 2/22026-09-19

fsck.erofs: add multi-threaded decompression

4 files changed, +467 −55 · fsck/main.c, lib/data.c, lib/global.c, include/erofs/internal.h

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_task holding its parent NID, its NID, its own output path and its own copy of the directory stack, so -ELOOP detection 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 corrupted flag are protected with erofs_mutex_t.
  • A new erofs_cond_t wrapper (include/erofs/cond.h) and erofs_mutex_destroy() keep the code on erofs-utils' own primitives. Built without EROFS_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 in liberofs_global_exit(). Each worker has its own cache-line-aligned queue.
  • A per-file struct z_erofs_mt_read_ctx groups 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 then ftruncate()d to i_size so 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.

Minimum extraction time (best of 10 runs)

AlgorithmClustermasterPatch 1Patches 1+2Patch 1 gainPatch 2 gainTotal

Mean ± standard deviation (10 runs)

AlgorithmClustermasterPatch 1Patches 1+2Patch 1 gainPatch 2 gainTotal

Patch 1 gain: patch 1 against master. Patch 2 gain: patches 1+2 against patch 1. Total: patches 1+2 against master. Source: the cover letter of the final series.

Timeline

  1. [PATCH 0/2] fsck.erofs: implement concurrent extraction and decompression
  2. [PATCH 1/2] fsck.erofs: implement concurrent directory traversal
  3. [PATCH 2/2] fsck.erofs: add multi-threaded decompression
  4. Maintainer applies the series to experimental-mt-extraction
  5. Gao Xiang finalizes the series for the upstream merge into erofs-utils master