Linux Btrfs filesystem development
 help / color / mirror / Atom feed
* [PATCH v4 0/6] btrfs: add per-inode compression levels in xattrs
@ 2026-08-25 13:07 koraynilay
  2026-08-25 13:07 ` [PATCH v4 1/6] btrfs: export btrfs_match_compress_type(), move it to compression.h koraynilay
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: koraynilay @ 2026-08-25 13:07 UTC (permalink / raw)
  To: Chris Mason, David Sterba
  Cc: Qu Wenruo, Zygo Blaxell, linux-btrfs, koraynilay

Add per-inode compression levels using
btrfs property set /path/to/file compression "algo:level", using the
same syntax as the compress mount option.
If set on folders, all new children will inherit the setting, while
already existing children will be unaffected.

This patch series also fixes a small bug: before, when setting
btrfs.compression, it would keep the mount option level, even if the
algo was different (!!), so with e.g. compress=zstd:15 and
btrfs.compression=zlib the data gets compressed at zlib:9 (because it
would still get clamped at the right range).
After this patch series, if the user doesn't specify a level (e.g.
"zstd") btrfs inherits the level from the mount option, while if instead
the user specifies a level it will use that (e.g. "zstd:0" would use the
default for the algorithm, and "zstd:10" would of course use level 10).

I also want to thank Zygo for helping me by explaining stuff and for
noticing this bug.

Now, there is the question of having a fix for the bug as a separate
patch to be backported or not, and there are 3 possibilities for that
(original email listing them[1]):

- Option 1:
  don't have a specific patch to be backported, keep the current
  behaviour on older kernels.

  This is the option I personally prefer[2].
  
  Pros:
  * documentation[3] can be made clear about this behaviour, telling users
    that kernels < 7.X will "support" cross-algo level specification,
    while >= 7.X won't and will only inherit the level if the algorithm is
    the same
  * won't break any existing use-case
  
  Cons:
  * new users on older kernels will encounter this bug

- Option 2:
  have a specific patch to be backported that keeps the current behaviour,
  but only if the compress= algo is the same as the btrfs.compression one,
  if they aren't, use the default for the btrfs.compression algo (e.g.
  compress=zstd:15 and btrfs.compression=zlib would compress at zlib:3
  instead of clamp(zlib, 15) = 9).
  
  Pros:
  * fixes the cross-algo bug without breaking setups that rely on level
    inheritance in a way that makes sense
  
  Cons:
  * documentation has to mention that the behaviour might be the bugged
    one or this one, depending on if the kernel has this bugfix patch
  * may break some weird use-cases, but no one should really expect the
    level to be inherited if the algorithm is different
  
- Option 3:
  have a specific patch to be backported that fixes the behaviour
  entirely, using the default level in all btrfs.compression cases, since
  levels wouldn't be supported.
  Equivalent of setting algo:0 after this patch series gets applied.
  
  Pros:
  * very simple code fix, 2 lines of compress_level = 0, while option 2
    would need an additional if to check the compress type against the
    fs_info one
  
  Cons:
  * documentation has to mention that the behaviour might be the bugged
    one or this one, depending on if the kernel has this bugfix patch
  * breaks all use-cases relying on level inheritance from the mount
    option to the xattr

Changes in this v4:
* remove the single patch for the bug, as per [2]
* reduce code duplication by putting the level parsing logic after the
  algorithm type logic, using a level_pos variable to indicate the
  position of the ':' instead of having the same exact code for each
  algo.
* add btrfs_compress_typelevel2str() helper
* fix btrfs.compression not being preserved when *any* chattr operation
  gets executed changed

[1]: https://lore.kernel.org/linux-btrfs/DKJZQAFIRW7H.3KE8DKWO5E3TV@gmail.com
[2]: https://lore.kernel.org/linux-btrfs/DKLRY9Q5SEI3.VUDASVYPW9MY@gmail.com
[3]: https://github.com/kdave/btrfs-progs/pull/1152


koraynilay (6):
  btrfs: export btrfs_match_compress_type(), move it to compression.h
  btrfs: also validate compression levels in
    btrfs_compress_is_valid_type()
  btrfs: add per-inode compression levels in xattrs
  btrfs: support inheritance for per-inode compression levels
  btrfs: add btrfs_compress_typelevel2str() helper
  btrfs: preserve btrfs.compression when setting inode flags

 fs/btrfs/btrfs_inode.h |  1 +
 fs/btrfs/compression.c | 55 +++++++++++++++++++++++++++++--
 fs/btrfs/compression.h |  5 ++-
 fs/btrfs/inode.c       | 10 ++++++
 fs/btrfs/ioctl.c       | 13 +++++++-
 fs/btrfs/props.c       | 73 +++++++++++++++++++++++++++++-------------
 fs/btrfs/props.h       |  9 ++++++
 fs/btrfs/super.c       |  8 -----
 8 files changed, 139 insertions(+), 35 deletions(-)


base-commit: 818bebeb63dd6bf5f4e07e145f6cdbace520a34c
-- 
2.55.0


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2026-08-25 13:08 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-25 13:07 [PATCH v4 0/6] btrfs: add per-inode compression levels in xattrs koraynilay
2026-08-25 13:07 ` [PATCH v4 1/6] btrfs: export btrfs_match_compress_type(), move it to compression.h koraynilay
2026-08-25 13:07 ` [PATCH v4 2/6] btrfs: also validate compression levels in btrfs_compress_is_valid_type() koraynilay
2026-08-25 13:07 ` [PATCH v4 3/6] btrfs: add per-inode compression levels in xattrs koraynilay
2026-08-25 13:07 ` [PATCH v4 4/6] btrfs: support inheritance for per-inode compression levels koraynilay
2026-08-25 13:07 ` [PATCH v4 5/6] btrfs: add btrfs_compress_typelevel2str() helper koraynilay
2026-08-25 13:07 ` [PATCH v4 6/6] btrfs: preserve btrfs.compression when setting inode flags koraynilay

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox