From 15325a37675766d7ff08209d92edebcf0a1559c9 Mon Sep 17 00:00:00 2001 From: Christopher Haster Date: Wed, 31 Dec 2025 12:32:13 -0600 Subject: [PATCH] Fixed incorrect assumption that weights imply bshrub roots rbyd.weight == btree.weight does not imply rbyd is a bshrub root! This was introduced during a btrv rework, and, unfortunately, works _most_ of the time. It's extra deceptive because we eagerly collapse these degenerate roots in lfs3_btree_commit_, but we can't collapse bshrub roots! Well, not easily anyways (I guess we could convert to a btree...), but what's important is that single-entry btree nodes are possible, and relying on the weight for shrubbed roots is a weak condition. Instead, we now just check the shrub bit for shrubbed roots. We have a whole bit for this, so might as well actually use it. This isn't even the first reliance of the shrub bit in this function! --- Code changes minimal: code stack ctx before: 35148 2136 660 after: 35152 (+0.0%) 2136 (+0.0%) 660 (+0.0%) code stack ctx gbmap before: 38388 2144 776 gbmap after: 38388 (+0.0%) 2144 (+0.0%) 776 (+0.0%) code stack ctx preerase before: 38928 2168 796 preerase after: 38928 (+0.0%) 2168 (+0.0%) 796 (+0.0%) --- lfs3.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lfs3.c b/lfs3.c index ff6bf31e..8c45addb 100644 --- a/lfs3.c +++ b/lfs3.c @@ -6332,9 +6332,9 @@ static lfs3_stag_t lfs3_btree_traverse(lfs3_t *lfs3, // restart from the root? if (btrv->bid == -1 || btrv->rid >= (lfs3_srid_t)btrv->rbyd.weight - // we do this unconditionally when rbyd == root to avoid - // bshrubs falling out-of-sync - || btrv->rbyd.weight == btree->r.weight) { + // we do this unconditionally when rbyd is a shrub to avoid + // bshrub root traversals falling out-of-sync under mutation + || lfs3_rbyd_isshrub(&btrv->rbyd)) { // end of traversal? if (btrv->bid >= (lfs3_sbid_t)btree->r.weight) { return LFS3_ERR_NOENT;