From: Breno Leitao <leitao@debian.org>
To: Chris Mason <clm@fb.com>, David Sterba <dsterba@suse.com>,
Omar Sandoval <osandov@fb.com>
Cc: linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org,
jlayton@kernel.org, boris@bur.io, kernel-team@meta.com,
stable@vger.kernel.org, Breno Leitao <leitao@debian.org>
Subject: [PATCH] btrfs: fix extent changeset leak in encoded writes
Date: Fri, 31 Jul 2026 04:45:50 -0700 [thread overview]
Message-ID: <20260731-btrfs_kmemleak-v1-1-9600453eef4e@debian.org> (raw)
Investigating some machines with kmemleak, I am constantly seeing
the following memory leak that seems real.
kmemleak: unreferenced object 0xffff88869f7d01c0 (size 64):
kmemleak: comm "btrfs", pid 1613416, jiffies 4316358595
kmemleak: backtrace (crc ab59040a):
kmemleak: __kmalloc_cache_noprof
kmemleak: qgroup_reserve_data
kmemleak: btrfs_qgroup_reserve_data
kmemleak: btrfs_do_encoded_write
kmemleak: btrfs_do_write_iter
kmemleak: btrfs_ioctl_encoded_write
kmemleak: btrfs_ioctl
kmemleak: ... and 2 more object(s) with the same backtrace
and
kmemleak: unreferenced object 0xffff88830d94edc0 (size 64):
kmemleak: comm "btrfs", pid 1613416, jiffies 4316358595
<snip>
kmemleak: ... and 2 more object(s) with the same backtrace
Looking at the code, it seems we don't free data_reserved, but
we should (!?). I was able to come up with a xfstest test that exposes
the kmemleak above:
https://github.com/leitao/xfstest/commit/81c83a3fbb20b4ad695055ede7fcb73d3ffa2e52
Free the changeset on the way out, as every other caller of
btrfs_qgroup_reserve_data() already does.
Fixes: 7c0c7269f7b5 ("btrfs: add BTRFS_IOC_ENCODED_WRITE")
Cc: stable@vger.kernel.org
Signed-off-by: Breno Leitao <leitao@debian.org>
---
fs/btrfs/inode.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 0fcbfc3939462..f8ad96256ff67 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -9965,6 +9965,7 @@ ssize_t btrfs_do_encoded_write(struct kiocb *iocb, struct iov_iter *from,
if (cb)
cleanup_compressed_bio(cb);
out:
+ extent_changeset_free(data_reserved);
if (ret >= 0)
iocb->ki_pos += encoded->len;
return ret;
---
base-commit: 95d6a9ccef99117115e41e9adb271243bd5e985b
change-id: 20260731-btrfs_kmemleak-d44637bd2518
Best regards,
--
Breno Leitao <leitao@debian.org>
next reply other threads:[~2026-07-31 11:47 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-31 11:45 Breno Leitao [this message]
2026-07-31 11:56 ` [PATCH] btrfs: fix extent changeset leak in encoded writes Filipe Manana
2026-07-31 15:04 ` David Sterba
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260731-btrfs_kmemleak-v1-1-9600453eef4e@debian.org \
--to=leitao@debian.org \
--cc=boris@bur.io \
--cc=clm@fb.com \
--cc=dsterba@suse.com \
--cc=jlayton@kernel.org \
--cc=kernel-team@meta.com \
--cc=linux-btrfs@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=osandov@fb.com \
--cc=stable@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox