From: Johannes Thumshirn <johannes.thumshirn@wdc.com>
To: David Sterba <dsterba@suse.cz>
Cc: "linux-btrfs @ vger . kernel . org" <linux-btrfs@vger.kernel.org>,
Johannes Thumshirn <johannes.thumshirn@wdc.com>
Subject: [PATCH v2 1/5] btrfs: free allocated pages on failed cache write-out
Date: Fri, 14 Feb 2020 00:57:59 +0900 [thread overview]
Message-ID: <20200213155803.14799-2-johannes.thumshirn@wdc.com> (raw)
In-Reply-To: <20200213155803.14799-1-johannes.thumshirn@wdc.com>
When we fail to write out a dirty block group, we leak the pages allocated
for a block-group's io_ctl. This can be seen with generic/475 and kmemleak
turned on:
unreferenced object 0xffff8882249c9000 (size 128):
comm "fsstress", pid 1791, jiffies 4294902054 (age 32.100s)
hex dump (first 32 bytes):
80 0e 42 08 00 ea ff ff 00 0d 42 08 00 ea ff ff ..B.......B.....
00 eb 0e 08 00 ea ff ff 00 e8 0e 08 00 ea ff ff ................
backtrace:
[<00000000cd20c449>] io_ctl_init+0xa2/0x110 [btrfs]
[<00000000281944cc>] __btrfs_write_out_cache+0x71/0x410 [btrfs]
[<000000005d518c07>] btrfs_write_out_cache+0x82/0xd0 [btrfs]
[<000000002bb2675c>] btrfs_start_dirty_block_groups+0x1f6/0x440 [btrfs]
[<000000004f955ad0>] btrfs_commit_transaction+0xb7/0x970 [btrfs]
[<00000000a69c8761>] btrfs_sync_file+0x28f/0x390 [btrfs]
[<00000000fa939e06>] do_fsync+0x33/0x70
[<000000002ff0388b>] __x64_sys_fdatasync+0xe/0x20
[<00000000fdbf32d4>] do_syscall_64+0x43/0x120
[<00000000b782d265>] entry_SYSCALL_64_after_hwframe+0x44/0xa9
When cleaning up a block group release all allocated pages. As the data in
the pages is already lost, we can at least free the memory occupied by
them.
Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
---
fs/btrfs/disk-io.c | 6 ++++++
fs/btrfs/free-space-cache.c | 6 ++++++
fs/btrfs/free-space-cache.h | 1 +
3 files changed, 13 insertions(+)
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index 018681ec159b..b79c194b1126 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -4460,6 +4460,12 @@ static void btrfs_cleanup_bg_io(struct btrfs_block_group *cache)
{
struct inode *inode;
+ /*
+ * If we end up here, we want the pages to be already released
+ * otherwise we'll leak them.
+ */
+ btrfs_drop_dirty_io_ctl(&cache->io_ctl);
+
inode = cache->io_ctl.inode;
if (inode) {
invalidate_inode_pages2(inode->i_mapping);
diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c
index 0598fd3c6e3f..3c7660b04a81 100644
--- a/fs/btrfs/free-space-cache.c
+++ b/fs/btrfs/free-space-cache.c
@@ -371,6 +371,12 @@ static void io_ctl_drop_pages(struct btrfs_io_ctl *io_ctl)
}
}
+void btrfs_drop_dirty_io_ctl(struct btrfs_io_ctl *io_ctl)
+{
+ io_ctl_drop_pages(io_ctl);
+ io_ctl_free(io_ctl);
+}
+
static int io_ctl_prepare_pages(struct btrfs_io_ctl *io_ctl, struct inode *inode,
int uptodate)
{
diff --git a/fs/btrfs/free-space-cache.h b/fs/btrfs/free-space-cache.h
index 2e0a8077aa74..cbe25c31041d 100644
--- a/fs/btrfs/free-space-cache.h
+++ b/fs/btrfs/free-space-cache.h
@@ -147,6 +147,7 @@ int btrfs_trim_block_group_extents(struct btrfs_block_group *block_group,
int btrfs_trim_block_group_bitmaps(struct btrfs_block_group *block_group,
u64 *trimmed, u64 start, u64 end, u64 minlen,
u64 maxlen, bool async);
+void btrfs_drop_dirty_io_ctl(struct btrfs_io_ctl *io_ctl);
/* Support functions for running our sanity tests */
#ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS
--
2.24.1
next prev parent reply other threads:[~2020-02-13 15:58 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-02-13 15:57 [PATCH v2 0/5] Fix memory leak on failed cache-writes Johannes Thumshirn
2020-02-13 15:57 ` Johannes Thumshirn [this message]
2020-02-13 15:58 ` [PATCH v2 2/5] btrfs: use inode from io_ctl in io_ctl_prepare_pages Johannes Thumshirn
2020-02-13 15:58 ` [PATCH v2 3/5] btrfs: make the uptodate argument of io_ctl_add_pages() boolean Johannes Thumshirn
2020-02-13 15:58 ` [PATCH v2 4/5] btrfs: use standard debug config option to enable free-space-cache debug prints Johannes Thumshirn
2020-02-13 15:58 ` [PATCH v2 5/5] btrfs: simplify error handling in __btrfs_write_out_cache() Johannes Thumshirn
2020-02-18 16:50 ` [PATCH v2 0/5] Fix memory leak on failed cache-writes David Sterba
2020-02-18 16:54 ` Johannes Thumshirn
2020-02-24 17:49 ` David Sterba
2020-02-25 0:23 ` Johannes Thumshirn
2020-02-25 0:56 ` Johannes Thumshirn
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=20200213155803.14799-2-johannes.thumshirn@wdc.com \
--to=johannes.thumshirn@wdc.com \
--cc=dsterba@suse.cz \
--cc=linux-btrfs@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;
as well as URLs for NNTP newsgroup(s).