linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Btrfs: fix memory leak of reloc_root
@ 2016-07-19 22:36 Liu Bo
  2016-07-26 15:32 ` David Sterba
  0 siblings, 1 reply; 2+ messages in thread
From: Liu Bo @ 2016-07-19 22:36 UTC (permalink / raw)
  To: linux-btrfs; +Cc: David Sterba

When some critical errors occur and FS would be flipped into RO,
if we have an on-going balance, we can end up with a memory leak
of root->reloc_root since btrfs_drop_snapshots() bails out
without freeing reloc_root at the very early start.

However, we're not able to free reloc_root in btrfs_drop_snapshots()
because its caller, merge_reloc_roots(), still needs to access it to
cleanup reloc_root's rbtree.

This makes us free reloc_root when we're going to free fs/file roots.

Signed-off-by: Liu Bo <bo.li.liu@oracle.com>
---
 fs/btrfs/disk-io.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index 60ce119..db53eb8 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -3737,8 +3737,15 @@ void btrfs_drop_and_free_fs_root(struct btrfs_fs_info *fs_info,
 	if (btrfs_root_refs(&root->root_item) == 0)
 		synchronize_srcu(&fs_info->subvol_srcu);
 
-	if (test_bit(BTRFS_FS_STATE_ERROR, &fs_info->fs_state))
+	if (test_bit(BTRFS_FS_STATE_ERROR, &fs_info->fs_state)) {
 		btrfs_free_log(NULL, root);
+		if (root->reloc_root) {
+			free_extent_buffer(root->reloc_root->node);
+			free_extent_buffer(root->reloc_root->commit_root);
+			btrfs_put_fs_root(root->reloc_root);
+			root->reloc_root = NULL;
+		}
+	}
 
 	if (root->free_ino_pinned)
 		__btrfs_remove_free_space_cache(root->free_ino_pinned);
-- 
2.5.5


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] Btrfs: fix memory leak of reloc_root
  2016-07-19 22:36 [PATCH] Btrfs: fix memory leak of reloc_root Liu Bo
@ 2016-07-26 15:32 ` David Sterba
  0 siblings, 0 replies; 2+ messages in thread
From: David Sterba @ 2016-07-26 15:32 UTC (permalink / raw)
  To: Liu Bo; +Cc: linux-btrfs, David Sterba

On Tue, Jul 19, 2016 at 03:36:05PM -0700, Liu Bo wrote:
> When some critical errors occur and FS would be flipped into RO,
> if we have an on-going balance, we can end up with a memory leak
> of root->reloc_root since btrfs_drop_snapshots() bails out
> without freeing reloc_root at the very early start.
> 
> However, we're not able to free reloc_root in btrfs_drop_snapshots()
> because its caller, merge_reloc_roots(), still needs to access it to
> cleanup reloc_root's rbtree.
> 
> This makes us free reloc_root when we're going to free fs/file roots.
> 
> Signed-off-by: Liu Bo <bo.li.liu@oracle.com>

Reviewed-by: David Sterba <dsterba@suse.com>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-07-26 15:33 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-07-19 22:36 [PATCH] Btrfs: fix memory leak of reloc_root Liu Bo
2016-07-26 15:32 ` David Sterba

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).