Skip to content

Commit

Permalink
lxd/storage/drivers/driver/btrfs/volumes: Enable compression on block…
Browse files Browse the repository at this point in the history
… raw files

This has the side effect of reducing the maximum extent size for compressible extents and reduces space waste
when partially rewriting extents that can cause the block file to end up exceeding the BTRFS volume quota.

Fixes canonical#9124

Signed-off-by: Thomas Parrott <thomas.parrott@canonical.com>
  • Loading branch information
tomponline committed Dec 3, 2021
1 parent 68cf3d0 commit 41775f7
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions lxd/storage/drivers/driver_btrfs_volumes.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,23 @@ func (d *btrfs) CreateVolume(vol Volume, filler *VolumeFiller, op *operations.Op
if err != nil {
return err
}

// Create empty file so we can set the compression property on it.
f, err := os.OpenFile(rootBlockPath, os.O_RDWR|os.O_CREATE, 0600)
if err != nil {
return errors.Wrapf(err, "Failed to open %s", rootBlockPath)
}
f.Close()

// Use lzo as fastest, this will also reduce the maximum extent size for compressed extents from
// 128MiB to 128KiB. Extents are immutable so when blocks are written to they end up in new extents
// and the old ones remains until all of its data is dereferenced or rewritten. These old extents
// are counted in the quota, and so by using smaller extents this reduces the wasted and avoids
// the disk image from reaching the subvolume quota.
_, err = shared.RunCommand("btrfs", "property", "set", rootBlockPath, "compression", "lzo")
if err != nil {
return err
}
}

err = d.runFiller(vol, rootBlockPath, filler)
Expand Down

0 comments on commit 41775f7

Please sign in to comment.