]> git.hungrycats.org Git - bees/commitdiff
thread: add workaround-clone-logical-ino = auto
authorZygo Blaxell <bees@furryterror.org>
Thu, 24 Sep 2026 02:12:49 +0000 (22:12 -0400)
committerZygo Blaxell <bees@furryterror.org>
Tue, 6 Oct 2026 05:51:40 +0000 (01:51 -0400)
The clone/LOGICAL_INO kernel bug needs LOGICAL_INO walking the same live
trees that dedupe is modifying.  A LOGICAL_INO call with the COMMIT_ROOT
flag walks the commit root instead, so once the kernel has shown it
honours the flag the serialization only costs throughput.

Add an "auto" value.  It starts serialized like "yes", and logical_ino()
switches locking off once resolve.commit-root = yes and a call with the
flag has succeeded (commit_root_confirmed()).  The serialization stays
if resolve.commit-root = no, while support is unknown, and when the
kernel is proven not to support the flag.

The option is now loaded by BeesContext next to resolve.commit-root,
since logical_ino() needs the mode, instead of being applied once in
bees_main.  The kind table entry becomes Kind_Free because the value is
no longer a plain boolean.  The default stays "yes".

Assisted-by: Claude-Code:claude-opus-5-5
docs/config-file.md
src/bees-config-v2.cc
src/bees-context.cc
src/bees.cc
src/bees.h
test/config-parse.cc

index 2e6de87f93e40ce5c1fbf4636afc9abe983208f0..df37b9939704dce57e262c7da9111dd54c4cc41e 100644 (file)
@@ -723,6 +723,7 @@ The `[thread]` section sets how many worker threads bees runs and how aggressive
 
   * `yes` (the default) prevents any thread from running dedupe while another thread is running `LOGICAL_INO`, and vice versa.  The two ioctls never overlap.
   * `no` removes the restriction: any thread may run either operation at any time.  This is faster under high concurrency but unsafe on kernels affected by the bug.
+  * `auto` starts like `yes`, and switches to `no` once a `LOGICAL_INO` call has successfully walked the commit root (see `resolve.commit-root`).  The bug needs `LOGICAL_INO` to walk the same trees dedupe is modifying, and commit-root walks do not.  The restriction stays in place if `resolve.commit-root = no`, or if the kernel does not support commit-root walks.
 
   Leave this enabled unless you have confirmed your kernel is not affected.
 
index 889a327ebac3c8832afeadc2be555d18cba37f18..b491ca370bd6a335348c2041099a7d5a99da4fe9 100644 (file)
@@ -40,7 +40,9 @@ static const char bees_config_v2[] = R"--v2-config--(
         # bug triggered when both run concurrently.  yes: no thread runs
         # dedupe while another runs LOGICAL_INO (and vice versa).  no: any
         # thread may run either operation at any time (faster, but unsafe
-        # on affected kernels).
+        # on affected kernels).  auto: yes until a LOGICAL_INO call using
+        # the commit root succeeds, then no; stays yes if
+        # resolve.commit-root = no or the kernel lacks the flag.
         workaround-clone-logical-ino = yes
 
 
index c668d8b95b6acc163f37a591bdfc33ed69052a07..a8a6506c3719537beddb2bb46ed9ca7837c5896e 100644 (file)
@@ -1013,6 +1013,22 @@ BeesContext::logical_ino(const uint64_t logical, const bool all_refs)
                BEESLOGWARN("LOGICAL_INO commit-root resolution rejected by this kernel, using live-root walks");
        }
 
+       // thread.workaround-clone-logical-ino = auto:  the kernel bug needs
+       // LOGICAL_INO walking the same live trees that dedupe is modifying.
+       // Once a walk with the COMMIT_ROOT flag has succeeded, every later
+       // walk uses the commit root too, so the serialization can go.  Until
+       // then (support unknown, unsupported, or resolve.commit-root = no) it
+       // stays.  The check runs before the next call rather than after the
+       // confirming one, so one extra call may still be serialized.
+       THROW_CHECK0(runtime_error, m_workaround_clone_logical_ino_auto);
+       if (*m_workaround_clone_logical_ino_auto && *m_resolve_commit_root
+                       && !m_workaround_clone_logical_ino_released.load()
+                       && BtrfsIoctlLogicalInoArgs::commit_root_confirmed()
+                       && !m_workaround_clone_logical_ino_released.exchange(true)) {
+               MultiLocker::enable_locking(false);
+               BEESLOGINFO("LOGICAL_INO commit-root resolution confirmed, no longer serializing dedupe against it [thread.workaround-clone-logical-ino]");
+       }
+
        return rv;
 }
 
@@ -1327,6 +1343,23 @@ BeesContext::set_config(const Innie& bconfig)
        BEESLOGINFO("resolving refs against the "
                << (*m_resolve_commit_root ? "commit root" : "live root")
                << " [resolve.commit-root]");
+
+       // Workaround for the logical-ino-vs-clone kernel bug:  serialize the
+       // dedupe ioctl against LOGICAL_INO.  "auto" starts serialized and lets
+       // logical_ino() lift it once a commit-root walk has succeeded.
+       BEESTRACE("loading thread.workaround-clone-logical-ino");
+       const auto workaround_clone_logical_ino = m_config->get("thread.workaround-clone-logical-ino", [](const string &str) -> optional<bool> {
+               if (str == "auto") {
+                       return nullopt;
+               }
+               return bees_parse_bool(str);
+       });
+       m_workaround_clone_logical_ino_auto = !workaround_clone_logical_ino;
+       MultiLocker::enable_locking(workaround_clone_logical_ino.value_or(true));
+       BEESLOGINFO("thread.workaround-clone-logical-ino = "
+               << (!workaround_clone_logical_ino ? "auto" : *workaround_clone_logical_ino ? "yes" : "no")
+               << " [thread.workaround-clone-logical-ino]");
+
 }
 
 void
index 319d64fe7d876d25bbc58d863d6bbb2a67cd22bf..7ff53de1e7f8f98907e38960f824ac58dde65dfa 100644 (file)
@@ -714,12 +714,6 @@ bees_main(int argc, char *argv[])
                        bc->get_config().get("state.point.defer", bees_parse_bool));
        }
 
-       // Workaround for the logical-ino-vs-clone kernel bug: serialize the
-       // dedupe ioctl against LOGICAL_INO unless the operator opts out.
-       const bool workaround_clone_logical_ino = bc->get_config().get("thread.workaround-clone-logical-ino", bees_parse_bool);
-       BEESLOGINFO("thread.workaround-clone-logical-ino = " << (workaround_clone_logical_ino ? "yes" : "no") << " [thread.workaround-clone-logical-ino]");
-       MultiLocker::enable_locking(workaround_clone_logical_ino);
-
        // Start crawlers
        bc->start();
 
index e271a44caacab81385dca2002a5ed3f8dd7f2a51..3173bf8143db43abcd54261aa525eb00051aae0f 100644 (file)
@@ -1397,6 +1397,12 @@ private:
        /// resolution.  Empty until set_config() loads it; reading it before
        /// then throws rather than silently picking a side.
        optional<bool>                                  m_resolve_commit_root;
+       /// thread.workaround-clone-logical-ino = auto:  keep the dedupe vs
+       /// LOGICAL_INO serialization only until a commit-root walk succeeds.
+       /// Empty until set_config() loads it.
+       optional<bool>                                  m_workaround_clone_logical_ino_auto;
+       /// Set once the auto workaround has been switched off.
+       atomic<bool>                                    m_workaround_clone_logical_ino_released{false};
 
        LRUCache<BeesResolveAddrResult, BeesAddress>    m_resolve_cache;  ///< Caches LOGICAL_INO results.
 
index 35ffc7566c0da9b1f9dee53cceb72e46733276e7..f55dc5e91ee2004f2a61dd96bb39b1a7b674f065 100644 (file)
@@ -181,7 +181,7 @@ static const KindRule s_kind_by_name[] = {
        { "verify-delay",               Kind_Count    },
        { "version",                    Kind_Free     },
        { "workaround-btrfs-send",      Kind_Bool     },
-       { "workaround-clone-logical-ino", Kind_Bool   },
+       { "workaround-clone-logical-ino", Kind_Free   },
        { "writeback-fsync",            Kind_Bool     },
        { "writeback-rate-max",         Kind_Size     },
        { "writeback-time",             Kind_Duration },