This is a note to let you know that I've just added the patch titled btrfs: set correct ram_bytes when splitting ordered extent to the 6.8-stable tree which can be found at: http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary The filename of the patch is: btrfs-set-correct-ram_bytes-when-splitting-ordered-extent.patch and it can be found in the queue-6.8 subdirectory. If you, or anyone else, feels it should not be added to the stable tree, please let <stable@xxxxxxxxxxxxxxx> know about it. >From 63a6ce5a1a6261e4c70bad2b55c4e0de8da4762e Mon Sep 17 00:00:00 2001 From: Qu Wenruo <wqu@xxxxxxxx> Date: Tue, 16 Apr 2024 08:07:00 +0930 Subject: btrfs: set correct ram_bytes when splitting ordered extent From: Qu Wenruo <wqu@xxxxxxxx> commit 63a6ce5a1a6261e4c70bad2b55c4e0de8da4762e upstream. [BUG] When running generic/287, the following file extent items can be generated: item 16 key (258 EXTENT_DATA 2682880) itemoff 15305 itemsize 53 generation 9 type 1 (regular) extent data disk byte 1378414592 nr 462848 extent data offset 0 nr 462848 ram 2097152 extent compression 0 (none) Note that file extent item is not a compressed one, but its ram_bytes is way larger than its disk_num_bytes. According to btrfs on-disk scheme, ram_bytes should match disk_num_bytes if it's not a compressed one. [CAUSE] Since commit b73a6fd1b1ef ("btrfs: split partial dio bios before submit"), for partial dio writes, we would split the ordered extent. However the function btrfs_split_ordered_extent() doesn't update the ram_bytes even it has already shrunk the disk_num_bytes. Originally the function btrfs_split_ordered_extent() is only introduced for zoned devices in commit d22002fd37bd ("btrfs: zoned: split ordered extent when bio is sent"), but later commit b73a6fd1b1ef ("btrfs: split partial dio bios before submit") makes non-zoned btrfs affected. Thankfully for un-compressed file extent, we do not really utilize the ram_bytes member, thus it won't cause any real problem. [FIX] Also update btrfs_ordered_extent::ram_bytes inside btrfs_split_ordered_extent(). Fixes: d22002fd37bd ("btrfs: zoned: split ordered extent when bio is sent") CC: stable@xxxxxxxxxxxxxxx # 5.15+ Reviewed-by: Filipe Manana <fdmanana@xxxxxxxx> Signed-off-by: Qu Wenruo <wqu@xxxxxxxx> Reviewed-by: David Sterba <dsterba@xxxxxxxx> Signed-off-by: David Sterba <dsterba@xxxxxxxx> Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx> --- fs/btrfs/ordered-data.c | 1 + 1 file changed, 1 insertion(+) --- a/fs/btrfs/ordered-data.c +++ b/fs/btrfs/ordered-data.c @@ -1189,6 +1189,7 @@ struct btrfs_ordered_extent *btrfs_split ordered->disk_bytenr += len; ordered->num_bytes -= len; ordered->disk_num_bytes -= len; + ordered->ram_bytes -= len; if (test_bit(BTRFS_ORDERED_IO_DONE, &ordered->flags)) { ASSERT(ordered->bytes_left == 0); Patches currently in stable-queue which might be from wqu@xxxxxxxx are queue-6.8/btrfs-make-sure-that-written-is-set-on-all-metadata-blocks.patch queue-6.8/btrfs-set-correct-ram_bytes-when-splitting-ordered-extent.patch queue-6.8/btrfs-qgroup-do-not-check-qgroup-inherit-if-qgroup-is-disabled.patch queue-6.8/btrfs-always-clear-pertrans-metadata-during-commit.patch queue-6.8/btrfs-make-btrfs_clear_delalloc_extent-free-delalloc.patch