Skip to content

Commit 3a17a4d

Browse files
author
Zygo Blaxell
committed
tempfile: make sure FS_COMPR_FL stays set
btrfs will set the FS_NOCOMP_FL flag when all of the following are true: 1. The filesystem is not mounted with the `compress-force` option 2. Heuristic analysis of the data suggests the data is compressible 3. Compression fails to produce a result that is smaller than the original If the compression ratio is 40%, and the original data is 128K long, then compressed data will be about 52K long (rounded up to 4K), so item 3 is usually false; however, if the original data is 8K long, then the compressed data will be 8K long too, and btrfs will set FS_NOCOMP_FL. To work around that, keep setting FS_COMPR_FL and clearing FS_NOCOMP_FL every time a TempFile is reset. Signed-off-by: Zygo Blaxell <bees@furryterror.org>
1 parent 4039ef2 commit 3a17a4d

1 file changed

Lines changed: 13 additions & 11 deletions

File tree

src/bees.cc

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,19 @@ BeesTempFile::resize(off_t offset)
502502
// Count time spent here
503503
BEESCOUNTADD(tmp_resize_ms, resize_timer.age() * 1000);
504504

505+
// Modify flags - every time
506+
// - btrfs will keep trying to set FS_NOCOMP_FL behind us when compression heuristics identify
507+
// the data as compressible, but it fails to compress
508+
// - clear FS_NOCOW_FL because we can only dedupe between files with the same FS_NOCOW_FL state,
509+
// and we don't open FS_NOCOW_FL files for dedupe.
510+
BEESTRACE("Getting FS_COMPR_FL and FS_NOCOMP_FL on m_fd " << name_fd(m_fd));
511+
int flags = ioctl_iflags_get(m_fd);
512+
flags |= FS_COMPR_FL;
513+
flags &= ~(FS_NOCOMP_FL | FS_NOCOW_FL);
514+
BEESTRACE("Setting FS_COMPR_FL and clearing FS_NOCOMP_FL | FS_NOCOW_FL on m_fd " << name_fd(m_fd) << " flags " << to_hex(flags));
515+
ioctl_iflags_set(m_fd, flags);
516+
517+
// That may have queued some delayed ref deletes, so throttle them
505518
bees_throttle(resize_timer.age(), "tmpfile_resize");
506519
}
507520

@@ -543,17 +556,6 @@ BeesTempFile::BeesTempFile(shared_ptr<BeesContext> ctx) :
543556
// Add this file to open_root_ino lookup table
544557
m_roots->insert_tmpfile(m_fd);
545558

546-
// Set compression attribute
547-
BEESTRACE("Getting FS_COMPR_FL on m_fd " << name_fd(m_fd));
548-
int flags = ioctl_iflags_get(m_fd);
549-
flags |= FS_COMPR_FL;
550-
551-
// Clear NOCOW because it conflicts with COMPR, and NOCOW could be set on the root subvol
552-
flags &= FS_NOCOW_FL;
553-
554-
BEESTRACE("Setting FS_COMPR_FL on m_fd " << name_fd(m_fd) << " flags " << to_hex(flags));
555-
ioctl_iflags_set(m_fd, flags);
556-
557559
// Count time spent here
558560
BEESCOUNTADD(tmp_create_ms, create_timer.age() * 1000);
559561

0 commit comments

Comments
 (0)