]> git.hungrycats.org Git - bees/commitdiff
extent-layer: skip hash table refs quietly in the block map
authorZygo Blaxell <bees@furryterror.org>
Sat, 10 Oct 2026 23:04:50 +0000 (19:04 -0400)
committerZygo Blaxell <bees@furryterror.org>
Sun, 11 Oct 2026 00:48:00 +0000 (20:48 -0400)
The hash table file is blacklisted so that bees never dedupes it, and
block_map_fetch skips every blacklisted ref.  The skip logs a full extent
dump saying the crawler should not have reached the extent, which is true
of a temp file (the transid floor keeps the crawler off those) but not of
beeshash.dat, whose extents the crawler reaches like any other.

Remember the hash table's file id when it is blacklisted, and skip its
refs with their own counter, block_map_ref_hashtable, before the temp
file trap.

Assisted-by: Claude-Code:claude-opus-5-5
docs/event-counters.md
src/bees-context.cc
src/bees-extent-layer.cc
src/bees-hash.cc
src/bees.h

index 815ab7a1a653bd50056710ab5b9598e2f8e99687..3f7d0fcbab5b4f0c74c48ebb9fa5cb21c06d046a 100644 (file)
@@ -83,7 +83,8 @@ The `block` event group consists of operations related to reading data blocks fr
 
  * `block_bytes`: Number of data bytes read.
  * `block_hash`: Number of block hashes computed.
- * `block_map_ref_tempfile`: A data ref was excluded from block map coverage because it points into a file on bees's blacklist, which includes its own temporary files.  Temp files are recycled, so the data at such a ref may already belong to an unrelated write; it is not hashed.
+ * `block_map_ref_hashtable`: A data ref was excluded from block map coverage because it points into bees's hash table file.  The hash table is not deduplicated.
+ * `block_map_ref_tempfile`: A data ref was excluded from block map coverage because it points into a file on bees's blacklist (other than the hash table), which includes its own temporary files.  Temp files are recycled, so the data at such a ref may already belong to an unrelated write; it is not hashed.
  * `block_map_ref_unopenable`: A data ref was excluded from block map coverage because its file could not be opened — typically a ref in a deleted file or snapshot that lingers in the ref list until the last open fd closes or the subvol cleaner runs.  Blocks covered only by such refs are classified as unreachable.
  * `block_ms`: Total time reading data blocks.
  * `block_read`: Number of data blocks read.
index 3832d306e0e85120777b62dd9f8f16e11df52b6a..e8873e2b9f8666f3394ca72d4653abed357bb06e 100644 (file)
@@ -1963,6 +1963,21 @@ BeesContext::blacklist_erase(const BeesFileId &fid)
        m_blacklist.erase(fid);
 }
 
+void
+BeesContext::blacklist_insert_hash_table(const BeesFileId &fid)
+{
+       blacklist_insert(fid);
+       unique_lock<mutex> lock(m_blacklist_mutex);
+       m_hash_table_fid = fid;
+}
+
+bool
+BeesContext::is_hash_table_file(const BeesFileId &fid) const
+{
+       unique_lock<mutex> lock(m_blacklist_mutex);
+       return !!m_hash_table_fid && fid == m_hash_table_fid;
+}
+
 bool
 BeesContext::is_blacklisted(const BeesFileId &fid) const
 {
index e6cb9db9a669c590c6744252c294f2c8fd7f08da..7ca5796028569029db7b11bb3bf8f4b625f56b6f 100644 (file)
@@ -672,6 +672,13 @@ BeesBtrfsExtentLayer::block_map_fetch(BeesBtrfsExtentNode &node,
                // blacklist, so skip those refs instead of hashing them: they
                // contribute no data coverage and pass 2 never preads them.
                if (m_ctx.is_blacklisted(BeesFileId(ref.root(), ref.inum()))) {
+                       // The hash table is blacklisted too, but it is not a temp
+                       // file: its extents are ordinary and the crawler reaches
+                       // them normally.  Skip without hashing it.
+                       if (m_ctx.is_hash_table_file(BeesFileId(ref.root(), ref.inum()))) {
+                               BEESCOUNT(block_map_ref_hashtable);
+                               continue;
+                       }
                        // Reaching here means the transid floor did not keep the
                        // crawler off this extent, so say so loudly with the whole
                        // extent rather than incrementing a counter nobody reads.
index 2822b9e1b50e59c892692d44d8e9c62580076fce..343ba1a90d92b0cebde5b20ab60edff8d4741c46 100644 (file)
@@ -909,7 +909,7 @@ BeesHashTable::BeesHashTable(shared_ptr<BeesContext> ctx, string filename, off_t
                // If Hash is a btrfs, Root must be the same one
                if (root_info.fsid() != hash_info.fsid()) return;
                // Hash is on the same one, blacklist it
-               m_ctx->blacklist_insert(BeesFileId(m_fd));
+               m_ctx->blacklist_insert_hash_table(BeesFileId(m_fd));
        });
 }
 
index bab9f013dbbc40e2c6cf1f765cdd530b63801919..7b828c45fe3d8413e79729cb2aabe87cbf84d020 100644 (file)
@@ -1597,6 +1597,7 @@ private:
 
        mutable mutex                                   m_blacklist_mutex;
        set<BeesFileId>                                 m_blacklist;  ///< Files excluded from deduplication.
+       BeesFileId                                      m_hash_table_fid;  ///< The hash table file, if on this filesystem.
        mutable mutex                                   m_temp_transid_mutex;
        /// Earliest transid at which each live temp file materialized data.
        /// Empty when no temp file currently holds data.
@@ -1805,6 +1806,10 @@ public:
        void blacklist_erase(const BeesFileId &fid);
        /// Return true if @p fid is on the blacklist.
        bool is_blacklisted(const BeesFileId &fid) const;
+       /// Blacklist @p fid and remember it as the hash table file.
+       void blacklist_insert_hash_table(const BeesFileId &fid);
+       /// Return true if @p fid is the hash table file.
+       bool is_hash_table_file(const BeesFileId &fid) const;
 
        /// Record that temp file @p fid materialized data at @p transid.
        /// Idempotent: the first transid recorded since the last reset wins,