Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.221.43 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796293163; b=wM3nFUI5VoofCYji3KSznlgMAKoMQ+4S83t76Knihl/YQTZhoHwwfUeu39mRgajNlHuo msaL2vwpFfiPHyI+2iLvT5I2+XuEs3tNE3U3tJRINZdWzxR9FbuGWh90QBfWtmOWPUQNh wNmR1lV8V+Jt/haCeVY2L1alWP89T1nk0ZLPysTzR4uBFLzQYv6jkApM1HW3vNbbL3hWA s1cOGgyK9/WRs2isgjvLod0QOAzv00XTKug5N/cRFE5bVrxLHSUtn7p95u51AI7SJ+xTC r5/LZkHspvhSyhkLiQQiD3K0r6l8s3xhf/LK+mONsPb1C5DUgaus5qJvzQw93XTIkMA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796293163; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-ID:X-Mailer:MIME-Version: Content-Transfer-Encoding; bh=lwXO2pWBwZVoIcWPUyFVU4SxkexRrdvPa4wf3Lt54a8=; b=zER9q0lxeECHVcQg5GuyKceZLxh7tLL7mj8JifldmQVRmLbLD7BBSMiIaQX52QqVIKvy MJBEdF8S4PPpUyT6Mv7cWd95c20vsQmy4aO0wZmV6bOnIRTzcszeegAxmdzsfEZ5tPh4o zvQdOh682t67NVxasjo9+/Px30dQCjt472Rw+wAXxJ5CU4NSYRHc249rEMQyw0UNfAUcZ G7JyE55Y0BZqOHmzNtN5l0lB7cqHiV+VrNzoAmdL2DUS/IsEe4ERXDMzq3OR9EYwX87Jt FQ7iJd6F9JAC0JESCwuAEUTcBxcKviVkHba1ZGGALHLFRHbybVhqJdPu2O8di0TPflw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b="vpW/ezkd"; arc=none smtp.remote-ip=209.85.221.43 Received: from mail-wr1-f43.google.com (mail-wr1-f43.google.com [209.85.221.43]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B731E606A332 for ; Thu, 3 Dec 2026 10:19:22 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org B731E606A332 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=vpW/ezkd Received: by mail-wr1-f43.google.com with SMTP id ffacd0b85a97d-491f34b4e0fso6286046f8f.2 for ; Thu, 03 Dec 2026 02:19:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796293161; x=1796897961; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=lwXO2pWBwZVoIcWPUyFVU4SxkexRrdvPa4wf3Lt54a8=; b=vpW/ezkd93HZfS9mr7EUcjwiCUrun24iyMZZBdjJiMpaYskfd8tKxKvx08NfpK17ke b43M/0wwRN9XWn1a72ooH+GKGHNjhqoYBxYO2GOxWeKv54ZmS/VcqKTetCWoWmEZpsTu nbNWmF1RUCrmgydwMa78R8xklZDh16MChIafeT6BIdcqSVfEhH8EQvcsc91Tsv55m5p1 drCcAilz0Mu52JSDCUZu7+d414Q7q9eX/vL44Hur06TgswrS7QIWbM3pTCL3lN1mwCh4 BToDzo2hFloEnbq9mSy8lR04UlWunIh+/xfkLZaiJrYj9mmyfcoCic0rr2gqCEe/xqeg 39IQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796293161; x=1796897961; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=lwXO2pWBwZVoIcWPUyFVU4SxkexRrdvPa4wf3Lt54a8=; b=ApGmPVcKqi8pbL0VmwzTHl/P+VXETLrX1r/5lhXZAHyhQmbtjcD19P4Owin1MkQpPD +8N+mxRQnQTI+y8Ld6RISO5CXqc+6VPSuo2LqT5W7A4NswC7OXuNcsb675jYfIRIspM6 V/j3dr+S/sx6sAkEM8KZzrg2OMLBThaSt6YpGvEm9UydIh21yMSF2WHgUiayqiEhNZ5R w+j2/OF67f+hAkBo44qqXNm/qXlUc9y51UXwV2qho1lvOcJyUxHSGeC0IOhXljlRIqNN I2V5rZTcFbGv+CMxOgsLYzkqt76rQhHGspqkUxqqEb6DZA5HwyiPoY7C5VE0xcHrtPSn 8ARA== X-Forwarded-Encrypted: i=1; AL+hErH6bLKgiU6bpIid+A/RZaxD4LtU/4sf5EjzrAe3FlCCR8zN6pYXyPRetp/KfqKdOrr+kSpifm9Nchkilg==@vger.kernel.org X-Gm-Message-State: APuU4Z8Z5EwROmuIIJQZztGdUISRm9ookys3T1fWFVUty4nOJAakvc3Q TDByps2StaZs+klc0bxMMqo3/4W6qlFmPgGSGaTOihgVvj8yWWtgC4nH X-Gm-Gg: AZFdTZdGEi3yxcaNgL0wWCU3tIwWCP7Gnshum1NtbvlRp9DIuQe87qgVYnsQ+eiWwuK 3HMcXWljYbf6AOdzTTvtQuJhCUs30Ydr/UeYXOc0Ojz+NbLUS86BwvidICp8XbDJQW4ru1rsmYL xbv2xDi3tGWwUBMtd/wla6Y8RqKi8+/zsSFJWlZNripCsR/52ixD6RuIgV3d7O6eufi35KuqFxT BJYVOAv9p4tZZv70IcKPMds9ZS5sgpqZylLn1MYr5J1/uTfaromc5fAvQtF4bXIKcgMn0JorawQ mC0boqDt4ODWjWkZEj6FWYhvXkHHCjpf2hxoqMGaw5k5n8xTX6epvVf5941OvzP89JVPvpS485a d2BVZNxQ882/vjMwR4InwpW5PhTiY/zRsmpRzO3p2UmUTogNm1eUPLwkZMkrvKdYNcHMFP4xusV +0MSB0gUhF74O3ydbuNXwjLHjowOKWiTqTXn84DP93enJYHjuflnFa7pYel/YLyN0hoQ3ayTVTV TGlAgEuqY7BF61ofGiRKgUmThu/7eSBDxTtdb+Dxc0pb79BmXNq6VlNg20naIbLL0p0O7HXCHNb YDeC+EKYRpX1BCMgkKEBx+2j X-Received: by 2002:a05:6000:1a8f:b0:4ae:43e9:da61 with SMTP id ffacd0b85a97d-4ae43e9daa2mr80560801f8f.4.1796293160757; Thu, 03 Dec 2026 02:19:20 -0800 (PST) Received: from infinity ([2001:b07:5d26:7a6a:365a:60ff:fe0d:cfc6]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4ab69bf630esm85402565f8f.16.2026.12.03.02.19.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Dec 2026 02:19:20 -0800 (PST) From: koraynilay To: David Sterba Cc: Chris Mason , Qu Wenruo , Zygo Blaxell , linux-btrfs@vger.kernel.org, koraynilay Subject: [PATCH v6 RESEND 0/6] btrfs: add per-inode compression levels in xattrs Date: Thu, 3 Dec 2026 11:18:58 +0100 Message-ID: <20261203101904.204251-1-koray.fra@gmail.com> X-Mailer: git-send-email 2.56.0 X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 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 Changes in v5: * this is exactly the same patch series as v4, but with merge conflicts caused by Commit e8a0095c7df170 ("btrfs: preserve the compression property when other inode flags change") fixed Changes in v6: * switch from kmemdup_nul() to a stack-based buffer to avoid a possible deadlock spotted by sashiko[4], and because it's cleaner, so also move the BTRFS_COMPRESS_PROP_MAX_LEN definition to patch 2/6 instead of later in the series [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 [4]: https://sashiko.dev/#/patchset/20260907200518.428277-1-koray.fra%40gmail.com?part=3 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 | 27 ++++++++++--------- fs/btrfs/props.c | 61 ++++++++++++++++++++++++++++++------------ fs/btrfs/props.h | 9 +++++++ fs/btrfs/super.c | 8 ------ 8 files changed, 134 insertions(+), 42 deletions(-) base-commit: 6255426d70f2755968bb5436ae7b43dae742ac38 prerequisite-patch-id: dc4e24d82d513b8e80e171875a73d397d7ec0762 -- 2.56.0