From: Zygo Blaxell Date: Sat, 14 Feb 2026 05:05:29 +0000 (-0500) Subject: bees: adjust BLOCK_SIZE_MAX_EXTENT to work around kernel bug X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b8086fb41af052bdadf35dc13382604e246dc12c;p=bees bees: adjust BLOCK_SIZE_MAX_EXTENT to work around kernel bug 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 --- diff --git a/src/bees.h b/src/bees.h index e1b8db3c..1fd86b4d 100644 --- a/src/bees.h +++ b/src/bees.h @@ -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;