]> git.hungrycats.org Git - bees/commitdiff
bees: adjust BLOCK_SIZE_MAX_EXTENT to work around kernel bug
authorZygo Blaxell <bees@furryterror.org>
Sat, 14 Feb 2026 05:05:29 +0000 (00:05 -0500)
committerZygo Blaxell <bees@furryterror.org>
Sat, 14 Feb 2026 05:23:07 +0000 (00:23 -0500)
In kernel commit 24542bf7ea5e4fdfdb5157ff544c093fa4dcb536 ("btrfs:
limit fallocate extent reservation to 256MB"), the maximum size of a
prealloc extent is set to 256MB.  This exceeds BTRFS_MAX_EXTENT_SIZE,
which is 128MB.

This causes some problems with parts of bees code which guard against
problems that arise when metadata is corrupted.  One manifestation of
that problem is a potential infinite (or very large finite) loop, caused
by the extent mapping code repeatedly trying to compute a dedupe solution
for a >128M extent, but being unable to do so because it is interrupted
when it hits the self-imposed 128M extent size limit.  This may be the
cause of issues such as [#325](https://github.com/Zygo/bees/issues/325).

Since the kernel bug is 14 years old, it's de facto part of the
filesystem spec now.  Increase the limit to the largest expected size
of btrfs extents.

Signed-off-by: Zygo Blaxell <bees@furryterror.org>
src/bees.h

index e1b8db3cdb79c83501cb618ddf929d4aa4ce03f8..1fd86b4d545325c3884dd4b42c3ddbc00eff4a28 100644 (file)
@@ -44,9 +44,11 @@ const off_t BLOCK_SIZE_MAX_EXTENT_SAME = 4096 * 4096;
 const off_t BLOCK_SIZE_MAX_COMPRESSED_EXTENT = 128 * 1024;
 
 // Maximum length of any extent in bytes
-// except we've seen 1.03G extents...
-// ...FIEMAP is slow and full of lies
-const off_t BLOCK_SIZE_MAX_EXTENT = 128 * 1024 * 1024;
+// Kernel commit 24542bf7ea5e4fdfdb5157ff544c093fa4dcb536
+// ("btrfs: limit fallocate extent reservation to 256MB")
+// introduces a bug where prealloc extents can be 256M long
+// instead of BTRFS_MAX_EXTENT_SIZE, i.e. 128M.
+const off_t BLOCK_SIZE_MAX_EXTENT = 256 * 1024 * 1024;
 
 // Masks, so we don't have to write "(BLOCK_SIZE_CLONE - 1)" everywhere
 const off_t BLOCK_MASK_CLONE = BLOCK_SIZE_CLONE - 1;