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>
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;