From: Hengyu Liang <hengyul@cs.unc.edu>
To: slava@dubeyko.com
Cc: glaubitz@physik.fu-berlin.de, frank.li@vivo.com,
linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
stable@vger.kernel.org
Subject: Re: [PATCH] hfs: avoid reusing occupied CNIDs after deletion
Date: Tue, 27 Oct 2026 23:59:19 -0400 [thread overview]
Message-ID: <20261028035919.733823-1-hengyul@cs.unc.edu> (raw)
In-Reply-To: <e2ee251e8ad47c6f1e2faf9ed1be787eccf5215c.camel@dubeyko.com>
Hi Slava,
On Mon, 2026-10-26 at 10:20 -0700, Viacheslav Dubeyko wrote:
> I am not suggesting to change the on-disk format. All modifications
> should be in-core metadata structures only.
Sorry, I misread that.
> The algorithm only solution will be inefficient and it can hide bugs,
> anyway.
The table below is about efficiency. On bugs: in both variants below,
a lookup or walk error leaves next_id unchanged, so it can only stay
too high, never fall onto a CNID in use. Which bugs did you have in
mind?
> I am thinking about adding to the struct hfs_bnode (b-tree node) a
> special field: u32 max_cnid. [...] What do you think? Does it make
> sense for you?
Yes, it makes sense, and it works. I wrote a prototype (max_cnid
rebuilt when a node is read, raised on insert, rescanned on remove and
after a split) and compared it with the unmount walk I suggested last
time. Deleting 8000 files in KVM on v7.3 (KASAN):
unpatched max_cnid unmount walk
newest first 14 s 7.0 s 0.4 s
odd ones, then even ones
newest first 4.1 s 3.0 s 0.2 s
Both are correct: no duplicate CNID in any run, including the
threadless case from my last mail.
> If you believe that this approach will not work, please, explain your
> vision of solution in details.
The unmount walk, on a delete:
(1) do nothing unless cnid == next_id - 1 (your step (1));
(2) if cnid - 1 has a thread, set next_id = cnid;
(3) otherwise keep next_id, which is still above all CNIDs in use, and
set a flag.
At unmount, if the flag is set, hfs_mdb_close() walks the leaf nodes
once and writes max + 1 to drNxtCNID. The walk cannot run in sync_fs:
hfs_new_inode() takes a CNID before the catalog records are inserted,
so a walk there could miss that CNID and lower next_id onto it.
Your max_cnid
Pros:
- next_id was exact after every delete in every run, so drNxtCNID
on disk is right even after a crash or remount ro.
- Nothing to do at unmount.
Cons:
- A delete of next_id - 1 still visits every leaf node (about 3000
here); the per-node max only saves parsing their records.
Checking the thread of cnid - 1 first brings the first row to
0.4 s, but not the second.
- max_cnid must stay right on insert, remove, split and node read
(hooks in bnode.c and brec.c). A missed update would let next_id
fall onto a CNID in use.
Unmount walk
Pros:
- A delete never walks the catalog; the one walk at unmount costs
17 ms here (cold cache).
- Only catalog.c and mdb.c change, not the b-tree code.
Cons:
- next_id is not lowered during a mount: after deleting all 8000
files oldest first, the next file gets CNID 8016, not 16.
- After a crash or remount ro the high value stays on disk. In my
8000-file crash test drNxtCNID stayed at 8015 on the empty volume,
more than 4096 above the largest CNID, and fsck.hfs -fn asked for
a minor MDB repair.
Which do you prefer? I can turn either into the next version.
Thanks,
Hengyu
prev parent reply other threads:[~2026-10-28 3:59 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-15 11:01 Hengyu Liang
2026-10-15 19:58 ` Viacheslav Dubeyko
2026-10-16 2:31 ` Hengyu Liang
2026-10-17 22:35 ` Viacheslav Dubeyko
2026-10-19 23:29 ` Viacheslav Dubeyko
2026-10-21 15:31 ` Hengyu Liang
2026-10-21 22:26 ` Viacheslav Dubeyko
2026-10-22 12:06 ` Hengyu Liang
2026-10-22 22:40 ` Viacheslav Dubeyko
2026-10-23 17:32 ` Hengyu Liang
2026-10-26 17:20 ` Viacheslav Dubeyko
2026-10-28 3:59 ` Hengyu Liang [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=20261028035919.733823-1-hengyul@cs.unc.edu \
--to=hengyul@cs.unc.edu \
--cc=frank.li@vivo.com \
--cc=glaubitz@physik.fu-berlin.de \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=slava@dubeyko.com \
--cc=stable@vger.kernel.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
all inboxes | Powered by JetHome®