From: Gao Xiang <xiang@kernel.org>
To: Chris Ayoub <cayoub@openai.com>
Cc: linux-erofs@lists.ozlabs.org
Subject: Re: [PATCH] rebuild: prevent quadratic snapshot merges on wide directories
Date: Mon, 10 Aug 2026 08:18:45 +0800 [thread overview]
Message-ID: <ankY5UFLlWbKkNyd@XiangdeMacBook-Pro.local> (raw)
In-Reply-To: <20260809-rebuild-wide-directory-index-v1-1-ac8b7bce3edd@openai.com>
Hi Chris,
On Sun, Aug 09, 2026 at 05:44:08PM -0400, Chris Ayoub wrote:
> Directory entry merging currently performs a linear search of the
> destination directory for each source entry. Repeating this operation
> for wide directories makes snapshot rebuilding quadratic.
>
> Add a temporary hashmap keyed by the parent inode and entry name during
> rebuild. Use the index to find existing children while preserving the
> existing merge and replacement behavior, and release it when rebuilding
> finishes.
>
> In the original reproducer, merging 129 layers containing approximately
> 2.4 million entries did not finish after 1195 seconds. With the index,
> the same merge completed in 1.40 seconds. The widest directories
> contained 65,212 and 83,318 entries.
>
> Assisted-by: Codex:gpt-5
> Signed-off-by: Chris Ayoub <cayoub@openai.com>
> ---
> Snapshot rebuild currently performs a linear directory search for every
> entry being merged. This becomes prohibitively expensive for container
> images with very wide directories.
>
> The patch adds a temporary rebuild-only hashmap keyed by parent inode and
> entry name. It preserves the existing merge and replacement behavior and
> releases the index after all source trees have been loaded.
>
> The original workload merged 129 layers containing approximately 2.4
> million entries. The unmodified rebuild did not finish after 1195 seconds;
> with the index, it completed in 1.40 seconds. The widest directories had
> 65,212 and 83,318 entries.
>
> Validation against current dev (v1.9.3) on arm64 Ubuntu 24.04:
>
> - Full build with LZ4, LZMA, FUSE, and Zstd enabled
> - make check
> - Byte-identical output versus unmodified v1.9.3 for file replacement,
> whiteout and opaque-directory handling, and an 8,000-entry directory
> - Extracted-tree checks for replacement, whiteout, and opaque semantics
> - 8,000-entry local rebuild: 0.23 seconds before, 0.01 seconds after
Yes, it's a known issue, but could you avoid using `hashmap` in
erofs-utils (we could just use `struct list_head hash[xxx] instead.`).
I'd like to get rid of `hashmap` since it's out of git codebase and
the license is GPL only.
Thanks,
Gao Xiang
prev parent reply other threads:[~2026-08-10 0:18 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-09 21:44 [PATCH] rebuild: prevent quadratic snapshot merges on wide directories Chris Ayoub via B4 Relay
2026-08-10 0:18 ` Gao Xiang [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ankY5UFLlWbKkNyd@XiangdeMacBook-Pro.local \
--to=xiang@kernel.org \
--cc=cayoub@openai.com \
--cc=linux-erofs@lists.ozlabs.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox