* [PATCH] btrfs: zoned: fix double counting of split ordered extent
@ 2021-09-06 15:04 Naohiro Aota
2021-09-07 8:00 ` Johannes Thumshirn
2021-09-07 11:18 ` David Sterba
0 siblings, 2 replies; 3+ messages in thread
From: Naohiro Aota @ 2021-09-06 15:04 UTC (permalink / raw)
To: linux-btrfs; +Cc: David Sterba, Naohiro Aota
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
This commit fixes the double counting by subtracting split extent's size
from fs_info->ordered_bytes.
Fixes: d22002fd37bd ("btrfs: zoned: split ordered extent when bio is sent")
Cc: stable@vger.kernel.org # 5.12+
Signed-off-by: Naohiro Aota <naohiro.aota@wdc.com>
---
fs/btrfs/ordered-data.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/fs/btrfs/ordered-data.c b/fs/btrfs/ordered-data.c
index edb65abf0393..6b51fd2ec5ac 100644
--- a/fs/btrfs/ordered-data.c
+++ b/fs/btrfs/ordered-data.c
@@ -1049,6 +1049,7 @@ static int clone_ordered_extent(struct btrfs_ordered_extent *ordered, u64 pos,
u64 len)
{
struct inode *inode = ordered->inode;
+ struct btrfs_fs_info *fs_info = BTRFS_I(inode)->root->fs_info;
u64 file_offset = ordered->file_offset + pos;
u64 disk_bytenr = ordered->disk_bytenr + pos;
u64 num_bytes = len;
@@ -1066,6 +1067,13 @@ static int clone_ordered_extent(struct btrfs_ordered_extent *ordered, u64 pos,
else
type = __ffs(flags_masked);
+ /*
+ * The splitting extent is already counted and will be added again
+ * in btrfs_add_ordered_extent_*(). Subtract num_bytes to avoid
+ * double counting.
+ */
+ percpu_counter_add_batch(&fs_info->ordered_bytes, -num_bytes,
+ fs_info->delalloc_batch);
if (test_bit(BTRFS_ORDERED_COMPRESSED, &ordered->flags)) {
WARN_ON_ONCE(1);
ret = btrfs_add_ordered_extent_compress(BTRFS_I(inode),
--
2.33.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] btrfs: zoned: fix double counting of split ordered extent
2021-09-06 15:04 [PATCH] btrfs: zoned: fix double counting of split ordered extent Naohiro Aota
@ 2021-09-07 8:00 ` Johannes Thumshirn
2021-09-07 11:18 ` David Sterba
1 sibling, 0 replies; 3+ messages in thread
From: Johannes Thumshirn @ 2021-09-07 8:00 UTC (permalink / raw)
To: Naohiro Aota, linux-btrfs; +Cc: David Sterba
Looks good,
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] btrfs: zoned: fix double counting of split ordered extent
2021-09-06 15:04 [PATCH] btrfs: zoned: fix double counting of split ordered extent Naohiro Aota
2021-09-07 8:00 ` Johannes Thumshirn
@ 2021-09-07 11:18 ` David Sterba
1 sibling, 0 replies; 3+ messages in thread
From: David Sterba @ 2021-09-07 11:18 UTC (permalink / raw)
To: Naohiro Aota; +Cc: linux-btrfs, David Sterba
On Tue, Sep 07, 2021 at 12:04:28AM +0900, Naohiro Aota wrote:
> 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
>
> This commit fixes the double counting by subtracting split extent's size
> from fs_info->ordered_bytes.
>
> Fixes: d22002fd37bd ("btrfs: zoned: split ordered extent when bio is sent")
> Cc: stable@vger.kernel.org # 5.12+
> Signed-off-by: Naohiro Aota <naohiro.aota@wdc.com>
Added to misc-next, thanks.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-09-07 11:19 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-06 15:04 [PATCH] btrfs: zoned: fix double counting of split ordered extent Naohiro Aota
2021-09-07 8:00 ` Johannes Thumshirn
2021-09-07 11:18 ` David Sterba
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.