Skip to content

Commit f79645d

Browse files
naotakdave
authored andcommitted
btrfs: zoned: fix double counting of split ordered extent
btrfs_add_ordered_extent_*() add num_bytes to fs_info->ordered_bytes. Then, splitting an ordered extent will call btrfs_add_ordered_extent_*() again for split extents, leading to double counting of the region of a split extent. These leaked bytes are finally reported at unmount time as follow: BTRFS info (device dm-1): at unmount dio bytes count 364544 Fix the double counting by subtracting split extent's size from fs_info->ordered_bytes. Fixes: d22002f ("btrfs: zoned: split ordered extent when bio is sent") CC: [email protected] # 5.12+ Reviewed-by: Johannes Thumshirn <[email protected]> Signed-off-by: Naohiro Aota <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent c124706 commit f79645d

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

fs/btrfs/ordered-data.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1049,6 +1049,7 @@ static int clone_ordered_extent(struct btrfs_ordered_extent *ordered, u64 pos,
10491049
u64 len)
10501050
{
10511051
struct inode *inode = ordered->inode;
1052+
struct btrfs_fs_info *fs_info = BTRFS_I(inode)->root->fs_info;
10521053
u64 file_offset = ordered->file_offset + pos;
10531054
u64 disk_bytenr = ordered->disk_bytenr + pos;
10541055
u64 num_bytes = len;
@@ -1066,6 +1067,13 @@ static int clone_ordered_extent(struct btrfs_ordered_extent *ordered, u64 pos,
10661067
else
10671068
type = __ffs(flags_masked);
10681069

1070+
/*
1071+
* The splitting extent is already counted and will be added again
1072+
* in btrfs_add_ordered_extent_*(). Subtract num_bytes to avoid
1073+
* double counting.
1074+
*/
1075+
percpu_counter_add_batch(&fs_info->ordered_bytes, -num_bytes,
1076+
fs_info->delalloc_batch);
10691077
if (test_bit(BTRFS_ORDERED_COMPRESSED, &ordered->flags)) {
10701078
WARN_ON_ONCE(1);
10711079
ret = btrfs_add_ordered_extent_compress(BTRFS_I(inode),

0 commit comments

Comments
 (0)